1
$\begingroup$

I am looking at the following mathematica code

Subscript[ff, r1_, r2_, CC_][x_, y_] := (r1 x + r2 y) (1 - (x + y)/CC)
Subscript[gg, r1_, r2_, CC_][x_, y_] := x

enter image description here

and am wondering why the $r1,r2,CC$ variables are written as subscripts instead of being included as []'s. What does putting a variable as subscript do? I tried looking for this information here but didn't find my answer.

$\endgroup$
2
  • 2
    $\begingroup$ See here (18395) $\endgroup$ – Sektor Mar 19 '16 at 7:34
  • $\begingroup$ By writing it this way the author is separating parameters from variables. Using Subscript is a big no-no in Mathematica programming (as Sektor's link indicates). While it is possible to use it, it leads to problems more often than not. Please resist the temptation to use it. $\endgroup$ – Sjoerd C. de Vries Mar 19 '16 at 14:52
2
$\begingroup$

It's a matter of notation.

I'd have written the functions as

ff[r1_,r2_,CC_,x_,y_]:= (r1*x + r2*y)(1 - (x + y)/CC)
gg[r1_,r2_,CC_,x_,y_]:= x

And would have gotten the same results if I called them to calculate

Input: Print[ff[1,2,3,4,5],",",gg[1,2,3,4,5]]
Output: -28,4

with

Input: Print[Subscript[ff,1,2,3][4,5],",",Subscript[gg,1,2,3][4,5]]
Output: -28,4

My guess is that the author of the code snippet wishes to keep seperate the subscript variables from the (x,y) variables for his own (aesthetic or not) reasons.

You can also see from here that the Subscript[] function is used just for formatting purposes.

$\endgroup$
2
  • 1
    $\begingroup$ If you read the post I linked to you will see that this behaviour is not always consistent. $\endgroup$ – Sektor Mar 19 '16 at 10:22
  • $\begingroup$ Unfortunately I've read your very informative link after my post. Thanks ! $\endgroup$ – milia Mar 20 '16 at 23:05

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.