MathGroup Archive 2013

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

Search the Archive

Re: How to plot functions

  • To: mathgroup at
  • Subject: [mg130118] Re: How to plot functions
  • From: Bill Rowe <readnews at>
  • Date: Sun, 10 Mar 2013 17:08:12 -0400 (EDT)
  • Delivered-to:
  • Delivered-to:
  • Delivered-to:
  • Delivered-to:

On 3/10/13 at 12:48 AM, radressss at (radres) wrote:

>Let's say I've defined a function f[c]=c*x^2

>when I try to plot this directly,

>Plot[ f[3], {x, -10, 10} ]

>it doesn't plot anything.

Right. Define f as follows:

f[c_]:= c*x^2

There are two key points. First, I've used SetDelayed (:=)
rather than Set (=). This results in the function f being
evaluated when it is used by Plot, not before. Using Set causes
f to be evaluated when it is defined. That is usually not the
behavior you want for a function.

Second, and more important, I've used c_ not c as the argument
for f. The pattern c_ matches anything and gives it a local name
of c. So, call f with a numeric value, Mathematica replaces the
c on the right hand side with the values supplied.

Without the blank(_) portion and with Set, you have defined f
for the symbol c, not anything else. That is f[3] is undefined
resulting in no plot being displayed. Notice, the difference between

In[7]:= f[c] = c*x^2; f[3]

Out[7]= f[3]


In[8]:= g[c_] = c*x^2; g[3]

Out[8]= 3*x^2

  • Prev by Date: Re: How to plot functions
  • Next by Date: Re: How to plot functions
  • Previous by thread: Re: How to plot functions
  • Next by thread: MixedRadixQuantity