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

3 vues (au cours des 30 derniers jours)
Urvi
Urvi le 19 Oct 2012
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!

Réponses (1)

Azzi Abdelmalek
Azzi Abdelmalek le 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=[];
  2 commentaires
Urvi
Urvi le 19 Oct 2012
why have you given y1=0 y2=0 y3=0? I need them from my odes.
Azzi Abdelmalek
Azzi Abdelmalek le 19 Oct 2012
it's just an initialization, not effect

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by