Taylor series calculation sin(x)

Hello! i write a function to caculate sin(x) and x should be typed in degree measure, but when i push the button 'Run', i can't get the values. i cant figure why. Hier is the code:
function s= sinus(x)
s=0;
for n=0:1:Inf
a=2*n+1;
b=((-1)^n)*((x^a)/(factorial(a)));
s=s+b;
end
end
Thanks for your help!

댓글 수: 2

Azzi Abdelmalek
Azzi Abdelmalek 2016년 4월 18일
You have an infinite loop for n=0:1:Inf
Roger Stafford
Roger Stafford 2016년 4월 18일
The infinite series you are using requires that x be in radians, not degrees. The easiest thing to do is to first convert x to radians by multiplying by pi/180.

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

답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2016년 4월 18일

1 개 추천

This a function, you can't run it like you run a script. You need to save it as sinus.m then from the windows command type
x=15
y=sinus(x)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

질문:

2016년 4월 18일

편집:

2016년 4월 19일

Community Treasure Hunt

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

Start Hunting!

Translated by