Reputation: 1
I have following MATLAB code:
>> syms x
>> z = 20.*exp(x)+cos(x)
>> derivative = diff(z)
How can I calculate value of derevative for any number, e.g. 6?
Following commands
>> clear all
>> x = 6
>> derevative = 20*exp(x)-sin(x)
works fine, but if x is symbolic I don't use x = 6 such as above example.
Upvotes: 0
Views: 5300
Reputation: 1
you can use the function given below:
syms a b
subs(cos(a) + sin(b), [a, b], [sym('alpha'), 2])
it works perfect.
Upvotes: 0
Reputation: 222481
The right way to do this is the following:
syms x
z = 20.*exp(x)+cos(x)
derivative = diff(z)
subs(derivative, 6)
where the last line subs(derivative, 6)
does the job, you need.
Upvotes: 3
Reputation: 1850
You can try this:
syms x;
z = 20.*exp(x)+cos(x);
derivative = diff(z);
x = 5;
result = eval(derivative)
Upvotes: 1
Reputation: 15756
There's a tutorial on how to do symbolic computation in MATLAB. From what I understand, it is a bit unorthodox to use MATLAB for symbolic computations, though.
Upvotes: 0