The test suite includes a simple recursive Fibonacci sequence generator, but it's terribly inefficient. One simple method for improving its performance is using a technique called memoization. Write a function that takes a function_handle that we wish to memoize and returns a function_handle to a memoized version of the initial handle.
Solution Stats
Problem Comments
6 Comments
Solution Comments
Show comments
Loading...
Problem Recent Solvers101
Suggested Problems
-
Project Euler: Problem 1, Multiples of 3 and 5
3672 Solvers
-
Project Euler: Problem 3, Largest prime factor
1789 Solvers
-
Create a square matrix of multiples
497 Solvers
-
Find the sides of an isosceles triangle when given its area and height from its base to apex
2142 Solvers
-
497 Solvers
More from this Author56
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
Whoops, accidentally had the answer in the test suite. Fixed now.
Bryant,
Any chance you can elaborate a bit? I can make a memoized fibonacci code, but that's not really what you're asking. I don't get what the function call with 2 arguments (and 2nd argument the function itself) is in the test set: seq = memfib(n-1, memfib);
Sorry for the confusion.
Paul, it uses a feature that was just introduced in R2017a. If the answer hadn't accidentally been in the test suite, I never would have figured this one out either!
I tried comparing this code with a non-memoized version, and it was 6 times slower!
Love the name of the problem.^^
As difficult as the problem looks, (one of the) solution is quite easy and straight forward.