現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
How do I prepare the following ODE for ode45?
1 回表示 (過去 30 日間)
古いコメントを表示
Sergio Manzetti
2018 年 2 月 20 日
Hello, I would like to solve the following ODE in ode45, but the example's on the site are not describing using higher order derivatives with non-linear terms.
The ODE is:
y''' = y(2+x^2)
initial conditions are: y(0)=0 y'(0)=0 y''(0)=0
Thanks!
2 件のコメント
Sergio Manzetti
2018 年 2 月 20 日
編集済み: Sergio Manzetti
2018 年 2 月 20 日
I got so far:
dYdX = @(X,Y) [Y(3) + (x^2+2)*Y(1)]; % Differential equation
res = @(ya,yb) [ya(1); ya(2); yb(2)-1]; % Boundary conditions
SolYinit = bvpinit([0 1E+1], [1; 1; 1]);
Fsol = bvp4c(dYdX, res, SolYinit);
X = Fsol.x;
F = Fsol.y;
figure(1)
plot(X, F)
legend('F_1', 'F_2', 'F_3', 3)
grid
But the first line is not correct. Can you see what is missing?
採用された回答
Torsten
2018 年 2 月 20 日
fun = @(x,y)[y(2);y(3);y(1)*(2+x^2)];
y0 = [0 0 0];
xspan = [0 5];
[X,Y] = ode45(fun,xspan,y0);
plot(X,Y(:,1),X,Y(:,2),X,Y(:,3));
Best wishes
Torsten.
17 件のコメント
Sergio Manzetti
2018 年 2 月 21 日
Hi Torsten, I am trying to expand the interval from 0 5 to -500 to +500, but I only get a flat line. Even when I go back to 0 5 in the interval, the graph again appears as a flat line...
Steven Lord
2018 年 2 月 21 日
Your initial conditions state that y, its first derivative, and its second derivative are all 0 at x = 0. If you think about this from a physics standpoint where y is the position of your solution (let's think of this as a race car), y' is the velocity, and y'' is the acceleration this corresponds to you being at the starting line at a dead stop with your foot off the gas pedal.
Speaking very roughly, at the first time step (I'm treating x as time here) y'' is 0*something, so you never accelerate. If you don't accelerate you can't go faster than 0. If you don't go faster than 0, you can't move away from 0. Torsten's solution (correctly) demonstrates that the solution to your system of equations with that set of initial conditions is y(x) = 0.
Now if you were to tweak the initial conditions, say by stomping on the gas pedal as the race starts:
>> y0 = [0 0 1];
>> [X,Y] = ode45(fun,xspan,y0);
>> plot(X,Y(:,1),X,Y(:,2),X,Y(:,3));
You get something that looks a bit more interesting. For most of the time span your curves looks like they are at 0, but that's because of the scaling on the Y axis. If you zoom in you can see that y, its first derivative, and its second derivative take off very rapidly. [Given that the acceleration increases as the square of x, you get going REALLY quickly.]
Sergio Manzetti
2018 年 2 月 22 日
編集済み: Sergio Manzetti
2018 年 2 月 22 日
Hi, unfortunately I have no information on what the acceleration is, but it can be given an arbitrary value to begin with. Thanks for this suggestion, I will work on this model instead. The first line was originally foreign to me, does it mean that y(0) = 0 , y'(0)=0 and y''(0)=1 ?
The plot becomes more interesting as the second derivative is set to 1, as you say. But how do I interpret the three lines here?

Sergio Manzetti
2018 年 2 月 22 日
Thanks, if I add a constant to the y''' term, it appears as:
fun = @(x,y)[y(2);y(3)*h;y(1)*(2+x^2)];
y0 = [0 0 1];
xspan = [0 5];
[X,Y] = ode45(fun,xspan,y0);
plot(X,Y(:,1),X,Y(:,2),X,Y(:,3));
where h is defined before. But why this weird structure in ODE45 to represent y''': y(2);y(3)*h ?
Sergio Manzetti
2018 年 2 月 22 日
Thanks Torsten.
So ODE45 represents the form y''' + y(1-x^2)=0 as
[ y(2) y(3) y(1)*(2+x^2)]
Torsten
2018 年 2 月 22 日
No.
fun = @(x,y)[y(2);y(3);y(1)*(2+x^2)];
represents the system of ODEs
y1' = y2
y2' = y3
y3' = y1*(1-x^2)
And having a solution for y1, y2 and y3 of this system gives you a solution of y'''=y*(1-x^2) because y1'''=y2''=y3'=y1*(1-x^2).
Please read the document I linked to.
Best wishes
Torsten.
Sergio Manzetti
2018 年 2 月 22 日
編集済み: Sergio Manzetti
2018 年 2 月 22 日
Thanks! I did it read it, but haven't done this in 2 years, so it was not clear.
Cheers
Sergio Manzetti
2018 年 2 月 22 日
編集済み: Sergio Manzetti
2018 年 2 月 22 日
About the picture, I think I misunderstood you before, you said y, y' and y''. The colors are associated by default to y , y' and y''?

Torsten
2018 年 2 月 22 日
The first curve is the solution of your third-order ODE.
Use
plot(X,Y(:,1))
if you only want to see this curve and not also its first and second derivative.
Best wishes
Torsten.
Sergio Manzetti
2018 年 2 月 22 日
編集済み: Sergio Manzetti
2018 年 2 月 22 日
Thanks Torsten! PS: Is it possible with this to get the third order derivative of the solution?
Jan
2018 年 2 月 22 日
@Sergio: If you want the 3rd derivative, simply use the already provided function:
fun = @(x,y)[y(2);y(3);y(1)*(2+x^2)];
After
[X,Y] = ode45(fun,xspan,y0);
you have X and Y (which is [y, y', y'']. So you can calculate the 3rd derivative easily:
d3y = y(:,1) .* (2 + X .^ 2);
Sergio Manzetti
2018 年 2 月 28 日
Hi Jan, is it possible to plot the square modulus of the numerical solution following your suggestion here ?
Torsten
2018 年 2 月 28 日
Maybe, if you tell us what the "square modulus of the numerical solution" is.
その他の回答 (1 件)
Sergio Manzetti
2018 年 2 月 28 日
編集済み: Sergio Manzetti
2018 年 2 月 28 日
(abs(y))^2
if y is the solution
11 件のコメント
Sergio Manzetti
2018 年 3 月 9 日
編集済み: Sergio Manzetti
2018 年 3 月 9 日
Hi Torsten you wrote in the initial ODE45 command:
fun = @(x,y)[y(2);y(3);y(1)*(2+x^2)];
y0 = [1 0 0];
xspan = [0 5];
[X,Y] = ode45(fun,xspan,y0);
plot(X,Y(:,1),X,Y(:,2),X,Y(:,3));
but the first line fun appears to me as D3Y*(2+x^2)Y=0
Is this correct? If so it is not the function I wrote.
Sorry I have to re-check.
What I wanted to calculate is
y''' = y(2+x^2)
thus D3Y - y(2+x"2)=0
so would this code reflect that?
fun = @(x,y)[y(2);y(3);y(1)-(2+x^2)];
y0 = [1 0 0];
xspan = [0 5];
[X,Y] = ode45(fun,xspan,y0);
plot(X,Y(:,1),X,Y(:,2),X,Y(:,3));
Thanks!
Torsten
2018 年 3 月 9 日
The first line is
(1) y1'(x) = y2(x)
(2) y2'(x) = y3(x)
(3) y3'(x) = y1(x)*(2+x^2).
Thus the equation for y1 is
y1(x)*(2+x^2) = (from (3)) y3'(x) = (from (2)) y2''(x) = (from (1)) y1'''(x)
which means that y1 is the function you searched for.
Sergio Manzetti
2018 年 3 月 9 日
編集済み: Sergio Manzetti
2018 年 3 月 9 日
Thanks Torsten, does this mean that the third derivative in ODE45 is given by:
(1) y1'(x) = y2(x)
(2) y2'(x) = y3(x)
so y(2);y(3)?
Should I want to multiply a constant to the D3Y part, is it multiplied as such?:
fun = @(x,y)[y(2);y(3) *h;y(1)*(2+x^2)];
where h is the constant?
Sergio Manzetti
2018 年 3 月 9 日
編集済み: Sergio Manzetti
2018 年 3 月 9 日
OK, this is quite a new way to think...so one lists the levels of derivation of y as such?
Torsten
2018 年 3 月 9 日
You transform a higher order ODE to a system of first-order ODEs.
I already gave you the link to digest this.
参考
カテゴリ
Help Center および File Exchange で Ordinary Differential Equations についてさらに検索
タグ
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
アジア太平洋地域
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)