Community Tip - You can change your system assigned username to something more personal in your community settings. X
I am wondering how one uses a function within a function. For exampe:
t=0,1..10
f(t):=2*t
then t and f(t) are vectors of length 10. t contains the 11 numbers 0-10 and f(t) contains the 11 numbers 0 through 20
Now, I need to use the values of f(t) in another equation, like:
g(f(t)):=10*f(t)
I should be able to get a vector of 11 numbers ranging from 0 to 200, but I can not make this work.
In my actual problem I am using an ODE solver to get the values f(t) and so I can't just change the algebra. I need to use the values of f(t) in another equation? HOW DO I DO THIS
Solved! Go to Solution.
define g(x):=10*x and then evaluate g(f/t))=
The description you gave does not match the math you wrote. The t = 0..10 created a range variable, not a vector. The function f(t) = 2*t doesn't care what t is, so when you use t in f(t) = you get a range result, not a vector.
Werner has the correct functions above, and they will work with either range or vector arguments, but I think what you want is a vector. That vector needs to be defined before using it as the argument in the evaluation.
Another tip: when defining a function, any variable listed in an argument list ignores any prior use of the variable. So the 2*t in the definition of f(t) doesn't really know anything about the t range variable at that point. Thus, t can be anything, a scalar, a range variable, or a vector when the function is evaluated, depending upon what is put in the argument list during the evaluation.
t:=0,1..10
f(t):=2*t
g(t):=10*f(t)
inside the parethesis adjecent to the g should contain all the variables that would be used within the equation.
example
A:=0,1..10
B:=0,2...6
C(A):=A/3
D(B):=2*B
E(A,B):=C(A) - D(B)
There is no need for the definition of those range variables - they do not affect the function definitions with their formal parameters which happen to be of the same name.