Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Evaluating function of functions

I have two symbolic functions

syms a(t) b(t) t
a(t) = 5*b(t);
b(t) = exp(t);

How do I determine the value of the function a(t=5) for a specific t, lets say t=5:

a(5)

What I get is

a(5)
ans = 5*b(5)

but I want the actual value (1.4841e+02). What I tried is something like

eval(a(5))
subs(a, b(t), exp(5))

Is there anybody who can help. Thanks!

Edit: Please note that b(t) is defined after a(t). This is important to me.

like image 664
O. Berner Avatar asked Mar 16 '26 13:03

O. Berner


1 Answers

As suggested in the comments, most of your problems come from the order of your definitions. You create a(t) before defining how b(t) looks like, but you already have told MATLAB that b(t) will exists. Basically, MATLAB knows that in a(t) there is something called b(t) but doesnt really know what (as even if you have defined it, you defined it after running that 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.

like image 175
Ander Biguri Avatar answered Mar 19 '26 08:03

Ander Biguri



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!