MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: ODE with in a piece wise plot

  • To: mathgroup at smc.vnet.net
  • Subject: [mg104243] Re: ODE with in a piece wise plot
  • From: Hannes Kessler <HannesKessler at hushmail.com>
  • Date: Sun, 25 Oct 2009 01:04:43 -0400 (EDT)
  • References: <hbu7ps$7he$1@smc.vnet.net>

Hello Becky,

I don't understand what you mean with "put in a ODE where the (x-1)
is".
Nevertheless, here is an example how one can use your function in an
ODE:

E1 = If[-1 <= x <= 0, 1,   If[3 <= x <= 5, 2, If[-1 <= x <= 3=
, (x -
1)]]]

(* Equivalent but better looking *)
E1=PiecewiseExpand[E1]

(* Function definition using E1*)
f[xx_] := E1 /. x :> xx

(* Plot your function *)
Plot[f[x], {x, -5, 5}]

(* Use it as rhs in an ODE *)
equation=y'[x] + y[x] == f[x]
solution = NDSolve[{equation, y[-5] == 1}, y, {x, -5, 5}]

(* The solution function and its plot *)
yfunc = y /. First[solution]
Plot[yfunc[x], {x, -5, 5}]

By the way, you can enter a piecewise function definition similar to
the one obtained by PiecewiseExpand by entering <escape>pw<esacpe>
followed by one or more <ctrl>enter. Or use Piecewise[..] (look into
the Mathematica help for Piecewise).

Best regards,
Hannes Kessler

On 24 Okt., 08:45, "Becky" <noslow... at comcast.net> wrote:
> Can this be done?
>
> First of all, a basic example and then what I want to change.
>
> E1=If[-1<=x<=0,1,If[3<=x<=5,2,If[-1<=x<=3,(x-1)]]]
> Plot[E1,{x,-5,5}]
>
> The purpose of this was to join all three areas into one plot.
>
> Now!  I want to put in a ODE where the (x-1) is.  
>
> Is this possible, and if so, would you mind giving me an example?



  • Prev by Date: Re: Re: which values of m satisfies the inequality
  • Next by Date: Re: How to print/display symbolic expressions from inside a Module
  • Previous by thread: ODE with in a piece wise plot
  • Next by thread: Re: ODE with in a piece wise plot