how do i access the inside of the interpoating functions
- To: mathgroup at smc.vnet.net
- Subject: [mg43518] how do i access the inside of the interpoating functions
- From: shawn_s_kim at yahoo.com (sean k)
- Date: Thu, 18 Sep 2003 05:40:23 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
good to see the group back up. What I would like to do is to look inside the interpolatingn functions generated by the NDSolve in Mathematica. so take y[t] -> InterpolatingFunction[{{0., 25.}}, "<>"][t] for instance. I need to figure out a few things about this interpolating function. 1. what is the Maximum y[t] value and the t value associated with that in the range of t given. (if there are more than on maximums, then the value of the first one that occurs in terms of time and the value of t. ) 2. what is the half Maximal y[t] value and the t values associated with it? 3. are any of values less than 0? if it has at least a single value that is negative, thenn I would like to throw out the integration( is this a proper way to control for artifacts/or targets?) For 1, 2 what I have thought initially is to use Table and use some kinda logic along with it. but it will be too slow since the intervals will be have to be sufficienly small. For 3, I'm kinda stumped. Similarly i can use table but its still going to be so slow... There has to be another way to approachthis problem? So far only thing that I have found in the math group archives that does something similar to what I want is to use the FindRoot as below. It seems to work for the equations that saturate( second cells pasted below), but not for the type shown below. I's using lorenz eqn's here as an example. This really isn;t very good example since the maximum comes later in the time range, but my systems shows maximums before in the eralier time points. begin first cell---- solution = NDSolve[{Derivative[1][x][t] == -y[t] - z[t], x[0] == -0.04, Derivative[1][y][t] == x[t] + 0.425*y[t], y[0] == -0.3, Derivative[1][z][t] == 2 - (4 - x[t])*z[t], z[0] == 0.52}, {x[t], y[t], z[t]}, {t, 0, 25}, Method -> RungeKutta] (*ParametricPlot3D[Evaluate[{x[t], y[t], z[t]} /. solution], {t, 0, 25}, PlotPoints -> 1000, PlotRange -> All];*) (*pulling out interpolating functions*) interp = solution[[1, 2, 2]] (*finding the maxvalues for y[t]*) maxYoft = Max[Table[interp, {t, 0, 25, 1}]] (*finding the t value for max Y this doesn't work. is there any other ways to do this? instead of using findroot? I don't quite understand how it's working, and it seems to cause lotta errors which means i would have to use Check[] on this too....*) tformaxY = FindRoot[interp == maxYoft, {t, 0}] (*half maximal y*) halfmaxY = ( maxYoft)/2 (*tfor half maximal y*) {t, halfmaxY} tforhalfmaxY = FindRoot[interp == halfmaxY, {t, 0}] Plot[Evaluate[y[t] /. solution], {t, 0, 25}]; end first cell--- this one below works as expected and pick out at least the half maximal values and time associated with it and generates no errors. begin second cell --- In[1]:= NDSolve[{D[y[t], t] == 1 - y[t], y[0] == 0}, y[t], {t, 0, 20}]; secondCellsol = y[t] /. %[[1]] maxy = Max[Table[secondCellsol, {t, 0, 20, 0.01}]] halfmaxy = maxy/2 FindRoot[secondCellsol == halfmaxy, {t, 1}] Plot[secondCellsol, {t, 0, 10}, PlotRange -> {0, 2}] end second cell ---