Function function evaluation
I have two symbolic functions
syms a(t) b(t) t
a(t) = 5*b(t);
b(t) = exp(t);
How to determine the value of the function a (t = 5) for a specific t, say t = 5:
a(5)
I get
a(5) ans = 5*b(5)
but I want the actual value (1.4841e + 02). I have tried something like
eval(a(5))
subs(a, b(t), exp(5))
Is there anyone who can help. Thank!
Edit: Note that b (t) is defined after a (t). It's important for me.
source to share
As pointed out in the comments, most of your problems come from the order of your definitions. You create a(t)
before you define what it looks like b(t)
, but you've already told MATLAB that it b(t)
will exist. Basically, MATLAB knows that a(t)
there is something called b(t)
, but it doesn't know what (like even if you defined it, you defined it after running this line of code!).
syms a(t) b(t) t
a(t) = 5*b(t); % MATLAB does not error because you told it that b(t) is symbolic. It just has no idea what it looks like.
b(t) = exp(t);
Just change the first lines to:
syms a(t) b(t) t
b(t) = exp(t); % MATLAB here understand that the syntax b(t)=.. is correct, as you defined b(t) as symbolic
a(t) = 5*b(t); % MATLAB here knows what b(t) looks like, not only that it exists
and do
double(a(3))
To get a numeric result.
source to share