MathGroup Archive 2005

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

Search the Archive

Re: Why are the functions different?


Sure, f1[x] is fine, but what about f1[-1] (or any other x value in the Plot):

f1[x_] := Normal[Series[Tanh[x], {x, 0, 5}]]
f1[-1]

You get an error message saying -1. is not a valid variable, and indeed it isn't!

Instead, you can use:

x=. (* in case x had a value *)
f1[x_] = Normal[Series[Tanh[x], {x, 0, 5}]]

Now the Plot works.

Even if your original definition would work, you don't want to calculate the Series and Normal repeatedly, for every x value in the Plot. And that's what SetDelayed would do.

Bobby

On Thu, 31 Mar 2005 01:24:00 -0500 (EST), Helge Stenstroem <helge.stenstrom.NOSPAM at NOSPAMericsson.com> wrote:

> How are these two functions (f0 and f1) different? f0 can be plotted,
> but f1 cannot.
>
> f1[x_] := Normal[Series[Tanh[x], {x, 0, 5}]]
> f0[x_] := x - x^3/3 + (2*x^5)/15
>
> When evaluated like this:
>  f0[x]
>  f1[x]
> they look the same.
>
> The following gives error messages if f0 is replaced by f1.
>  Plot[{Tanh[z], f0[z]}, {z, -1, 1}]
>
> (Mathematica 4.1 on Windows 2000)



-- 
DrBob at bigfoot.com


  • Prev by Date: Re: Why are the functions different?
  • Next by Date: Re: Why are the functions different?
  • Previous by thread: Re: Why are the functions different?
  • Next by thread: Re: Why are the functions different?