How to import a Symbolic Formula, so i can solve it with ode45 ?

1 vue (au cours des 30 derniers jours)
Robert Thiel
Robert Thiel le 10 Déc 2016
Commenté : Steven Lord le 10 Déc 2016
Im generating symbolic Formulas like
ddTheta1 =...
-(2*((m2*s2^2 + J2)*(l1*m2*s2*sin(T1 - T2)*dT2^2 + g*l1*m2*sin(T1) + g*m1*s1*sin(T1)) + (l1*m2^2*s2^2*(l1*sin(2*T1 - 2*T2)*dT1^2 - g*sin(T1) + g*sin(T1 - 2*T2)))/2))/(2*(m2*s2^2 + J2)*(m2*l1^2 + m1*s1^2 + J1) - l1^2*m2^2*s2^2*(cos(2*T1 - 2*T2) + 1))
ddTheta2 =...
(l1*m2*s2*sin(T1 - T2)*(m2*l1^2 + m1*s1^2 + J1)*dT1^2 - g*m2*s2*sin(T2)*(m2*l1^2 + m1*s1^2 + J1) + l1*m2*s2*cos(T1 - T2)*(l1*m2*s2*sin(T1 - T2)*dT2^2 + g*l1*m2*sin(T1) + g*m1*s1*sin(T1)))/((m2*s2^2 + J2)*(m2*l1^2 + m1*s1^2 + J1) - l1^2*m2^2*s2^2*cos(T1 - T2)^2)
How can i import it to this function, so i can solve it per ode45
function [ xp ] = x3punkt( t , x ) % mit J
global m1 m2 J1 J2 l1 l2 s1 s2 g u1 u2 ddTheta1 ddTheta2
T1 = x(1); % Theta1
T2 = x(2); % Theta2
dT1 = x(3); % dTheta1
dT2 = x(4); % dTheta2
% [ ddTheta1 , ddTheta2 ] = RTL_DGL;
ddTheta1 =...
-(2*((m2*s2^2 + J2)*(l1*m2*s2*sin(T1 - T2)*dT2^2 + g*l1*m2*sin(T1) + g*m1*s1*sin(T1)) + (l1*m2^2*s2^2*(l1*sin(2*T1 - 2*T2)*dT1^2 - g*sin(T1) + g*sin(T1 - 2*T2)))/2))/(2*(m2*s2^2 + J2)*(m2*l1^2 + m1*s1^2 + J1) - l1^2*m2^2*s2^2*(cos(2*T1 - 2*T2) + 1));
ddTheta2 =...
(l1*m2*s2*sin(T1 - T2)*(m2*l1^2 + m1*s1^2 + J1)*dT1^2 - g*m2*s2*sin(T2)*(m2*l1^2 + m1*s1^2 + J1) + l1*m2*s2*cos(T1 - T2)*(l1*m2*s2*sin(T1 - T2)*dT2^2 + g*l1*m2*sin(T1) + g*m1*s1*sin(T1)))/((m2*s2^2 + J2)*(m2*l1^2 + m1*s1^2 + J1) - l1^2*m2^2*s2^2*cos(T1 - T2)^2);
xp = [dT1; dT2; ddTheta1; ddTheta2];
end
Right now i just copy and paste the Formulas, but i would like to use something like this
[ ddTheta1 , ddTheta2 ] = RTL_DGL;
Thanks for your help

Réponses (1)

Star Strider
Star Strider le 10 Déc 2016
I cannot figure out what you are doing. See the documentation for odeToVectorField and matlabFunction. They should help you do what you want.
The odeFunction function is also an option, but I’ve not used it.
  2 commentaires
Robert Thiel
Robert Thiel le 10 Déc 2016
I see, i did not explained it properly. First im generating symbolic Formulas with the Function RTL_DGL. Now i want to use these Formulas as part of the odefun (in this case x3punkt) for the ode45 solver. Right now i run the RTL_DGL function in the command window and then just copy the result in the odefun function. I would like to have this step automatic. So i dont have to copy the new formula if i change anything in RTL_DGL.
Steven Lord
Steven Lord le 10 Déc 2016
Use matlabFunction to convert the symbolic expression into a function or solve the system of ODEs symbolically using dsolve.

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by