0
$\begingroup$

To avoid affecting lamda in other part of my notebook, I have wrapped code with Module. After wrapping, red colored font appeared.Could I know the reason?

    Clear[n, \[Lambda], t];
Module[{\[Lambda] = 5},
 Manipulate[
  Plot[1 - Exp[-\[Lambda] t], {t, 0, 7}], {{n, 10}, 1, 100, 1}]]

enter image description here

$\endgroup$
4
  • 3
    $\begingroup$ With instead of Module. $\endgroup$
    – cvgmt
    Commented Feb 26 at 13:43
  • 3
    $\begingroup$ You should not put Manipulate inside another module. Manipulate is module itself and has it own way of deciding which symbols belong to it. The right way to do this is to put module inside Manipulate. Like this Clear[n, \[Lambda], t]; Manipulate[Module[{\[Lambda] = 5}, Plot[1 - Exp[-\[Lambda]* n * t], {t, 0, 7}] ], {{n, 10}, 1, 100, 1} , TrackedSymbols :> {n} ] $\endgroup$
    – Nasser
    Commented Feb 26 at 13:46
  • 1
    $\begingroup$ You get red symbols when you do something like this Module[{a = 5}, Module[{a}, Exp[a*t]]] and this is basically the same thing you did. It is just that Manipulate under the cover becomes dynamic module. $\endgroup$
    – Nasser
    Commented Feb 26 at 13:47
  • 1
    $\begingroup$ Or just make λ another control variable in the Manipulate with its initial value set to 5. $\endgroup$
    – Bob Hanlon
    Commented Feb 26 at 18:01

0

Your Answer

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

Browse other questions tagged or ask your own question.