Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #13809
| From | Bill Rowe <readnews@sbcglobal.net> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Re: How to plot functions |
| Date | 2013-03-11 05:41 +0000 |
| Message-ID | <khjqq5$77r$1@smc.vnet.net> (permalink) |
| Organization | Time-Warner Telecom |
On 3/10/13 at 12:48 AM, radressss@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[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]
and
In[8]:= g[c_] = c*x^2; g[3]
Out[8]= 3*x^2
Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread
Re: How to plot functions Bill Rowe <readnews@sbcglobal.net> - 2013-03-11 05:41 +0000
csiph-web