Are you blogging on PH? Get your free blog.

Matlab

Moderators: None (Apply to moderate this forum)
Number of threads: 597
Number of posts: 1018

This Forum Only
Post New Thread

Report
*while* loop homework problem Posted by jlkamikaze on 16 Nov 2009 at 2:22 PM
"One interesting property of a Fibonacci sequence is that the ratio of the values of adjacent members of the sequence approach a number called “the golden ratio” or PHI. Create a program that accepts the first two numbers of a Fibonacci sequence as a user input and then calculates additional values in the sequence until the ratio of adjacent values converges to within 0.001. You can do this in a WHILE loop by comparing the ratio of element k to element k-1 and the ratio of element k-1 to element k-2. If you call your sequence x, then the code for the WHILE statement is

while abs(x(k)/x(k-1) – x(k-1)/x(k-2))>0.001"

the first part of the code is:
x(1)=input('Enter the first starting value for your Fibonacci: ')
x(2)=input('Enter the second starting value for your Fibonacci: ')

^^^but idk how to complete the rest with the WHILE loop

i need to calculate how many terms [k] are needed to get an error within 0.001 units but im clueless...thanx in advance for any help guys



 
Popular resources and forums for programmers on Programmersheaven.com
Assembly, Basic, C, C#, C++, Delphi, Java, JavaScript, Pascal, Perl, PHP, Python, Ruby, Visual Basic
© Copyright 2009 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Publisher: Lars Hagelin. Read the latest words from the publisher here.
Be the first to sign up for Lars Hagelin’s In-depth Outsourcing Newsletter here.
bootstrapLabs Logo A BootstrapLabs project.