Search code examples
matlabderivative

Derivative long equation in matlab, then calculation the result


I have a example like this: I have a velocity of one element===derivative it====> the acceleration of element. The velocity is calculate from many equation, like this:

    syms m w k E mI c w t L z;
E=2.7*10^10;
L=21;
mI=0.001332;
z=5;
m=500;
k=1*10^7;
c=30000;
w=300;
t=1;
a=((((m*w^2-k)/(E*mI))^2+(c*w/(E*mI))^2)^(1/8));
b=(atan(-c*w/(m*w^2-k))/4+pi/4);
syms cosi(w);
cosi=a*exp(t*b);
delta=2*(1-cosh(cosi*L)*cos(cosi*L));
syms v(w);
v=((sin(cosi*L)-sinh(cosi*L))*(cosh(cosi*z)+cos(cosi*z))+(cosh(cosi*L)...
    -cos(cosi*L))*(sinh(cosi*z)+sin(cosi*z)))...
    /(E*mI*cosi^3*delta);

f=jacobian(v,w);

With m,k,E,mI,c are constant, w is independent variable. 1.Now I want to calculate the derivative of v 2.Now I want to compile these code into Net assembly to call it by c# program. How can I fix it.

function [resultv,resultf]=Untitled4(m1, w1, k1, E1, mI1, c1, t1, L1, z1)
syms m w k E mI c w t L z cosi(w)
a=((((m*w^2-k)/(E*mI))^2+(c*w/(E*mI))^2)^(1/8));
b=(atan(-c*w/(m*w^2-k))/4+pi/4);
cosi=a*exp(t*b);
delta=2*(1-cosh(cosi*L)*cos(cosi*L));
v=((sin(cosi*L)-sinh(cosi*L))*(cosh(cosi*z)+cos(cosi*z))+(cosh(cosi*L)...
    -cos(cosi*L))*(sinh(cosi*z)+sin(cosi*z)))...
    /(E*mI*cosi^3*delta);

f=jacobian(v,w);

E=E1;
L=L1;
mI=mI1;
z=z1;
m=m1;
k=k1;
c=c1;
w=w1;
t=t1;
resultv=double(subs(v));
resultf = double(subs(f));
end

Thank you very much.


Solution

  • Use jacobian. Let's say you want to derive wrt w

    syms m w k E mI c w t L z 
    
    a=((((m*w^2-k)/(E*mI))^2+(c*w/(E*mI))^2)^(1/8));
    b=(atan(-c*w/(m*w^2-k))/4+pi/4);
    cosi=(a*exp(t*b));
    delta=2*(1-cosh(cosi*L)*cos(cosi*L));
    v=((sin(cosi*L)-sinh(cosi*L))*(cosh(cosi*z)+cos(cosi*z))+(cosh(cosi*L)...
        -cos(cosi*L))*(sinh(cosi*z)+sin(cosi*z)))...
        /(E*mI*cosi^3*delta);
    
    jacobian(v,w)
    

    UPDATE AFTER QUESTION HAS BEEN UPDATED

    syms m w k E mI c w t L z cosi(w)
    a=((((m*w^2-k)/(E*mI))^2+(c*w/(E*mI))^2)^(1/8));
    b=(atan(-c*w/(m*w^2-k))/4+pi/4);
    cosi=a*exp(t*b);
    delta=2*(1-cosh(cosi*L)*cos(cosi*L));
    v=((sin(cosi*L)-sinh(cosi*L))*(cosh(cosi*z)+cos(cosi*z))+(cosh(cosi*L)...
        -cos(cosi*L))*(sinh(cosi*z)+sin(cosi*z)))...
        /(E*mI*cosi^3*delta);
    
    f=jacobian(v,w);
    
    E=2.7*10^10;
    L=21;
    mI=0.001332;
    z=5;
    m=500;
    k=1*10^7;
    c=30000;
    w=300;
    t=1;
    
    results = double(subs(f))