Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

When I evlauate

data = RandomReal[10, {5, 10, 2}];
fit[i_] := FindFit[data[[i]], a Sin[x] + b, {a, b}, x]
fit[1]

I get something like:

{a -> 0.177375, b -> 3.91185}

Then, I try to plot the points and the fitted function together in one figure.

Show[ListPlot @ data[[1]], Plot[a Sin[x] + b /. %, {x, 0, 10}]]

With % I can get the figure I want, but

Show[ListPlot @ data[[1]], Plot[a Sin[x] + b /. fit[1], {x, 0, 10}]]

returns errors.

Why does this occur? Why can't I insert fit[1] in ReplaceAll, and how can I correct my mistake?

share|improve this question

closed as off-topic by Artes, m_goldberg, bobthechemist, Michael E2, Sjoerd C. de Vries Apr 21 at 16:35

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Artes, m_goldberg, bobthechemist, Michael E2, Sjoerd C. de Vries
If this question can be reworded to fit the rules in the help center, please edit the question.

5  
You should use Plot[Evaluate[a Sin[x] + b /. fit[1]], {x, 0, 10}] or Plot[a Sin[x] + b /. fit[1], {x, 0, 10}, Evaluated -> True]. –  Artes Apr 21 at 13:31
    
Thank you @artes but I can't even found the Evaluated function in the documentation center. But it works! –  bushiwo Apr 21 at 13:39
1  
Evaluate is a function and it is documented. Evaluated is an option. It is not documented indeed. –  Sjoerd C. de Vries Apr 21 at 16:34

Browse other questions tagged or ask your own question.