How can I write an algorithm to calculate $R_n$s for any desired $n$ from the following equation with given $f,R_0$?

So the output of the code would be $R_1,R_2,...$


I have derived this equation for my specific problem myself and I can calculate every $R_n$ manually but since $R_n$ is not separable I don't know how to write a code for it.

Any ideas?

  • 1
    $\begingroup$ Move everything over to one side so you have $g(R_n) = 0$, then you can compute the roots of this equation using any nonlinear solver or "root-finding algorithm" that you like, e.g., bisection method, iterative methods. $\endgroup$ – amarney Nov 22 '17 at 23:19
  • 2
    $\begingroup$ It's a linear equation in $R_n$, isn't it, because $R_n^2$ cancels from both sides? $\endgroup$ – Kirill Nov 23 '17 at 2:53
  • $\begingroup$ @Kirill Thanks, I did a little math since yesterday and could move the $R_n$ to one side of the equation. I'll post an answer myself. $\endgroup$ – Alireza Nov 23 '17 at 9:15

So I did a little math and I noticed $R_n^2$ cancels from both sides as @Kirill noticed in the comments.

I post this for clarification.

$$R_n^2-2fR_n=R_0^2-2fR_0+\sum_{i=0}^n\sum_{j=0}^nR_iR_j$$ $$R_n^2-2fR_n=R_0^2-2fR_0+\sum_{i=0}^{n-1}\sum_{j=0}^{n-1}R_iR_j+R_n\sum_{j=0}^nR_j+R_n\sum_{i=0}^{n-1}R_i$$ $$R_n^2-2fR_n=R_0^2-2fR_0+\sum_{i=0}^{n-1}\sum_{j=0}^{n-1}R_iR_j+R_n\sum_{j=0}^{n-1}R_j+R_n^2+R_n\sum_{i=0}^{n-1}R_i$$ $$R_n=\frac{R_0^2-2fR_0+\sum_{i=0}^{n-1}\sum_{j=0}^{n-1}R_iR_j}{-2(f+\sum_{i=0}^{n-1}R_i)}$$

| cite | improve this answer | |

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.