How to evaluate the value of Symbolic Expressions

I tried this code -
syms f(a) g(b)
f(a)=sin(a);
g(b)=exp(b);
disp(f(2));
disp(g(4));
syms h(a,b);
h(a,b)=diff(f(a),a)*diff(g(b),b);
disp(h(2,4));
but it doesnt return the values of sin(2) and exp(4); It just returns sin(2) and exp(4). It gives values of algebraic expressions, but not trigonometric and exponential functions. How to calculate the values?? Please Help.

 Accepted Answer

f=@(a) sin(a);
g=@(b) exp(b);
disp(f(2));
disp(g(4));

6 Comments

No, this wont help, I have to differentiate the functions f(a) and g(b). There is a lot more complex equation than this.
Shree, in your case, the functions are f and g, f(a) and f(b) are not functions. And from above they are different, what is the problem?
f=@(a) sin(a);
g=@(b) exp(b);
disp(f(2));
disp(g(4));
h=@(a,b) diff(f(a),a)*diff(g(b),b);
disp(h(2,4));
There is a complex equation including trigonometric and exponential functions. I have to do some mathematical operations on it, like calculating hessian etc, and then Find out its values for specific values of inputs. Now calculating each term manually will be difficult. I plan to let matlab do it. Matlab calculates the expression, but doesn't return the mathematical values. I want Mathematical values to compare with, thats Why.
syms a b
f=sin(a);
g=exp(b);
double(subs(f,2))
double(subs(g,2))
h=diff(subs(f,a),a)*diff(subs(g,b),b);
a=2;
b=4;
double(subs(h));
Got it. Thanks. double() also Worked. :)

Sign in to comment.

More Answers (0)

Categories

Find more on Mathematics in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!