Using a for loop to compute a Taylor series of sine?
조회 수: 3 (최근 30일)
이전 댓글 표시
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/149870/image.png)
I understand while loops pretty well, but for loops always seem to throw me off. Can someone please help me? Thanks.
댓글 수: 2
James Tursa
2015년 10월 8일
Please make an attempt and post your code, and then ask specific questions about it. Then we can comment on it and make suggestions.
채택된 답변
Stalin Samuel
2015년 10월 8일
%%sample code
prompt = 'Enter angle value between 0 to 2pi? ';
x = input(prompt)
prompt = 'Enter the no of terms? ';
N = input(prompt)
ty = 0;
for i = 1:N
ty = ty +((-1)^(i))*((x^(2*i+1))/(factorial(2*i+1)));%your calculations
end
fprintf(['actual value ' num2str(ty)]) %display the results
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!