1
$\begingroup$

I am trying to find the maximum element of the list for a given value of variable $c$. The example of the list is as follows:

List = {-1 + 6 (1 - c/2), -(9/10) + 6 (1 - c/2)}

I am trying to implement the following command:

Manipulate[Max[List], {c, 0, 2}]

Of course, it does not work. I guess Mathematica has some straightforward way of implementing this unknown to me. Any hint would be appreciated

$\endgroup$
7
  • 1
    $\begingroup$ (1) List is a built-in symbol. You can't set it's value. It is recommended that you use variable names that begin with lowercase (no built-in symbols are lowercase, so you know there won't be a name collision), or else use a naming pattern that you know won't result in name collisions. $\endgroup$
    – lericr
    Jul 25, 2022 at 22:01
  • $\begingroup$ @lericr noted, thank you. Luckily, I am using a different name in the actual file. $\endgroup$
    – Oleh
    Jul 25, 2022 at 22:02
  • $\begingroup$ (2) Manipulate will set up a sort of local scope for variable names. You used c as the dynamic variable in the Manipulate, but the "real" name of that variable will be different. So, the c in your list (defined outside of the Manipulate) is not the same c in the list expression. $\endgroup$
    – lericr
    Jul 25, 2022 at 22:04
  • $\begingroup$ You can either pull the expression explicitly into the Manipulate (rather than indirectly via a variable like list, or you can turn the static list variable into a function. Then pass your Manipulate c to the function inside the Manipulate. $\endgroup$
    – lericr
    Jul 25, 2022 at 22:06
  • $\begingroup$ My "or" wasn't intended to imply that these were the only two options. :) $\endgroup$
    – lericr
    Jul 25, 2022 at 22:06

1 Answer 1

3
$\begingroup$

Just to be explicit, here is a fairly clean way:

myExpression[arg_] := {-1 + 6 (1 - arg/2), -(9/10) + 6 (1 - arg/2)}

Manipulate[Max[myExpression[c]], {c, 0, 2}]
$\endgroup$

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.