TransWikia.com

Wrong answer with RSolve function

Mathematica Asked by Charmbracelet on June 2, 2021

The green function is defined as:

$left{begin{array}{l}G_{0}=1 G_{k}=sum_{j=1}^{k} phi^{prime} G_{k-j},quad k geqslant 1end{array}right.$

where

$phi_{j}^{prime}=left{begin{array}{l}phi_{j}, 1 leqslant j leqslant 2 0, j>2end{array}right.$

I want to use RSolve to get the sequence function of $G$,

RSolve[{g[0] == 1, 
g[k] == Sum[
If[j > 2, 0, Subscript[[Phi], j]]*g[k - j], {j, 1, k}]}, g[k], k]

However, the answer contains $phi_j$ which should be $phi_1$ or $phi_2$.

Solution with phi_j

Update & Solution

Thanks to @user64494, I edit the code and get the right answer.

Notice that when k=1, k-j may be a negative index, so g[1] should be added manually.

The code would be:

RSolve[{g[0] == 1, g[1] == Subscript[[Phi], 1], 
  g[k] == Sum[Subscript[[Phi], j]*g[k - j], {j, 1, 2}]}, g[k], k]

And the solution is:

$$
g(k)to frac{2^{-k-1} left(sqrt{phi _1^2+4 phi _2} left(phi _1-sqrt{phi _1^2+4 phi _2}right){}^k-phi _1 left(phi _1-sqrt{phi _1^2+4 phi _2}right){}^k+sqrt{phi _1^2+4 phi _2} left(sqrt{phi _1^2+4 phi _2}+phi _1right){}^k+phi _1 left(sqrt{phi _1^2+4 phi _2}+phi _1right){}^kright)}{sqrt{phi _1^2+4 phi _2}}
$$

But I still wonder why there’s a $phi_j$ in the previous solution. I assume every $phi$ should be evaluated before getting the solution, is this right?

One Answer

An approach using FindSequenceFunction

Clear["Global`*"]

Format[ϕ[n_]] = Subscript[ϕ, n];

phi[j_] = Piecewise[{{ϕ[j], 1 <= j <= 2}}];

g2[0] = 1;

g2[k_Integer?Positive] := g2[k] = 
 Sum[phi[j]*g2[k - j], {j, 1, k}]//Simplify

seq = Table[{k, g2[k]}, {k, 0, 7}] // Simplify

enter image description here

g[k_] = FindSequenceFunction[seq, k]

enter image description here

Checking,

And @@ Table[g[k] == g2[k], {k, 0, 20}] // Simplify

(* True *)

Correct answer by Bob Hanlon on June 2, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP