0
$\begingroup$

I am trying to code the following formulas:

enter image description here

I did it in the following way:

S[u_] := 2.94/(u + 520 E^(-0.14 u))
u[n_] := 1/\[CapitalSigma] Sum[X[i, x], {i, 2, n}];
X[1, n_ + 1] := S[u[n]] Sum[b[i] X[i, n], {i, 1, 13}]
X[i_ + 1, n_ + 1] := s[i] X[i, n]

But when I type X[1,5], it returns X[1,5] instead of some summation expression. This doesn't happens with u[7] tho. See:

enter image description here

What can be done? I tried to write X with $n,i$ and $n-1,i-1$ but it also doesn't work. Can I define it just as the formulas above?

$\endgroup$
3
  • 2
    $\begingroup$ X[i_ +1, n_ + 1] will apply to expression like X[3 + 1, 5, + 1]. What you want is for X to apply to X[4, 6], and then properly adapt the values (minus one). Therefore: X[1, n_] := S[u[n - 1]] Sum[b[i] X[i, n - 1], {i, 1, 13}]; X[i_, n_] := s[i - 1] X[i - 1, n - 1] $\endgroup$
    – Domen
    Nov 14 '21 at 9:01
  • 1
    $\begingroup$ However, you also have a mistake in the limits of the sum in the definition of u (should be {i, 2, 13}). Finally, there the definition for X[1, 1] is missing. $\endgroup$
    – Domen
    Nov 14 '21 at 9:07
  • $\begingroup$ If you want to retain the syntax (just for convenience), you can do With[{n = nplusone - 1}, X[i_, nplusone_] := <definition involving n>]. This will replace all ns with nplusone -1, then set the definition. $\endgroup$
    – thorimur
    Nov 14 '21 at 22:25

Your Answer

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

Browse other questions tagged or ask your own question.