Reputation: 93
I would like to calculate the derivative of the following function in Matlab in point x=1.0:
v = sin(x)+ cos(3*x)
I tried this but it returns py = []
sym x,
x=1.0,
y=sin(x) + cos(3*x),
py=diff(y);
Upvotes: 1
Views: 10608
Reputation: 238209
With such a simple function v(x) = sin(x)+ cos(3*x)
just use the explicit formula for its derivative, i.e. vv = dv/dx = cos(x) - 3*sin(3*x)
.
Then its value in x = 1.0 is: vv(1.0) = cos(1.0) - 3*sin(3*1.0)
.
Upvotes: 0
Reputation: 36710
There are multiple functions in Matlab called diff. Important for this question is the "standard" diff, which is for vecor/matrix input. This is what you called. If you read the documentation, you will understand the empty output: http://www.mathworks.de/de/help/matlab/ref/diff.html
Suitable for your case is the symbolic toolbox: http://www.mathworks.de/de/help/symbolic/diff.html The examples explain how to use, if the toolbox is available.
Upvotes: 0