1
$\begingroup$

I am trying to compare plots of the function (1+x)^{1/3} and its power series. The code for the power series generates an error message referring to an invalid variable: 'General::ivar: -1.09993 is not a valid variable."' This message occurred with a minimum x of -1.1. Whatever value is given to the minimum x, the error message is always .00007 or .00008 greater. Yet it continues and plots the curve to maximum x. I would like to know the reason for the error message.

A previous similar question by @fasttouch "Plot Series output?" was closed as off-topic. The apparent correct answers were to apply Normal[], which I have done, and Evaluate[], which here seems to have no effect, as the curves with and without it coincide. If there is a trivial syntax error, it would not surprise me, but I can't see it, nor does the answer appear to be easily found in the documentation. I have Mathematica 8.

I am also wondering why I need to reference the series with an index in Plot, but not in Print.

x0 = 0; n = 30;

Print["Series up to 5th power: ", 
  Normal[Series[Power[1 + x, 1/3], {x, x0,  5}]]];

Plot[{
  Evaluate[Normal[Series[Power[1 + x, 1/3], {x, x0,  n}][[1]]]],
  Normal[Series[Power[1 + x, 1/3] + .01, {x, x0,  n}][[1]]]
  }, {x, -1.1, 2.5}, Background -> White]

After submitting this, I find that all works well if I write it this way:

s[x_] := Normal[Series[Power[1 + x, 1/3], {x, x0,  n}]];

Plot[Evaluate@s[x], {x, -1, 1}]

My current guess is that there was some confusion of the x's in Series[] and Plot[].

$\endgroup$
3
$\begingroup$

You have the x overloaded in too many places. You use it as free variable for the Series, then you use it for the plot command variable. I think this error happens because

 ?? Plot

show it has HoldAll. Then the x for the plot takes effect before the Series is expanded. But this 'x' is now a number, so Series complains as it needs a symbol.

But best to Keep things simple. One way:

ClearAll[x]
x0 = 0; n = 30;
ser = Normal[Series[Power[1 + x, 1/3], {x, x0, n}]];
f = (1 + x)^(1/3);
Plot[Evaluate@{ser, f}, {x, -1.1, 2.5}, Background -> White, 
     Frame -> True, PlotLegends -> {"Series", "function"}]

Mathematica graphics

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.