1
$\begingroup$

I am working on a Mathematica notebook and making graphs for my lab. I can't make a graph for my linearized data as LinearModelFit gives equation in z even though I pass x as an argument.

linfit = LinearModelFit[data, x, x]
$\endgroup$
  • 3
    $\begingroup$ Use ClearAll[x] before linfit =...? $\endgroup$ – kglr Sep 26 '18 at 23:51
1
$\begingroup$

Somewhere/sometime before LinearModelFit[data,x,x] is invoked you must have defined x as z. To check if this is the case you can use ValueQ:

ValueQ[x]

gives True if a value has been defined for x, and gives False otherwise. Alternatively, you can use

?x

which returns

enter image description here

if x is previously assigned a value, just the first line otherwise.

The following simple examples replicates your case:

x = z;
data = {{0, 1}, {1, 0}, {3, 2}, {5, 4}};
linfit = LinearModelFit[data, x, x]

enter image description here

As a fix, you can use ClearAll to clear all values, definitions, attributes, messages, and defaults associated with x before using x in LinearModelFit:

ClearAll[x]
linfit = LinearModelFit[data, x, x]

enter image description here

$\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.