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!