# How can I solve a system of differential equations where one equation contains the answer to another?

3 ビュー (過去 30 日間)
Erik Andersson 2019 年 11 月 22 日
Commented: Star Strider 2019 年 11 月 22 日
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 件のコメント

ME 2019 年 11 月 22 日
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?

サインイン to comment.

### 採用された回答

Star Strider 2019 年 11 月 22 日
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 件のコメント

Erik Andersson 2019 年 11 月 22 日
Thank you, this has solved it.
Star Strider 2019 年 11 月 22 日
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))

サインイン to comment.