4
$\begingroup$

I am trying to plot and manipulate the following 3rd degree polynomial:

f[a_,b_,c_,d_][x_]=ax^3+bx^2+c*x+d;

Manipulate[Plot[f[a, b, c, d][x],{x, -2, 2},PlotRange->All],
{{a, 2.76},-4,4},{{b,-3.12},-5,5},{{c, 1.14},-5, 5},{{d, 3},-8,8}]

but at the same time I want my parameters to satisfy the following condition:

b^2-3a*c=0

I am struggling to understand how to import such condition to the parameters in Manipulate. I've tried Piecewise but it didn't work. Since this condition has to be satisfied when I manipulate one of the parameters the others should automatically change.

$\endgroup$
2
  • $\begingroup$ TrackingFunction is often a way to go $\endgroup$
    – Kuba
    Commented Nov 30, 2017 at 18:25
  • $\begingroup$ @Kuba it works! Thank you! $\endgroup$ Commented Dec 1, 2017 at 0:50

1 Answer 1

6
$\begingroup$

but at the same time I want my parameters to satisfy the following condition: b^2-3a*c=0

This can be done using second argument of dynamics as follows

enter image description here

Manipulate[
Grid[{
{Row[{Style["b^2-3a*c = ",16],Chop[b^2-3a*c]}]},
{Plot[(a*x^3+b*x^2+c*x+d)^2,{x,-2,2},PlotRange->All,ImageSize->400]
}},Frame->All,Spacings->{1, 1}],

Grid[{
{"a ",Manipulator[Dynamic[a,{a=#;c=#;b=Sqrt[3 a c]}&],{-4,7}],Dynamic[NumberForm[a,{3,3}]]},
{"b ",Manipulator[Dynamic[b,{b=#;c=#;a=b/3}&],{-5,5}],Dynamic[NumberForm[b,{3,3}]]},
{"c ",Manipulator[Dynamic[c,{c=#;b=#;a=c/3}&],{-4,7}],Dynamic[NumberForm[N@c,{3,3}]]},
{"d ",Manipulator[Dynamic[d,{d=#}&],{-5,5}],Dynamic[NumberForm[d,{3,3}]]}
}],
{{a,-1},None},
{{b,Sqrt[3.0]},None},
{{c,-1},None},
{{d,-3},None},
Alignment->Center,SynchronousUpdating->True,
SynchronousInitialization->True,
FrameMargins->1,ImageMargins->1,ControlPlacement->Left        
]

The above will insure b^2-3a*c=0 when changing a or b or c.

$\endgroup$
2
  • $\begingroup$ +1. But is there a way to do this with TrackingFunction? $\endgroup$ Commented Dec 19, 2017 at 1:31
  • $\begingroup$ @aardvark2012 as far as I know tracking function should work also, as it is similar to using second argument of dynamics, but I do not use trackingFunction. I like to find one method that works and stick to it. So I use the above method in all my manipulate code. If trackingFunction does not work for you, may be you could open a new question on this and someone who know more about this function could help. $\endgroup$
    – Nasser
    Commented Dec 19, 2017 at 1:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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