Evaluate Matlab symbolic function

user2141889 picture user2141889 · Nov 17, 2013 · Viewed 13.8k times · Source

I have a problem with symbolic functions. I am creating function of my own whose first argument is a string. Then I am converting that string to symbolic function:

f =  syms(func)

Lets say my string is sin(x). So now I want to calculate it using subs.

a = subs(f, 1)

The result is sin(1) instead of number.

For 0 it works and calculates correctly. What should I do to get the actual result, not only sin(1) or sin(2), etc.?

Answer

noobmaster69 picture noobmaster69 · Nov 17, 2013

You can use also use eval() to evaluate the function that you get by subs() function

f=sin(x);
a=eval(subs(f,1));
disp(a);
a =

    0.8415