Question: USING MATLAB CODE TO SOLVE THIS We showed an instrumented version that computed the number of recursive function calls using a persistent variable. Another way

USING MATLAB CODE TO SOLVE THIS
We showed an "instrumented" version that computed the number of recursive function calls using a persistent variable. Another way to try to profile the function calls you make is to save a trace. For example, it can be a vector whose elements capture the order the function was called with the various input arguments. In this problem, you need to modify the function above, so that it has an additional input argument, a vector v. The vector needs to store the input arguments of the recursive function calls in the order they were made. Let's call the function fibo_trace, Here is an example run:
f=fibo(n-2)+fibo(n-1);
end
end
We showed an "instrumented" version that computed the number of recursive function calls using a persistent variable. Another way to try to profile the function calls you make to save a trace. For example, it can be a vector whose elements capture the order the function was called with the various input arguments. In this problem, you need to modif the function above, so that it has an additional input argument, a vector v. The vector needs to store the input arguments of the recursive function calls in the order they were made. Let's call the function fibo_trace, Here is an example run:The output shows that the function was first called with input argument 6, then it was called again with 4 and then with 2. Is this correct? Yes, because we initially called it with then it called itself with n-2, that is 4, and that instance of the function called itself with ( n-2), that is 2. At that point there are no further recursive calls, it simply returned the solution 2 to the previous call (with 4) and it called the function again with ( n-1), that is,3. And so on.Once you have a trace like this, you can identify if the function works as intended or not. You can also use the trace to plot a histogram. See below. Disregard the first bar, but what the heights of the other bars are and try to figure out what the pattern is. Once you solved the problem, make the histogram yourself with a larger input like 10 or 15. It is fascinating indeed!
[f trace ]=fibotrace (10,[]);
> histogram(trace)
 USING MATLAB CODE TO SOLVE THIS We showed an "instrumented" version

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!