       Re: InterpolatingFunction in NDSolve

• To: mathgroup at smc.vnet.net
• Subject: [mg21660] Re: InterpolatingFunction in NDSolve
• From: Bojan Bistrovic <bojanb at physics.odu.edu>
• Date: Fri, 21 Jan 2000 04:00:11 -0500 (EST)
• Organization: Old Dominion Universityaruba
• References: <86196r\$la7@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```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[y][x]==-10*y
> [x], y == 1},
>                     y,{x, 0, 0.5}]
>
> sss = (y[x] /. solution[])[];
>
> (* 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]]; *)
>
>
>
>      Print["Ooops!!!!"];
>
>      Abort[];
> ];
>
> sol2 = NDSolve[{Derivative[y][x] == Derivs[y,
> x], y == 0},
>                 y,{x, 0, 0.5}]
>
> Plot[Evaluate[y[x] /. sol2], {x, 0, 0.5}];
>
> Sent via Deja.com http://www.deja.com/

First of all, you don't nees the y variable in Derivs[y,x] (altho
it still works with it). Second, You don't need Block[{}, ...] (since
the whole idea of Block is to put something in {} which will be
blocked from any outside definitions and vice versa; outside
definitions won't be affected by the internal ones). The reason you
have problems is the Return command which is intended to be used in
different context (read the Mathematica Book for detailed explanation).
What you need is simply:

Derivs[x_]:= If[x < 0.25, sss[x], -sss[x]]
sol2 = NDSolve[{Derivative[y][x] == Derivs[x], y == 0},
y,{x, 0, 0.5}]

which DOES work.

Bye, Bojan

--
-------------------------------------------------------------
Bojan Bistrovic,                       bojanb at physics.odu.edu
Old Dominion University, Physics Department,      Norfolk, VA
-------------------------------------------------------------

```

• Prev by Date: Re: a question about complex variable
• Next by Date: Re: Header/Footer formatting question.
• Previous by thread: Re: InterpolatingFunction in NDSolve
• Next by thread: Re: Question:Polar Field Plot