How can I solve a system of differential equations where one equation contains the answer to another?
1 view (last 30 days)
Show older comments
Erik Andersson
on 22 Nov 2019
Commented: Star Strider
on 22 Nov 2019
I have the following system of differential equations that shall be solved
where are constants, I am looking for a way to deal with the fact that dot and Ω dot are dependant on eachother. I have tried implementing the ode45 function but I did not get a logical result.
1 Comment
ME
on 22 Nov 2019
You can 100% use MATLAB ODE solvers for this type of problem. Would you be able to upload your code so that we can see where you might have gone wrong?
Accepted Answer
Star Strider
on 22 Nov 2019
If you have the Symbolic Math Toolbox, let it do the ‘heavy lifting’:
syms omegax(t) omegay(t) omegas Omega(t) epsilon sigma alphas t Y
Eqns = [diff(omegax) == omegay*alphas + omegas*Omega*epsilon
diff(omegay) == omegax*alphas - diff(Omega)*epsilon
diff(Omega) == -diff(omegay) - Omega*sigma];
[VF,Subs] = odeToVectorField(Eqns)
Eqnsfcn = matlabFunction(VF, 'Vars',{t,Y,alphas,omegas,sigma,epsilon})
producing this system:
VF =
-(alphas*Y[2] + epsilon*sigma*Y[3])/(epsilon - 1)
alphas*Y[1] + epsilon*omegas*Y[3]
(alphas*Y[2] + sigma*Y[3])/(epsilon - 1)
Subs =
omegay
omegax
Omega
and anonymous function to use with the numeric ODE solvers (slightly edited):
Eqnsfcn = @(t,Y,alphas,omegas,sigma,epsilon) [-(alphas.*Y(2)+epsilon.*sigma.*Y(3))./(epsilon-1.0);alphas.*Y(1)+epsilon.*omegas.*Y(3);(alphas.*Y(2)+sigma.*Y(3))./(epsilon-1.0)];
The ‘Subs’ output are the substitutions odeToVectorField made, with ‘omegay’ being ‘Y[1]’ ‘omegax’ being ‘Y[2]’, and ‘Omega’ being ‘Y[3]’.
2 Comments
Star Strider
on 22 Nov 2019
As always, my pleasure!
When you do the numerical integration and plot the results, an easy way to use the legend function is:
legend(string(Subs))
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!