5
$\begingroup$

I was wondering if it is possible to manipulate a FindFit[] function. As a basic example, if I had an equation $ax^2+bx+c$ and a set of data, would it be possible to manipulate the c value, while Mathematica outputs the best fit values for a and b for that c value?

$\endgroup$
  • 2
    $\begingroup$ Yes, just use an explicit value for c in the model you provide to FindFit. $\endgroup$ – Sjoerd C. de Vries Jul 12 '13 at 20:10
  • $\begingroup$ One can theoretically Manipulate any expression. But see the SynchronousUpdating option to Manipulate for handling expressions that take a long time to compute. $\endgroup$ – Michael E2 Jul 12 '13 at 23:38
5
$\begingroup$

Extending @bills answer a little further:

p = Table[Prime[x], {x, 20}];

Manipulate[
 Show[ListPlot@p, Plot[y /. FindFit[p, y = a x^2 + b x + c, {a, b}, x], {x, 1, 20}, 
                       Evaluated -> True]], 
{c, -10, 10}]

Mathematica graphics

$\endgroup$
4
$\begingroup$

Here's one way:

 p = Table[Prime[x], {x, 20}]; 
 Manipulate[FindFit[p, a x^2 + b x + c, {a, b}, x], {c, -10, 10}]

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.