MathGroup Archive 2007

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

Search the Archive

Re: V6 evaluation inside Table and plot

  • To: mathgroup at smc.vnet.net
  • Subject: [mg76649] Re: V6 evaluation inside Table and plot
  • From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
  • Date: Fri, 25 May 2007 06:33:35 -0400 (EDT)
  • Organization: The Open University, Milton Keynes, UK
  • References: <f33onq$l4v$1@smc.vnet.net>

Gerry Flanagan wrote:
> Define a simple function
> 
> In[7]:= f = Function[{x}, x^3]
> 
> Out[7]= Function[{x}, x^3]
> 
> Taking two derivatives works as it should
> 
> In[2]:= f''[x]
> 
> I was converting some packages to work with V6, and immediately ran into 
> some evaluation issues I don't understand. It looks like forms like 
> f''[x] (derivative) are evaluated differently inside of Table and Plot 
> than outside.
> 
> Out[2]= 6 x
> 
> But this does not?
> 
> In[20]:= Table[f''[x], {x, 0, 1, .2}]
> 
> Out[20]= {0, 0, 0, 0, 0, 0}
> 
> Strangely, this works
> 
> In[4]:= Table[f'[x], {x, 0, 1, .2}]
> 
> Out[4]= {0., 0.12, 0.48, 1.08, 1.92, 3.}
> 
> Determining the derivative outside the Table makes it work again.
> 
> In[12]:= g = f'';
> 
> In[21]:= tmp = Table[g[x], {x, 0, 1, .2}]
> 
> Out[21]= {0., 1.2, 2.4, 3.6, 4.8, 6.}
> 
> Gerry Flanagan
> 

Hi Gerry,

Just two comments. First, since you name the function and manipulate it, 
it might be more judicious to use a body definition without pure 
function (in this case, f behave as expected within Table). Second, the 
behavior you notice in version 6 is also present in earlier version of 
Mathematica (at least 5.2).

(* Version 6.0 *)
In[1]:=
Clear[f]
f[x_] := x^3
{f'[x], f''[x]}
Table[{x, f[x], f'[x], f''[x]}, {x, 0, 1, .2}] // TableForm

Out[3]= {3*x^2, 6*x}

Out[4]//TableForm= 0.    0.      0.     0.

0.2   0.008   0.12   1.2

0.4   0.064   0.48   2.4

0.6   0.216   1.08   3.6

0.8   0.512   1.92   4.8

1.    1.      3.     6.

In[5]:=
Clear[f]
f = Function[{x}, x^3]
{f'[x], f''[x]}
Table[{x, f[x], f'[x], f''[x]}, {x, 0, 1, .2}] // TableForm

Out[6]= Function[{x}, x^3]

Out[7]= {3*x^2, 6*x}

Out[8]//TableForm= 0.    0.      0.     0

0.2   0.008   0.12   0

0.4   0.064   0.48   0

0.6   0.216   1.08   0

0.8   0.512   1.92   0

1.    1.      3.     0

(* Version 5.2 *)
  Clear[f]
  f[x_]:= x^3
  { f'[x], f''[x]}
  Table[ { x, f[x], f'[x], f''[x]}, { x,0,1,.2}]//TableForm

==>
{3*x^2, 6*x}

0     0       0      0

0.2   0.008   0.12   1.2

0.4   0.064   0.48   2.4

0.6   0.216   1.08   3.6

0.8   0.512   1.92   4.8

1.    1.      3.     6.

  Clear[f]
  f= Function[ {x}, x^3]
  { f'[x], f''[x]}
  Table[ { x, f[x], f'[x], f''[x]}, { x,0,1,.2}]//TableForm

==>
Function[{x}, x^3]

{3*x^2, 6*x}

0     0       0      0

0.2   0.008   0.12   0

0.4   0.064   0.48   0

0.6   0.216   1.08   0

0.8   0.512   1.92   0

1.    1.      3.     0

Regards,
Jean-Marc


  • Prev by Date: Re: asymptotics
  • Next by Date: Re: asymptotics
  • Previous by thread: Re: V6 evaluation inside Table and plot
  • Next by thread: Re: V6 evaluation inside Table and plot