2nd order ode by ode45 or other numerical method

Hi every one,
I am trying to solve below differential equation with matlab:
y''+(2/x)*y'=0.1248y
B.C 1 : y'(0)=0
B.C 2: y(1)=1
x interval: [0 1]
solution interval (or y): [0 1]
I used bvp4c and ode45 but every time I faced with error like "solve the collocation equations -- a singular Jacobian encountered"
this is my code:
function SolveBVP()
solinit = bvpinit([0,1],[0 0]);
sol = bvp4c(@deriv,@bcs,solinit);
x=linspace(0,1,100);
y=deval(sol,x);
plot(x,y(1,:),'b-x');
function dYdx = deriv(x,Y)
dYdx(1) = Y(2);
dYdx(2) = 0.1248*Y(1)-(2/x)*Y(2);
function res = bcs(ya,yb)
res = [ ya(2)
yb(1)-1];
It would be appricated if any one of you can help me.
best regards

 採用された回答

Ameer Hamza
Ameer Hamza 2020 年 5 月 10 日
編集済み: Ameer Hamza 2020 年 5 月 10 日

0 投票

You ODE have term 2/x, which becomes infinite at x=0. To avoid this, start the limit a bit above 0 (say 1e-20). Also, it is better to pass the initial guess at several points. Try this
x=linspace(1e-20,1,100);
solinit = bvpinit(x,[1 0]);
sol = bvp4c(@deriv,@bcs,solinit);
y=deval(sol,x);
plot(x,y(1,:),'b-x');

その他の回答 (1 件)

Rasoul Rahimzadeh Bafti
Rasoul Rahimzadeh Bafti 2020 年 5 月 10 日

0 投票

Dear Ameer,
Thanks for your kind response and consideration. That was very helpful!!!
Sincerely,
Rasoul

カテゴリ

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by