I Want to solve system of three differential equations numerically. How can i solve it with ode45, or are there any other ways?
1 view (last 30 days)
Show older comments
Hello. I wrote three equations for three different variables. I also have conditions.
syms v1(t) y1(t) y2(t) v2(t) a2(t) phi(t) Omega(t) Omegaac(t) omega(t) omegaac(t)
Omega = diff(phi,t);
Omegaac = diff(Omega,t);
omegaac = diff(omega,t);
v1 = diff(y1,t);
v2 = diff(y2,t);
a2 = diff(v2,t);
v1_y = v2 - (omega*r+Omega*L*cos(beta))*sin(phi);
v1_x = (omega*r+Omega*L*cos(beta))*cos(phi);
v1 = sqrt((v1_y)^2+(v1_x)^2);
cond1 = v1(0) == 0;
cond2 = v1_y(0)==0;
cond3 =v1_x(0)==0;
cond4 = y1(0) == 0;
cond5 = y2(0) == 0;
cond6 = v2(0) == 0;
cond7 = a2(0) == 0;
cond8 = phi(0) == 0;
cond9 = Omega(0)==0;
cond10 = Omegaac(0)==0;
cond11 = omega(0) == 0;
cond12 = omegaac(0)==0;
%equations look a bit like this, coefficients which will be denoted by some
%letters are known. only unknowns are variables.
ode1 = a2==(A+B*(Omega)^2*cos(phi)-C-(D*(v1_y))/v1);
ode2 = omegaac==((E*omega+F*Omega-v2*cos(phi))/v1);
ode2 = Omegaac==(G*sin(phi)+H*a2*sin(phi)-(I*omega+J*Omega-v2*cos(phi))/v1);
3 Comments
Torsten
on 6 Feb 2023
You don't need to explain what the variables mean.
Just state which of them are known and which of them are unknown.
For the unknowns, additionally give the initial values.
Accepted Answer
Star Strider
on 6 Feb 2023
syms v1(t) y1(t) y2(t) v2(t) a2(t) phi(t) L r A B C D E F G H I J beta Omega(t) Omegaac(t) omega(t) omegaac(t) Y t
sympref('AbbreviateOutput',false);
Omega = diff(phi,t);
Omegaac = diff(Omega,t);
omegaac = diff(omega,t);
v1 = diff(y1,t);
v2 = diff(y2,t);
a2 = diff(v2,t);
v1_y = v2 - (omega*r+Omega*L*cos(beta))*sin(phi);
v1_x = (omega*r+Omega*L*cos(beta))*cos(phi);
v1 = sqrt((v1_y)^2+(v1_x)^2);
cond1 = v1(0) == 0;
cond2 = v1_y(0)==0;
cond3 =v1_x(0)==0;
cond4 = y1(0) == 0;
cond5 = y2(0) == 0;
cond6 = v2(0) == 0;
cond7 = a2(0) == 0;
cond8 = phi(0) == 0;
cond9 = Omega(0)==0;
cond10 = Omegaac(0)==0;
cond11 = omega(0) == 0;
cond12 = omegaac(0)==0;
%equations look a bit like this, coefficients which will be denoted by some
%letters are known. only unknowns are variables.
ode1 = a2==(A+B*(Omega)^2*cos(phi)-C-(D*(v1_y))/v1);
ode2 = omegaac==((E*omega+F*Omega-v2*cos(phi))/v1);
ode3 = Omegaac==(G*sin(phi)+H*a2*sin(phi)-(I*omega+J*Omega-v2*cos(phi))/v1);
[VF,Sbs] = odeToVectorField([ode1; ode2; ode3]) % ADDED
odesfcn = matlabFunction(VF, 'Vars',{t,Y,A,B,C,D,E,F,G,H,I,J,L,beta,r}) % ADDED
Refer to it in the ode45 call (or whatever function you want to integrate it with) as:
@(t,Y)odesfcn(t,Y,A,B,C,D,E,F,G,H,I,J,L,beta,r)
Be sure that all the additional arguments (A,B,C,D,E,F,G,H,I,J,L,beta,r) are defined in your workspace first.
.
2 Comments
Star Strider
on 6 Feb 2023
No worries!
I do not use them with odeToVectorField or matlabFunction. They are supplied as arguments when you use ode45 (or whatever solver you choose) with your system. See that documentation for details.
More Answers (0)
See Also
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!