2
$\begingroup$

I'm not grokking the use of Manipulate when an expression contains Rules. This example works and throws no errors -

maxSol[a_] := FindMaximum[{Sin[x], {x > 0, x < a}}, {x, 1/2}]
fn[a_] := (x /. Last@maxSol[a])
Manipulate[
 maxSol[a],
 {{a, 1/2, "a"}, 1/10, 1, Appearance -> "Labeled"}]

But it complains about the Rule from FindMaximum not being a Rule when I do this,

maxSol[a_] := FindMaximum[{Sin[x], {x > 0, x < a}}, {x, 1/2}]
fn[a_] := (x /. Last@maxSol[a])
Manipulate[
 fn[a],
 {{a, 1/2, "a"}, 1/10, 1, Appearance -> "Labeled"}]

because it somehow transforms the Rule into its replacement value only. I'm having a hard time understanding why x is affected by Manipulate when it is not a control variable.

$\endgroup$
4
  • $\begingroup$ It works fine for me (Mma 12.2, Win10) $\endgroup$ – Alexei Boulbitch May 18 at 16:14
  • $\begingroup$ I cannot reproduce the problem on 12.1.1.0 on Mac. Image at the link: screencast.com/t/Ar8lrWoRsy $\endgroup$ – Sim May 18 at 17:29
  • $\begingroup$ I upgraded to 12.2 from 12.1 and the error disappeared. $\endgroup$ – andrescorrada May 18 at 19:55
  • $\begingroup$ Thanks, Alexei Boulbitch, for doing the version check on Windows $\endgroup$ – andrescorrada May 19 at 12:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.