1
$\begingroup$

Newbee to MMA, and completely have no clue about it. I need do a calculation of some iteration, seen in the picture below.

$n=3,4,5,..., \begin{cases} L_n=c_n\\ L_{n-1}=c_{n-1}\\ L_{n-p+1}=\displaystyle\sum_{r=1}^{p-2} (p-r-1)\;c_{p-r-1}\;L_{n-r+1}+c_{n-p+1}\;(p=3,4,5,...,n)\\ \end{cases}$

And for convenience and necessity,n equals 8. And the code is editted as

Subscript[L, 8] = Subscript[c, 8]
Subscript[L, 7] = Subscript[c, 7]
Subscript[L, 9 - p] =  
 Sum[(p - r - 1)*Subscript[c, p - r - 1]*Subscript[L, 9 - r] + 
        Subscript[c, 9 - p], {r, 1, p - 2}](*p=3,4,5,6,7,8*)

2 problems are encountered here.

Problem 1:

$c_1$ to $c_8$ is considered as constants with no certain values. Which code is needed to make it happen?

Problem 2:

As can be seen in the last part of my code, p has a range from $3$ to $8$. And again, which code is needed?

After searching so much info on the Internet, no solution is acquired....

$\endgroup$
  • 1
    $\begingroup$ Being a newbee, avoid Subscript. It is made for formatting, not calculations. For your indexed symbols, simply use c[8], L[7] etc. You can use a Do loop over p to get all the definitions done. $\endgroup$ – Marius Ladegård Meyer Jul 13 '17 at 13:56
  • $\begingroup$ @MariusLadegårdMeyer thank you for your advice about Subscript, but I do need use it for further programming, for the iteration presented here is just a small step in my work. And I will try Do loop. Thank you again. $\endgroup$ – Robin_Lyn Jul 14 '17 at 1:37
1
$\begingroup$

I agree in part with Marius Ladegård Meyer concerning Subscript : never use it in the left-hand side of a definition because you cannot easily remove it after. But I like using it on the right hand side. So,

L[8] := Subscript[c, 8]    
L[7] := Subscript[c, 7]    
L[k_] := Sum[((9 - k) - r - 1)*Subscript[c, (9 - k) - r - 1]*
    L[9 - r] + Subscript[c, k], {r, 1, (9 - k) - 2}]   

remark the use of := instead of = : delayed assignment
Also remark the substitution 9-p -> k in defining the left hand side of the sum : read up on 'pattern recognition' to learn why you need a single argument there (like ' k ' and not a subtraction like ' 9-p ' )
and last but not least,L[k_]:= read up on 'Patterns' and argument naming.
You'll get the hang of it soon enough. ;-)

$\endgroup$
  • $\begingroup$ Many thankssssss for your help. And the problem 1 is still no solved, that can Subscript[c, i](i=1,2,3,...,8) be considered as constants and how to do it? And after that, whether is it possible to get mathematical expressions of L[k_] you mentioned above? @Wouter $\endgroup$ – Robin_Lyn Jul 14 '17 at 1:50
  • $\begingroup$ @Robin_Lyn : have you tried to use the definitions in my answer to express the values of L[k] using Table[L[k], {k, 8}]? it produces {6 Subscript[c, 1] + 5 Subscript[c, 5] Subscript[c, 7] + 6 Subscript[c, 6] Subscript[c, 8] + 4 Subscript[c, 4] (Subscript[c, 6] + Subscript[c, 1] Subscript[c, 8]) +.... $\endgroup$ – Wouter Jul 14 '17 at 10:36
  • 1
    $\begingroup$ yes, I tried and it works~~~And the calculations followed are solved all the way down, for they are similar iterations. A huge stone in my heart is taken away. Greaaaat jooooooy! $\endgroup$ – Robin_Lyn Jul 14 '17 at 11: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.