MATLAB: How can i determine the analytical expression of the derived funtion “df(x)/dx”

matlab function

How can i determine the analytical expression of the derived funtion "df(x)/dx"?
x=linspace (0:40)
L=3;
sol(1)=2;
psi=1;
f (x) = @(x) cos ( (sol(1)/L) *x)- cosh( (sol(1)/L) *x)+ psi *( sin( (sol(1)/L) *x)- sinh( (sol(1))

Best Answer

Use the Symbolic Math Toolbox:
syms x
L=sym(3);
sol(1)=sym(2);
psi=sym(1);
f (x) = cos ( (sol(1)/L) *x)- cosh( (sol(1)/L) *x)+ psi *( sin( (sol(1)/L) *x)- sinh( (sol(1))));
df_dx = diff(f,x)
df_dx_fcn = matlabFunction(df_dx)
df_dx(x) =
(2*cos((2*x)/3))/3 - (2*sin((2*x)/3))/3 - (2*sinh((2*x)/3))/3
df_dx_fcn = @(x) cos(x.*(2.0./3.0)).*(2.0./3.0)-sin(x.*(2.0./3.0)).*(2.0./3.0)-sinh(x.*(2.0./3.0)).*(2.0./3.0)