Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2008

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

Search the Archive

Re: Draw two functions in a graph, one of them does also

  • To: mathgroup at smc.vnet.net
  • Subject: [mg90194] Re: [mg90176] Draw two functions in a graph, one of them does also
  • From: Murray Eisenberg <murray at math.umass.edu>
  • Date: Wed, 2 Jul 2008 05:28:26 -0400 (EDT)
  • Organization: Mathematics & Statistics, Univ. of Mass./Amherst
  • References: <200807011101.HAA15055@smc.vnet.net>
  • Reply-to: murray at math.umass.edu

First of all, you don't have two functions of x: you have the function f 
of x and then you have a function of two variables a and x.  I presume 
you wish to treat a as a parameter in g.

Second, you don't have Mathematica syntax for the two functions!

Here's one way:

    f[x_] := -x^2 + 6 x
    g[a_][x_] := a x

    Plot[{f[x], Table[g[a][x], {a, 0, 3}]}, {x, 0, 1}]

Add an option if you wish that makes the zero function (when a==0) be 
more visible:

    Plot[{f[x], Table[g[a][x], {a, 0, 3}]}, {x, 0, 1},PlotStyle->Thick]


That plots f in one color and the several g[a] in a second color.  If 
you want automatic coloring with more than two colors, you could do this:

   Plot[Evaluate@{f[x], Table[g[a][x], {a, 0, 3}]}, {x, 0, 1}]

(I don't know why the Evaluate does this!)

Another approach is to treat g as a function of two variables:

    Clear[g]
    g[a_,x_]:=a x

And then:

    Plot[{f[x], Table[g[a, x], {a, 0, 3}]}, {x, 0, 1}]


Felipe Mannshardt wrote:
> Is there a way to do a Plot do draw this two functions in the same graph ?
> I am asking because i am having problems due the parameter  "a".
> 
> I have,
> 
> f(x)= -x^2 + 6x
> g(x)= ax
> 
> i want to draw them in the same graphic and with a from 0 to 3 . . .
> 
> Can not think of a way of doing this, due the "a" parameter . . .
> 
> Plot[{f[x],[g[a][x]},{x,0,7},{a,0,3}]
> 
> 
> Can some help me out with this small issue ?
> 
>

-- 
Murray Eisenberg                     murray at math.umass.edu
Mathematics & Statistics Dept.
Lederle Graduate Research Tower      phone 413 549-1020 (H)
University of Massachusetts                413 545-2859 (W)
710 North Pleasant Street            fax   413 545-1801
Amherst, MA 01003-9305


  • Prev by Date: Re: For loop problem in mathematica
  • Next by Date: Re: Mouse focus in Mathematica
  • Previous by thread: Draw two functions in a graph, one of them does also have a parameter.
  • Next by thread: Re: Draw two functions in a graph, one of them does also have a parameter.