Bes Sa
Bes Sa

Reputation: 93

Calculating derivative in a given point - matlab

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

Answers (4)

David
David

Reputation: 8459

syms x
y=sin(x)+cos(3*x);
py=diff(y);
subs(py,x,1.0)

Upvotes: 2

Marcin
Marcin

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

user2875617
user2875617

Reputation:

syms x real
v = sin(x)+ cos(3*x)
diff(v)

Upvotes: 0

Daniel
Daniel

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

Related Questions