I need help creating a loop.
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Akzeptierte Antwort
Image Analyst
am 23 Mär. 2013
Bearbeitet: Image Analyst
am 23 Mär. 2013
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 Kommentare
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!