Problem 292. Infernal Recursion
Consider the recursion relation:
x_n = (x_(n-1)*x_(n-2))^k
Given x_1, x_2, and k, x_n can be found by this definition. Write a function which takes as input arguments x_1, x_2, n and k. The output should be x_n.
For example, if x_1=exp(1), x_2=pi, n=5, and k=5/9 then:
R = get_recurse(exp(1),pi,5,4/9)
R = 2.31187497992966
Solution Stats
Problem Comments
-
4 Comments
is there a story as to why this is "infernal"?
I hate recursion, so it is all infernal to me! Iteration is the way to go...
Test suite could helpfully include n=1 and n=2 tests. I thought that it needed extra complexity to handle these, but @bmtran's top solution shows it doesn't.
I spend a lot of time to get the correct R from the example. The issue is that you say k = 5/9 instead of 4/9 . Just a typo to correct . Thanks
Solution Comments
Show commentsProblem Recent Solvers79
Suggested Problems
-
Is my wife right? Now with even more wrong husband
1322 Solvers
-
Project Euler: Problem 1, Multiples of 3 and 5
3169 Solvers
-
Back to basics 23 - Triangular matrix
1001 Solvers
-
Find perfect placement of non-rotating dominoes (easier)
350 Solvers
-
Create a random logical vector of N elements of which M are true.
101 Solvers
More from this Author6
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!