Re: InterpolatingFunction in NDSolve
- To: mathgroup at smc.vnet.net
- Subject: [mg21647] Re: InterpolatingFunction in NDSolve
- From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
- Date: Fri, 21 Jan 2000 03:59:56 -0500 (EST)
- Organization: Universitaet Leipzig
- References: <86196r$la7@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Hi, the code Clear[sss]; Clear[solution]; Clear[sol2]; solution = NDSolve[{Derivative[1][y][x] == -10*y[x], y[0] == 1}, y, {x, 0, 0.5}] sss = (y[x] /. solution[[1]])[[0]]; (*interpolating function seems to be ok : can Plot it*) Plot[sss[t], {t, 0, 0.5}]; Derivs[y_, x_?NumericQ] := If[x < 0.25, sss[x], -sss[x]] sol2 = NDSolve[{Derivative[1][y][x] == Derivs[y, x], y[0] == 0}, y, {x, 0, 0.5}] Plot[Evaluate[y[x] /. sol2], {x, 0, 0.5}]; works fine. What is your problem ? Look at my Derivs[] function and never test a unrestricted pattern against a number. Hope that helps Jens eborzova at my-deja.com wrote: > > Hi everybody. > My question could be simple, but I just can't > figure it out. I need to use InterpolatingFunction > inside yet another function (Derivs) that is rhs > for NDSolve (please refer to the code below). The > problem is that if my rhs "Derivs" has some sort > of conditional logic (e.g. "If"), then it stops > working (see a comment with Return[sss[x]]). > > Any help/hints/feedback are greatly appreciated! > > Thanks. > Elena. > Clear[sss]; > Clear[solution]; > Clear[sol2]; > solution = NDSolve[{Derivative[1][y][x]==-10*y > [x], y[0] == 1}, > y,{x, 0, 0.5}] > > sss = (y[x] /. solution[[1]])[[0]]; > > (* interpolating function seems to be ok: can > Plot it *) > Plot[sss[t], {t, 0, 0.5}]; > > Derivs[y_, x_] := Block[{}, > > (* uncomment below to make it work *) > > (* Return[sss[x]]; *) > > If[x < 0.25, Return[sss[x]], Return[-sss > [x]]]; > > Print["Ooops!!!!"]; > > Abort[]; > ]; > > sol2 = NDSolve[{Derivative[1][y][x] == Derivs[y, > x], y[0] == 0}, > y,{x, 0, 0.5}] > > Plot[Evaluate[y[x] /. sol2], {x, 0, 0.5}]; > > Sent via Deja.com http://www.deja.com/ > Before you buy.