MathGroup Archive 2007

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

Search the Archive

Re: piecewise plot

  • To: mathgroup at smc.vnet.net
  • Subject: [mg78899] Re: piecewise plot
  • From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
  • Date: Thu, 12 Jul 2007 05:19:58 -0400 (EDT)
  • Organization: The Open University, Milton Keynes, UK
  • References: <f72b8v$9gl$1@smc.vnet.net>

Jake Trexel wrote:
> I would like to plot something like this with version 6
> At time 0 to 10 the current is 0, at time 10 to 20 it is 1, time 20 to 30 it 
> is 0, time 30 to 40 it is -0.5, time 40 to 50 it is 0, then at time 50 to 60 
> it is +2.
> I would like to break each of these up into something like this eq1:= for 0 
> to 10, eq2 := 10 to 20 and so on.  Then I want to combine the equations into 
> a plot.  Then I would like to fill in the different sections with different 
> colors.
> I will then go one with another eq. that uses these results and filled in 
> areas to show  how they interact.  I will worry about this after my first 
> question.
> Can some one help me?
> thanks
> Prof. Jake
> Former Professor of Mechanical Engineering 

Does

f[x_] := Piecewise[{{0, Inequality[0, LessEqual, x, Less, 10]},
        {1, Inequality[10, LessEqual, x, Less, 20]},
        {0, Inequality[20, LessEqual, x, Less, 30]},
        {-(1/2), Inequality[30, LessEqual, x, Less, 40]},
        {0, Inequality[40, LessEqual, x, Less, 50]},
        {2, Inequality[50, LessEqual, x, Less, 60]}}]
Plot[f[x], {x, 0, 60}, Filling -> 0., FillingStyle ->
      Directive[Opacity[0.5], Orange]]

help you?

Regards,
Jean-Marc


  • Prev by Date: Re: piecewise plot
  • Next by Date: Re: piecewise plot
  • Previous by thread: Re: piecewise plot
  • Next by thread: Re: piecewise plot