Using symbolic
computation you can obtain analytical
derivatives in MATLAB
The function is diff(..)
% analytical derivativesOutput from MATLAB
syms x y
y= sin(x); dy = diff(y,'x')
y=exp(2*x); dy = diff(y)
% derivative with respect to x is understoodf = sin(x); g = 2*x^2+3*x + 1;
y = f*g
dy =diff(y) % derivative of productu= 2*x + 3; f = sin(u);
diff(f) % chain rule
dy =
cos(x)
dy =
2*exp(2*x)
y =
sin(x)*(2*x^2+3*x+1)
dy =
cos(x)*(2*x^2+3*x+1)+sin(x)*(4*x+3)
ans =
2*cos(2*x+3)