How to get the output for the following code into the workspace?

3 ビュー (過去 30 日間)
Urvi
Urvi 2012 年 10 月 19 日
My code is as follows:
function H = newmain
global b1 b2 b3;
b1=0;
b2=2.0;
b3=0.33;
options=odeset('InitialStep', 0.01, 'MaxStep', 0.01, 'RelTol', 10., 'AbsTol',10.);
[t2,y2]=ode45(@equation,[0:0.05:0.1],[1 2 0], options);
H = [t2 y2]
end
function dy=equation(t,y)
global b1 b2 b3
dy=zeros(3,1);
b1=b1+1-exp(-b3)
b2=b1-y(1)
b3=b1+b2+y(2)
dy(1)=-b1*y(1);
dy(2)=b3*y(1)+b2*y(2);
dy(3)=sqrt(b1)+y(1)+y(3);
end
How can directly get the values of b1 b2 b3 y1 y2 y3 at the same time instant in the workspace?
Thanks!

回答 (1 件)

Azzi Abdelmalek
Azzi Abdelmalek 2012 年 10 月 19 日
function dy=equation(t,y)
global c b1 b2 b3 y1 y2 y3
y1=y(1);y2=y(2);y3=y(3);
dy=zeros(3,1);
b1=b1+1-exp(-b3)
b2=b1-y(1)
b3=b1+b2+y(2)
dy(1)=-b1*y(1);
dy(2)=b3*y(1)+b2*y(2);
dy(3)=sqrt(b1)+y(1)+y(3);
c=[c; b1 b2 b3 y1 y2 y3]
add in your main program
global c b1 b2 b3 y1 y2 y3
y1=0;y2=0;y3=0;c=[];
  2 件のコメント
Urvi
Urvi 2012 年 10 月 19 日
why have you given y1=0 y2=0 y3=0? I need them from my odes.
Azzi Abdelmalek
Azzi Abdelmalek 2012 年 10 月 19 日
it's just an initialization, not effect

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

カテゴリ

Help Center および File ExchangeOrdinary Differential Equations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by