MATLAB Answers

Simple system of ODES with starting condition

5 ビュー (過去 30 日間)
Velimir Corovic
Velimir Corovic 2019 年 12 月 9 日
Commented: Rena Berman 2019 年 12 月 12 日
opts = odeset('RelTol',1e-15,'AbsTol',1e-20);
X0 = [ 0.9 0.1 0 ];
[T X] = ode45(@(t,X)returnDerivative(t, X), [0 10], X0,opts) ;
plot(T,X);
function dXdt = returnDerivative(t, y)
dXdt = [-1/2*y(1)*y(3) ; 1/3*y(3) ; 1/2*y(1)*y(3) - 1/3*y(3)];
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
I am trying to solve this simple system of ODEs but it returns me constant solutions for X(1),X(2) and X(3)
and dimension of X is only 41 x 3 .Can someone explain me where is my mistake?
And what is in general best way to solve this kind of system of ODEs

  4 件のコメント

表示 1 件の古いコメント
Velimir Corovic
Velimir Corovic 2019 年 12 月 12 日
if I thought thst someone could learn from my question I wouldn't remove it , the question wasn't good because my concetration was very bad and I miscoded initial condtions.That's the reason of deleting question.
Star Strider
Star Strider 2019 年 12 月 12 日
If you want to re-post the corrected question, please do so.
Rena Berman
Rena Berman 2019 年 12 月 12 日
(Answers Dev) Restored edit

サインイン to comment.

件の回答 (1)

Star Strider
Star Strider 2019 年 12 月 9 日
The only (relative) mistake I can see is that it is not good to use global variables. Pass the values as extra parameters instead.
This works:
b=1/2;
k=1/3;
opts = odeset('RelTol',1e-15,'AbsTol',1e-20);
X0 = [ 1 0.00001 0 ];
[T X] = ode45(@(t,X)returnDerivative(t, X, b, k), [0 10], X0,opts) ;
plot(T,X);
function dXdt = returnDerivative(t, y, b, k) %X je vektor 4Nx1
dXdt = [-1/2*y(1)*y(3) ; 1/3*y(3) ; 1/2*y(1)*y(3) - 1/3*y(3)];
end
What result were you expecting?

  1 件のコメント

Star Strider
Star Strider 2019 年 12 月 10 日
I cannot find anything wrong with your code.
If you are copying a system of ODEs and may haave mis-coded them, please post the original (symbolic) expressions and initial conditions. I will see if I can find the error.

サインイン to comment.

サインイン してこの質問に回答します。

タグ


Translated by