What does this statement mean "Use a for loop to move x = 'a' half the distance to 'b' and do it 'n' times."
显示 更早的评论
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'?
采纳的回答
更多回答(1 个)
David Young
2014-9-14
0 个投票
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.
类别
在 帮助中心 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!