Solving two equations with ODE45

1 回表示 (過去 30 日間)
Sergio Manzetti
Sergio Manzetti 2018 年 4 月 4 日
編集済み: Sergio Manzetti 2018 年 4 月 4 日
Hi, I used the following command to solve one ODE
fun = @(x,y)[y(2);y(3);(y(1)*(1-x^2))];
y0 = [1 0 8]; %y, y', y''
xspan = [-3 3];
[X,Y] = ode45(fun,xspan,y0);
plot(X,Y(:,1)),,% X,Y(:,2),X,Y(:,3),X,Y(:,1).* (2 + X .^ 2));
However, I would like to solve this pair of equations instead of the given "fun":
How do I add two equations in the fun line?
Thanks!

採用された回答

Torsten
Torsten 2018 年 4 月 4 日
fun=@(x,y)[y(2);y(3);-(1+x^2)*y(4);y(5);y(6);(1+x^2)*y(1)]; %psi2,psi2',psi2'',psi1,psi1',psi1''
Best wishes
Torsten.
  9 件のコメント
Sergio Manzetti
Sergio Manzetti 2018 年 4 月 4 日
編集済み: Sergio Manzetti 2018 年 4 月 4 日
Thanks, following your link I used a new y0 and got a result, but plot only plots one form.
fun=@(x,y)[y(2);y(3);-(1+x^2)*y(4);y(5);y(6);(1+x^2)*y(1)]; %psi2,psi2',psi2'',psi1,psi1',psi1''
y0 = [1 0 8 1 0 8]; %y, y', y''
xspan = [-3 3];
[X,Y] = ode45(fun,xspan,y0);
plot(X,Y(:,1)), X,Y(:,2),X,Y(:,3),X,Y(:,1), '-o',X,Y(:,2), X,Y(:,2),X,Y(:,3),X,Y(:,1);
What is wrong in the plot section really?
Sergio Manzetti
Sergio Manzetti 2018 年 4 月 4 日
編集済み: Sergio Manzetti 2018 年 4 月 4 日
Hi Torsten, I edited this finally:
fun=@(x,y)[y(2);y(3);-(1+x^2)*y(4);y(5);y(6);(1+x^2)*y(1)]; %psi2,psi2',psi2'',psi1,psi1',psi1''
y0 = [1 0 8 1 0 8]; %y, y', y''
xspan = [-3 3];
[X,Y] = ode45(fun,xspan,y0);
plot(X,Y(:,1)), X,Y(:,2),X,Y(:,3),X,Y(:,1);
So it shows a plot. But this plot is identical to the plot of only one function present in the command (remove the second function and decrease to three dimensions, and it is the same plot).
Is that correct? I would have expected a different solution.

サインインしてコメントする。

その他の回答 (1 件)

KSSV
KSSV 2018 年 4 月 4 日
  1 件のコメント
Sergio Manzetti
Sergio Manzetti 2018 年 4 月 4 日
That was greek to me. Sorry

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeOrdinary Differential Equations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by