Re: beginner plot function with parameter

• To: mathgroup at smc.vnet.net
• Subject: [mg74041] Re: beginner plot function with parameter
• From: Bill Rowe <readnewsciv at sbcglobal.net>
• Date: Wed, 7 Mar 2007 03:12:30 -0500 (EST)

```On 3/6/07 at 5:30 AM, wei_li92 at hotmail.com (Wei Li) wrote:

>I am using mathematica 5 to plot a function with some parameter, I
>want to plot for example a simple parabolic function with positive
>parameter s:

>f[z_]:=(z/s)^2; Plot[f[z],{z,-s,s}];

This code cannot create a plot unless s has been previously set
to a numeric value.

That is doing:

s=3;
f[z_]:=(z/s)^2;
Plot[f[z],{z,-s,s}];

Should generate a plot for you.

Note, it is generally not a good idea to make the result of a
function dependent on a global variable assigned elsewhere.
Inevitably, particularly in large notebooks, this leads to
unexpected results and can be quite time consuming to locate why
those results occurred.

A better way to write f that avoids this problem would be

f[z_,s_]:=(x/s)^2

Or if you simply wanted to create several different plots you
could do the following:

f[s_]:=
Block[{z}, Plot[(z/s)^2, {z, -s, s}]]

With this definition you could easily generate a family of
parabolas as follows:

Show[
Block[{\$DisplayFunction=Identity}, f/@Range[3]]];
--
To reply via email subtract one hundred and four

```

• Prev by Date: analytic integration of InterpolatingFunction compositions
• Next by Date: Re: Transformation rules - explain please
• Previous by thread: Re: beginner plot function with parameter
• Next by thread: Re: beginner plot function with parameter