Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2004
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2004

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

Search the Archive

RE: Problems with Plot in Mathematica 4.0, Combining Plots with Different Domains

  • To: mathgroup at smc.vnet.net
  • Subject: [mg45846] RE: [mg45806] Problems with Plot in Mathematica 4.0, Combining Plots with Different Domains
  • From: "David Park" <djmp at earthlink.net>
  • Date: Tue, 27 Jan 2004 04:50:39 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

Manfred,

There are a number of ways to combine two plots with different domains.
Let's define your two functions.

f1[x_] := 1/2x^2 - x
f2[x_] := -1/2x^2 + x

We could combine them into one function using UnitSteps and make a regular
Plot.

f[x_] := f1[x](UnitStep[x + 3] - UnitStep[x]) +
    f2[x](UnitStep[x] - UnitStep[x - 3])

Plot[f[x], {x, -4, 4},
    Frame -> True,
    PlotRange -> All];

But if you want to deal with them as separate functions you could combine
two plots with the following statement.

Block[{$DisplayFunction = Identity},
  g1 = Plot[f1[x], {x, -3, 0}];
  g2 = Plot[f2[x], {x, 0, 3}];
  ]
Show[g1, g2,
    Frame -> True,
    PlotRange -> {{-4.1, 4.1}, All}];

Here the Block statement gives a local value to $DisplayFunction so as to
supress the side plots. Or you could use the DisplayTogether command from
Graphics`Graphics`.

Needs["Graphics`Graphics`"]

DisplayTogether[
    Plot[f1[x], {x, -3, 0}], Plot[f2[x], {x, 0, 3}], Frame -> True,
    PlotRange -> {{-4.1, 4.1}, All}];

The last two methods are sometimes a little tricky because they don't always
pick up all Options from the second plot.

Another method is to try the DrawGraphics package from my web site below.

Needs["DrawGraphics`DrawingMaster`"]

Draw2D[
    {Draw[f1[x], {x, -3, 0}],
      Draw[f2[x], {x, 0, 3}]},
    Frame -> True,
    PlotRange -> {{-4.1, 4.1}, All}];

Here the Draw statements are like the Plot statement except they just
extract the primitive graphics without making side plots. You could easily
add in other plot type graphics and Lines, Points, Text primitives or
graphics directives, or you could manipulate the primitive graphics before
drawing.

David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/





From: Manfred Fischer [mailto:manfis at t-online.de]
To: mathgroup at smc.vnet.net

Hi,

I want to plot the two functions in one Plot output
+0.5x^2-x (definition-range -3<=x<=0)
-0.5x^2+x (definition-range 0<=x<=3)

I can't find a mathematica 4.0 solution, please help!

-ManFis -





  • Prev by Date: Re: Equation counting in arXiv style sheet
  • Next by Date: Re: Simple question or how Mathematica getting on my nerves.
  • Previous by thread: Re: RE: GridPlot
  • Next by thread: Integraton & Minimization and complex number problem