Clear Filters
Clear Filters

How can i determine the analytical expression of the derived funtion "df(x)/dx" ?

1 view (last 30 days)
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))

Accepted Answer

Star Strider
Star Strider on 23 Jan 2017
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)
  2 Comments
Mallouli Marwa
Mallouli Marwa on 23 Jan 2017
If i want to comput the derived function in a point y=40 "df_dy(40)"
I obtain this error
Error using mupadmex
Error in MuPAD command: Index exceeds matrix dimensions.
Star Strider
Star Strider on 23 Jan 2017
I am not certain how you called the function, that is named ‘df_dx’, not ‘df_dy’. You can always rename it in the derivation and assignment, but you have to use the function name that exists. (I do not know if you used double quotes in your code. The double quotes (") are not valid MATLAB syntax.)
Depending on what you want, one of these will work:
y = 40;
SymOutput = df_dx(y)
SymOutput = vpa(df_dx(y))
NumOutput = df_dx_fcn(y)
SymOutput =
(2*cos(80/3))/3 - (2*sin(80/3))/3 - (2*sinh(80/3))/3
SymOutput =
-127076407709.60347598489525821488
NumOutput =
-127.0764e+009

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!