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

1 view (last 30 days)
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!

Answers (1)

Azzi Abdelmalek
Azzi Abdelmalek on 19 Oct 2012
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=[];

Community Treasure Hunt

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

Start Hunting!