Example2.2.5 Rev 1.doc

advertisement

Example 2.2.5 Stop Conditions

> restart:

> with(plots):

Enter the governing equations:

> eq[1]:=diff(y[1](t),t)=-10*y[1](t)^2+y[2](t);

> eq[2]:=diff(y[2](t),t)=10*y[1](t)^2-2*y[2](t);

Enter the variables:

> vars:=(y[1](t),y[2](t));

> eqs:=(eq[1],eq[2]);

> ICs:=(y[1](0)=1.,y[2](0)=0);

The governing equations are numerically solved as:

> sol:=dsolve({eqs,ICs},{vars},type=numeric);

The concentration profiles are plotted:

> odeplot(sol,[t,y[1](t)],0..2,title="Figure Exp.

2.2.10",axes=boxed,thickness=3);

Page 1

> odeplot(sol,[t,y[2](t)],0..2,title="Figure Exp.

2.2.11",axes=boxed,thickness=3);

Page 2

The objective is to find the time at which the maximum occurs. When y

2

attains the maximum value, zero and hence the right hand side of the equation becomes zero.

> sol:=dsolve({eqs,ICs},{vars},type=numeric,stop_cond=[-

2*y[2](t)+10*y[1](t)^2]);

If we try to evealute the solution at t=1, we get:

> ssol:=sol(1);

Warning, cannot evaluate the solution further right of .26421692, stop condition #1 violated

The numerical calculation stops when the residual is satisfied. The time at which the maximum occures is given by:

> ssol[1];

The maximum value of y

2

is given by:

> ssol[3];

Page 3

When we plot the solution, the profiles stop when the maximum value of y

2

is reached:

> odeplot(sol,[t,y[1](t)],0..2,title="Figure Exp.

2.2.12",axes=boxed,thickness=3);

Warning, cannot evaluate the solution further right of .26421692, stop condition #1 violated

> odeplot(sol,[t,y[2](t)],0..2,title="Figure Exp.

2.2.13",axes=boxed,thickness=3);

Warning, cannot evaluate the solution further right of .26421692, stop condition #1 violated

Page 4

>

Page 5

Download