Solve second order differential equation with independent variable

2 ビュー (過去 30 日間)
Abhivyakti
Abhivyakti 2014 年 1 月 28 日
コメント済み: Azzi Abdelmalek 2014 年 1 月 28 日
I need the solution to the following second order differential equation:
D2y+(2/x)*Dy= 10*(y/(1+y));
I want to use ode45 for this. I have split the equation in the following manner :
%y(1)=y(x);
%y(2)=Y'(x);
So the equation can be written as :
y'(1)=y(2);
y'(2)=10*(Y(1)/(1+(y(1)))-(2/x)*Y(2);
When I solve this usind ode45, I get a matrix comprising of Nan values.
I believe the variation of the independent variable, i.e x, cannot be done like this.
I am not sure how to solve this.
Any help would be appreciated. Thanks! :)
  2 件のコメント
Amit
Amit 2014 年 1 月 28 日
Post the code for your function? Also what are the initial values for Y and Y'
Abhivyakti
Abhivyakti 2014 年 1 月 28 日
I just know one condition here, i.e When x is 'R', y id 's0'. Here R,s0 are constants.

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

回答 (1 件)

Azzi Abdelmalek
Azzi Abdelmalek 2014 年 1 月 28 日
編集済み: Azzi Abdelmalek 2014 年 1 月 28 日
Your function should be:
function dz=myode45(x,z)
dz(1,1)=z(2)
dz(2,1)=-2*z(2)/x+10*z(1)/(z(1)+1)
%Call myode45
tspan=[0.1 10];
% don't start tspan at 0, because in your equation there is -2z(2)/x
y0=[0;1]; % initial conditions
[x,y]=ode45('myode45',tspan,y0)
  4 件のコメント
Abhivyakti
Abhivyakti 2014 年 1 月 28 日
Alright. Tell me one thing, is it that 'tspan' is supposed to incorporate the variation of the values of 'x' ? I understood the values 'y' is storing but what about 'x' and 'tspan' ?
Azzi Abdelmalek
Azzi Abdelmalek 2014 年 1 月 28 日
tspan=[t0 tf] % t0 is a start time, and tf is a final time
x represent time or whatever you want. It's in your equation

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

カテゴリ

Help Center および File ExchangeMathematics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by