Message Boards Message Boards

0
|
5092 Views
|
2 Replies
|
1 Total Likes
View groups...
Share
Share this post:

Why won't the LinearModelFit tutorial work for ma?

Posted 10 years ago

Hi folks, Probably a silly question for most of you, but I'm trying to switch to Mathematica for doing fits, linear and nonlinear. In working through the tutorials for LinearModelFit[ ], I cant get this to run:

data = Table[{3 + i + RandomReal[{-3, 7}], i + RandomReal[{-2, 5}]}, {i, 1, 20}];
model = LinearModelFit[data, x, x]
Show[ListPlot[data], Plot[model["BestFit"], {x, 0, 20}]]

The error is:

LinearModelFit::ivar: {0} is not a valid variable. >>

I guess that it has something to do with the initialization of the variable x ? ... I just copied the tutorial from the LinearModelFit page and tried to run it. Any help would be most appreciated, J.

POSTED BY: Jeff Cruzan
2 Replies

Somewhere you must have done something like:

x={0}

The symbol you use for a variable must be, well, variable, without a value assigned. You can remove values from the symbol x using:

Clear[x]

Or, you can start with a fresh kernel.

POSTED BY: John Doty

Strange, I copied your code, pasted it in and it ran perfectly for me.

Tim

POSTED BY: Tim Mayes
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract