       Re: How to plot functions

• To: mathgroup at smc.vnet.net
• Subject: [mg130118] Re: How to plot functions
• From: Bill Rowe <readnews at sbcglobal.net>
• Date: Sun, 10 Mar 2013 17:08:12 -0400 (EDT)
• Delivered-to: l-mathgroup@mail-archive0.wolfram.com
• Delivered-to: l-mathgroup@wolfram.com
• Delivered-to: mathgroup-newout@smc.vnet.net
• Delivered-to: mathgroup-newsend@smc.vnet.net

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

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

>when I try to plot this directly,

>Plot[ f, {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 is undefined
resulting in no plot being displayed. Notice, the difference between

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

Out= f

and

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

Out= 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