0
$\begingroup$

I want to generate a numerical simulation in table for an equational output. I have used following code. But somehow I can't get any output. I am very novice to Mathematica. Can anyone please recommend what change I should make?

Subscript[r, 1] := (-2 Subscript[c, 1] + \[Gamma] Subscript[c, 
   2] - (-2 + \[Gamma]) (-a + \[Tau] + (2 + \[Gamma]) ((\[Tau] - \
\[Tau] Subscript[\[Rho], 1])/(v \[Theta] Subscript[\[Rho], 1]))^(
      1/(-1 + v))))/(-4 + \[Gamma]^2)
simStep := 
 Module[{\[Gamma], Subscript[\[Rho], 1], 
   v, \[Theta], \[Tau]}, {\[Gamma], Subscript[\[Rho], 1]} = 
   RandomReal[1, 2];
  {\[Theta]} = 2;
  {\[Tau]} = 1;
  {v} = {2};
  {\[Gamma]} = 0.5;
  {Subscript[c, 1]} = 1;
  {Subscript[c, 2]} = 1;
  {Subscript[\[Rho], 1], Subscript[r, 1]}]


```
$\endgroup$
0

1 Answer 1

0
$\begingroup$

You get a lot of red ink. Try to simplify. Avoid complicated notations. The most useful formula: f1[x_,y_]:=f2[x,y] where f2 must not call f1 to avoid recursion (unless you want it).

Don't use Module for grouping, use parenthesis.

Example:

Clear@f1;f1[x_,y_]:=(Print@x;x+2 y)

f1[2,3]

; suppresses output.

If you need double output use a list:

Clear@f1; f1[x_, y_] := {x + 1, x^2}

Test each step before going to the next.

Clear@f2; f2@{x_, y_} := x - y

f2[2,3]

f2@{2, 3}

f2@f1[2, 3]

f@x is the same as f[x]. Clear is to be sure to start with a clean symbol.

$\endgroup$
2
  • $\begingroup$ Is there any serious reason to use parenthesis instead of Module or Block? Or do you recommend it simply because it is lighter? $\endgroup$
    – anderstood
    Commented Feb 10, 2021 at 20:19
  • $\begingroup$ I just use the simplest structure that is necessary. Simple means easy to read and not using computer resources. Module[{},x;y] is same as (x;y), Module[{var},x] introduces a new variable each time it is used. I almost never introduce variables, I use constants, introduced by With. The instructions I gave are probably sufficient to use Mathematica as a programmable calculator like the ones used at school. $\endgroup$ Commented Feb 11, 2021 at 11:20

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.