Re: NDSolve and MaxStepSize
- To: mathgroup@smc.vnet.net
- Subject: [mg11720] Re: NDSolve and MaxStepSize
- From: jtischer@pitagoras.univalle.edu.co
- Date: Thu, 26 Mar 1998 03:08:48 -0500
- Organization: Deja News - The Leader in Internet Discussion
- References: <6f1ksj$f7d@smc.vnet.net>
In article <6f1ksj$f7d@smc.vnet.net>, lang@einev.ch (Fred Lang) wrote: > > Dear MathGroup users, > > I have found the following naive behavior of NDSolve: > > In[1] = tmin = 0 ; t0 = 0.2 ; t1 = 0.5 ; tmax = 1 ; > > In[2] = f[t_] = Which[ t < t0 , 0.0 , t <= t1 , 0.5 , t <= tmax , 0 ] ; > > (* f(t) is a step function * ) > > In[3] = solution = > > NDSolve[ { v'[t] == f[t] , v[0] == 0 } , v[t] , {t,tmin,tmax} , > > , MaxSteps -> 5000 ] ; > > In[4] = vsol[t_] = v[t] /. solution ; > > vsol(t) is the null function! NDSolve has choosen a maximal step ! > > To receive the right answer I have to put MaxStepSize -> 0.01 : > > In[5] = solution = > > NDSolve[ { v'[t] == f[t] , v[0] == 0 } , v[t] , {t,tmin,tmax} , > > MaxStepSize -> 0.01 , MaxSteps -> 5000 ] ; > > In[6] = vsol[t_] = v[t] /. solution ; > > How can I convince my matlab engineering environment to use mathematica > with such a naive behavior? > > See you later. > > Fred Lang. > > I think Fred, you will convince them, if they are engineers. What is the MaxStepSize good for, if not for such a type of function? Playing around with your example I even could do better (or worse?) than you: Try this. On my pc (pentium pro, Win95), it produces something like an exponential curve. If you want to know what is happening here, have a look on FullForm[solution[[1,1,2]]]. f[t_] = Which[ t <= .002 , 0.0 , t < 1 , 0.5 , t ==1 , .00001 ]; solution = NDSolve[ { v'[t] == f[t] , v[0] == 0 } , v[t] , {t,tmin,tmax} , MaxSteps -> 5000 ] ; vsol[t_] = v[t] /. solution [[1]]; Plot[vsol[t],{t,0,1}] Jurgen -----== Posted via Deja News, The Leader in Internet Discussion ==----- http://www.dejanews.com/ Now offering spam-free web-based newsreading