solve a complex second order differential equation

the ode has a form:
and for, given , how could I use ode45 to solve it with plot? thx

 採用された回答

Bjorn Gustavsson
Bjorn Gustavsson 2021 年 10 月 20 日
編集済み: Bjorn Gustavsson 2021 年 10 月 20 日

0 投票

The first step is to convert your second-order ODE to two coupled first-order ODEs:
Then you should write that ODE-system as a matlab-function:
function [dphidt_domegadt] = yourODEs(t,phi_w)
phi = phi_w(1);
w = phi_w(2);
dphidt = w;
if t == 0 % Here I assume that domegadt/t goes to zero as t -> 0+, perhaps there are solutions for other finite values of that ratio...
domegadt = phi^3;
else
domegadt = -2/t*dphidt - phi^3;
end
dphidt_domegadt = [dphidt;
domegadt];
This should be possible to integrate with ode45:
phi0w0 = [1 0];
t_span = [0 exp(2)]; % some limits of yours
[t,phi_w] = ode45(@(t,phi_w) yourODEs(t,phi_w),t_span,phi0w0);
HTH

9 件のコメント

嘉杰 程
嘉杰 程 2021 年 10 月 20 日
I am afraid I can't run this code?
Bjorn Gustavsson
Bjorn Gustavsson 2021 年 10 月 20 日
My bad, forgot to combine the derivatives. Done now.
However, you seriously need to consider the division-by-zero issue, as hinted at in the code and outlined by Walter in his answer.
嘉杰 程
嘉杰 程 2021 年 10 月 21 日
編集済み: 嘉杰 程 2021 年 10 月 21 日
I have a further question, if I have a parameter t, the eqs goes like: ,
I want to solve it when t varies from certain scale, when , I want to plot relation, given too, could you help me switch the code for it? thx
(or can we just use integral to solve this problem?)
Walter Roberson
Walter Roberson 2021 年 10 月 21 日
That only has a solution when t = 1.
嘉杰 程
嘉杰 程 2021 年 10 月 21 日
編集済み: 嘉杰 程 2021 年 10 月 21 日
What I want to plot is lane-emden eqs, refer to Lane-Emden Differential Equation -- from Wolfram MathWorld
but I can't do like that when n=3.
Walter Roberson
Walter Roberson 2021 年 10 月 21 日
implies that is a contant independent of η . further tells us that which tells us that . When then because is indepdent of . This carries over to as we know the must be 0, and tells us that y must be 0 except perhaps when is infinite.
But your talk about which is irrelevant, as you have no other places with
I have a suspicion that you intended to imply that ϕ is a family of functions in variable t but your notation is wrong for that.
Walter Roberson
Walter Roberson 2021 年 10 月 21 日
I do not see any resemblence between the forms posted in https://www.mathworks.com/matlabcentral/answers/1567938-solve-a-complex-second-order-differential-equation#comment_1793988 and the link to tbe Lane-Emden Differential Equation
嘉杰 程
嘉杰 程 2021 年 10 月 21 日
every t determine certain curvature of phi and eta, when eta=0, phi(eta)=1, phi'(eta)=0, that's one side, another side is determined by t
嘉杰 程
嘉杰 程 2021 年 10 月 22 日
actually this is only a specific function when n=3

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

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2021 年 10 月 20 日

0 投票

You cannot use any numeric solver for that. You have initial conditions at η = 0, but at 0 you have a division by 0 which gets you a numeric infinity. That numeric infinity is multiplied by the boundary condition of 0, but numeric infinity times numeric 0 gives you NaN, not 0.
If you work symbolically you might think that the infinity and the 0 cancel out, but that only works if the φ' approaches 0 faster than 1/η approaches infinity, which is something that we do not immediately know to be true.

3 件のコメント

嘉杰 程
嘉杰 程 2021 年 10 月 20 日
So is there any suggestion?
嘉杰 程
嘉杰 程 2021 年 10 月 20 日
If I let to be a quite small number?
Bjorn Gustavsson
Bjorn Gustavsson 2021 年 10 月 20 日
That is not enough. The ratio of 1/t*dphi/dt has to behave well for t = 0.

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

カテゴリ

ヘルプ センター および File ExchangeProgramming についてさらに検索

製品

リリース

R2021b

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by