I need help creating a loop.

조회 수: 1 (최근 30일)
Mark
Mark 2013년 3월 22일
Our teacher asked us to create a loop that calculates sin(x) to nth number of terms.
our professor obviously doesnt know how to use matlab because he has not helped us at all.
can someone help with this? i want to learn and comprehend what is going on?
-sin(x) = x-(x^3/3!)+(x^5/5!)-(x^7/7!
-The calculation should stop when the magnitude of the last terms is less than .0000006, it should work for positive and negative values
-The function should return the estimate and number of terms required to get this accuracy
After___terms sin(__) is approximated to be_____.
  댓글 수: 3
Azzi Abdelmalek
Azzi Abdelmalek 2013년 3월 22일
What have you done so far?
Mark
Mark 2013년 3월 22일
I have tried a few different things, and none of them seem to work, and I am getting lost in some of the code. I would just lke a push in the right direction. My math skills are pretty sharp and I have figured most of this out on my own. I just dont know where to begin on this problem. There seem to be too many variables for me to sort through. I do not want an answer. Only guidance.
Thanks mark mark

댓글을 달려면 로그인하십시오.

채택된 답변

Image Analyst
Image Analyst 2013년 3월 23일
편집: Image Analyst 2013년 3월 23일
Here's a hint
x = 1.234; % Whatever...
theSum = 0;
for term = 1 : 10000
thisTerm = ...... % you do it. Involves x and term.
theSum = theSum + thisTerm; % Accumulate
if abs(thisTerm) < .0000006
break;
end
end
fprintf('The final sum = %f', theSum);
  댓글 수: 2
Mark
Mark 2013년 3월 23일
thank you. this makes sense, i will upload my formula when im done.
Jan
Jan 2013년 4월 4일
@Mark: It would be helpful if you post the solution.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by