I am working with convergent series, and I need to plot each calculation of a loop, against the number of the loop. Rather than post my code in here, I thought I'd post a more basic code, and then I can re-arrange any solution to fit my code later on.
Imagine that the loop was calculating numbers in the Fibonacci sequence, and then dividing each number by it's previous to converge on Phi.
The following function would display each outcome as it got closer and closer to Phi (1.618)
How would I plot this, so that if the user entered 15 loops, the x-axis would have intervals of 1 and the y-values would be the outcome of each loop for 'r'?Code:clear all; loops=input('Loops: '); n1=0; n2=1; k=0; while (k<loops) r=n2/n1; f=n1+n2; display(r); n1=n2; n2=f; f=0; k=k+1; end


LinkBack URL
About LinkBacks