MathGroup Archive 2010

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

Search the Archive

Re: Manipulate Series Expansions

  • To: mathgroup at smc.vnet.net
  • Subject: [mg112991] Re: Manipulate Series Expansions
  • From: Andrea <btlgs2000 at gmail.com>
  • Date: Sun, 10 Oct 2010 06:40:58 -0400 (EDT)
  • References: <i8pgeo$fgh$1@smc.vnet.net>

On Oct 9, 12:34 pm, Daniel <bridg... at gmail.com> wrote:
> I'm new to Mathemtica and have been searching the net for a while
> regarding using Manipulate to compare a series expansion to the
> original function, but haven't found an adequate solution to my
> errors.
>
> Why doesn't this work:
>
> Manipulate[
>  Plot[{Normal[Series[Sin[x], {x, 0, n}]], Sin[x]}, {x, -10 Pi,
>    10 Pi}, PlotRange -> 2], {n, 1, 100, 1}]
>
> I can do this to make it work as intended:
>
> p[x_, n_] := Normal[Series[Sin[y], {y, 0, n}]] /. y -> x
> Manipulate[
>  Plot[{p[x, n], Sin[x]}, {x, -10 Pi, 10 Pi}, PlotRange -> 2], {n, 1,
>   100, 1}]
>
> Any information would be helpful.

Hi Daniel, I try to help you and Mathematica gurus will correct me if
I'm wrong.
The problem is that the Plot function has the attribute HoldHall as
you can see running Attributes[Plot]. Functions with this attribute
receive their arguments unevaluated. This is useful because in this
way you can execute successfully coomands as Plot[Sin[x],{x,0,1}]
though you have previously set e.g x=1. If Plot had not this attribute
the previous command would be equivalent to Plot[Sin[1],{1,0,1}] and
Plot would fail.In your situation Plot will receive
{Normal[Series[Sin[x], {x, 0, 3}]], Sin[x]} and not {x - x^3/6,
Sin[x]} if you set n=3. Presumably in evaluating the value of the
function you passed to it at a particular point,e.g. 0, Plot will
execute  {Normal[Series[Sin[x], {x, 0, 3}]], Sin[x]}/.x->0 obtaining
{Normal[Series[Sin[3], {0, 0, 3}]], Sin[0]} that is not what you want
and will cause an error in Series function.
however there is a way to go round HoldHall attribute. You just have
to wrap with Evaluate the argument that you want to be evaluated. So
Manipulate[
 Plot[Evaluate@{Normal[Series[Sin[x], {x, 0, n}]],
    Sin[x]}, {x, -10 Pi, 10 Pi}, PlotRange -> 2], {n, 1, 100, 1}] will
work fine.
In my experience misunderstaning of the order of evaluation of
expressions in Mathematica is one of the most common source of errors
and programming in Mathematica at a more than trivial level without a
sufficient understanding of this argument can be a nightmare.I
recommend to you the sections of Mathematica guide in the chapter
http://reference.wolfram.com/mathematica/tutorial/EvaluationOfExpressionsOv=
erview.html
hope been useful
Andrea Mercuri


  • Prev by Date: Re: Astronomical Data Accuracy
  • Next by Date: Re: Generation of polynomials
  • Previous by thread: Re: Manipulate Series Expansions
  • Next by thread: Binary data file conversion