0
$\begingroup$

I am trying to run the function to perform a plot but instead, I am getting the error:

enter image description here

Message[With::lvset, {dt = 0.01, tfinal = 100., \[Gamma] = 1, k = 1, 
  Subscript[\[Sigma], 1] = 1, Subscript[\[Sigma], 2] = 2}, 
 Subscript[\[Sigma], 1] = 1, Subscript[\[Sigma], 1]]

The function, which is a for loop that stores the values in a list and plots them is :

With[{dt = 0.01, tfinal = 100.0, \[Gamma] = 1, k = 1, 
  Subscript[\[Sigma], 1] = 1, Subscript[\[Sigma], 2] = 2},
 x = {0, 0};
 a = 0.0;
 alist = {};
 dtsqrt = Sqrt[dt];
 M = ( {
    {1 + 1, -1},
    {-1, 1 + 1}
   } );
 \[Sigma] = ( {
    {1, 0},
    {0, 2}
   } );
 Do[
  dx = -M.x*dt + 
    dtsqrt*\[Sigma]. RandomVariate[NormalDistribution[], 2];
  a += x[[1]] dx[[2]] - x[[2]] dx[[1]] ;
  x += dx;
  AppendTo[alist, {t, a}], {t, dt, tfinal, dt}];
 p1 = ListPlot[alist, Joined -> True];
 Show[p1]
 ]

Could you tell me where the error emerges from or perhaps how to stop it from occurring?

$\endgroup$
3
  • 3
    $\begingroup$ The error message is trying to tell you that you cannot have Subscript[\[Sigma], 1] = 1 or Subscript[\[Sigma], 2] = 2 as part of the specification of With. Subscripts don't always behave how you might expect them to, so it's better to avoid them until you learn more about when they work and when they don't. There are some good posts on this site about possible workarounds if you really need to have a subscript. If you don't absolutely require a subscript, I would use \[Sigma]1 = 1 and \[Sigma]2 = 2. $\endgroup$
    – MassDefect
    Commented May 18, 2021 at 20:52
  • $\begingroup$ Thank you It worked $\endgroup$
    – user4933
    Commented May 18, 2021 at 20:57
  • 1
    $\begingroup$ You can use Format[σ1] = Subscript[σ, 1] to have σ1 display as a Subscript in output. $\endgroup$
    – Bob Hanlon
    Commented May 18, 2021 at 20:58

1 Answer 1

0
$\begingroup$

Don't use Subscript to name your variables. Name them $a1$ and $a2$ for example. This would solve the problem.

$\endgroup$
2
  • $\begingroup$ Why would this be the case? $\endgroup$
    – user4933
    Commented May 18, 2021 at 22:21
  • 2
    $\begingroup$ Subscripted variables are not symbols, which is what your error msg is telling you. The Notation package can transform subscripted variables to symbols, but you had better know what you are doing before using that pkg. It is generally best not to use subscripts unless absolutely necessary. $\endgroup$
    – Bill Watts
    Commented May 18, 2021 at 22:31

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.