The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Inactive » comp.soft-sys.math.mathematica

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: How to plot functions
Replies: 5   Last Post: Mar 11, 2013 1:41 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Bill Rowe

Posts: 1,647
Registered: 3/14/08
Re: How to plot functions
Posted: Mar 11, 2013 1:41 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

On 3/10/13 at 12:48 AM, (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

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.