Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Specify Step Size in NDSolve

494 views
Skip to first unread message

Andrea

unread,
Nov 19, 2003, 5:07:06 AM11/19/03
to
I posted the following message Friday the 14th of November, but have
not yet seen it, so I apologize if you see this twice.

I am using NDSolve, and have run into an error with the step size it
is using.  I get errors at very small times.  Mathematica will
continue beyond this time point, but results are very inaccurate.

I have increased MaxSteps up to 10^7, and at this point my computer
runs out of memory and eventually calculations stop.  This option is
not useful if the step size Mathematica chooses is very small, no
matter how many steps you specify.  I have altered other step size
options (MaxStepSize, MaxStepFraction, StartingStepSize), but they
only let you choose the maximum step size or a starting step size.
Essentially, I want to do the opposite and specify a minimum step size
so that the step size does not decrease to a near-zero value and run
out of steps before reaching my final time point.  I have searched for
an option StepSize, but found nothing.  Please help if you can.

Below is some example code (vtime and ytime are lists of time points
specified elsewhere):

T=343824133;

titer[k_,delta_,n_,c_]:=
   
    Module[{soln,y,v,valueslist,xtiter,ytiter},
     
      soln=NDSolve[{
            y'[t]== k v[t] T -delta y[t],
            v'[t]== n delta y[t]-c v[t],
            y[0]==7016819, v[0]== 2220151},
          {y,v},{t,0,1500}, MaxSteps->{10^5}];
     
      ytiter=Evaluate[y[ytime]/.soln];
      vtiter=Evaluate[v[vtime]/.soln];
     
      values=Table[Flatten[{ytiter, vtiter},1]];
      values
      ];

calcs = titer[0.0297, 4.51, 46.38, 6.145]

NDSolve::mxst: Maximum number of steps reached at the point
t=0.3300736733965773

"InterpolatingFunction::dmval" Input value {26} lies outside the range
of data in the interpolating function. Extrapolation will be used.

Thanks,
Andrea Knorr
Graduate Student
Chemical Engineering
University of Connecticut

Curt Fischer

unread,
Nov 20, 2003, 3:40:57 AM11/20/03
to

"Andrea" <andrea...@engr.uconn.edu> wrote in message
news:bpffca$lt1$1...@smc.vnet.net...

> I posted the following message Friday the 14th of November, but have
> not yet seen it, so I apologize if you see this twice.
>
> I am using NDSolve, and have run into an error with the step size it
> is using. I get errors at very small times. Mathematica will
> continue beyond this time point, but results are very inaccurate.

I think the reason NDSolve was failing was that your equations were highly
stiff, given the value of T that you are using! You might have tried
specifying an implicit method such as BDF or ImplicitRungeKutta. (That
might not have solve the problem either, though--I'm not sure what the
default method for NDSolve is. Maybe it is smart already tried those.)

> soln=NDSolve[{
> y'[t]== k v[t] T -delta y[t],
> v'[t]== n delta y[t]-c v[t],
> y[0]==7016819, v[0]== 2220151},
> {y,v},{t,0,1500}, MaxSteps->{10^5}];

But these equations are linear and a symbolic solution is available! These
are the inputs from a Mathematica session in which I solved your equations
analytically with DSolve and plugged in the value of the parameters you
wanted (output deleted to save space).

In[1]:=
T = 343824133;


In[3]:=
soln = DSolve[{
y'[t] == k v[t] T - delta y[t],
v'[t] == n delta y[t] - c v[t],
y[0] == 7016819, v[0] == 2220151},
{y[t], v[t]}, {t}]


In[5]:=
{y[t], v[t]} /. soln[[1]] /. {k -> 0.0297, delta -> 4.51, n -> 46.38,
c -> 6.145}

0 new messages