开发者

how to do substitution of n-1->n in mma

开发者 https://www.devze.com 2023-02-09 17:23 出处:网络
I have defined Subscript[S,n]=Subscript[X,n]+Subscript[S,n-1] For the expression: 3*n^2 – 6* n* Subscript[S, -1 + n] ^2

I have defined

Subscript[S,n]=Subscript[X,n]+Subscript[S,n-1]

For the expression:

3*n^2 – 6* n* Subscript[S, -1 + n] ^2 

I want to do n-1->n, but it seems

3*n^2 – 6* n* Subscript[S, -1 + n] ^2/. {n-1->n}

This way I got

3 n^2 - 6 n (Subscript[S, -1 + n] + Subscript[X, n])^2

does not do what I want. I want 3*n^2 be re-written as an equivalent using n-1, in this case, 3*(n-1)^2+6*(n-1)+3, then do the substitution to get 3*n^2+6*n+3

Overall, I want to have:

3*n^2+6*n+3+6*n*Subscript[S, n] ^2+6* Subscript[S, n] ^2

i.e. I also do not want mma to expand Subscript[S, n] in the final r开发者_开发问答esult.

How to do this in mma automatically?

Thanks a lot.


I'm not sure why you have the initial definition...

It looks like the result that you want (apart from some signs) follows from the simple

In[1]:= (3n^2-6 n Subsuperscript[S, n-1, 2])/.n->n+1//Expand
Out[1]= 3 n^2 + 6 n + 3 - 6 n Subscript[S, n]^2 - 6 Subscript[S, n]^2

As for not expanding out the Subscript terms in the final result, maybe you want something like

Collect[%1, Subscript[__], Factor]
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号