What does this statement mean "Use a for loop to move x = 'a' half the distance to 'b' and do it 'n' times."
Afficher commentaires plus anciens
I am creating a function m file called mystepcloser, this is the information I was provided with.
mystepcloser(a,b,n) which takes three inputs:
a: A real number.
b: A real number which you may assume is greater than 'a'.
n: A positive integer.
Does: Uses a for loop to move x = 'a' half the distance to 'b' and do it 'n' times.
Returns: The final value of 'a'.
I do not understand what it is suppose to do. What does it mean to move x='a' half the distance to 'b' and do it 'n' times. How would I go about creating a for loop that does this, and how would I make the for loop return the final value of 'a'?
Réponse acceptée
Plus de réponses (1)
David Young
le 14 Sep 2014
0 votes
Suppose a is 3 and b is 7. Then the 'distance' from a to b is 4, half the distance is 2, and moving a that much towards b means adding 2 to a to make it 5. Then do it again and a becomes 6 ... and so on.
Catégories
En savoir plus sur Logical dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!