- #1
shayaan_musta
- 209
- 2
Here is my program for finding sin(x) at given x value.
x=input('x=\n')
tol=input('Tolerence=\n')
n=1
t(n)=1
s(n)=1
while(1)
n=n+1
t(n)=- ((x.^2)*(t(n-1))) / ((2*(n)-1)*(2*(n)-2))
s(n)=s(n-1)+t(n)
if(abs(t(n))>tol)
break;
end
end
fprintf('sinx for x=%d is %f',x,s(n))
%END
And here is a output
x=
5
Tolerence=
0.01
n =
1
t =
1.0000 -4.1667
s =
1.0000 -3.1667
n =
2
t =
1.0000 -4.1667
s =
1.0000 -3.1667
sinx for x=5 is -3.166667
But according to calculator sin(5)=0.08715
And I am confident that my recursion formula is correct.
Please help me.
Thanks
x=input('x=\n')
tol=input('Tolerence=\n')
n=1
t(n)=1
s(n)=1
while(1)
n=n+1
t(n)=- ((x.^2)*(t(n-1))) / ((2*(n)-1)*(2*(n)-2))
s(n)=s(n-1)+t(n)
if(abs(t(n))>tol)
break;
end
end
fprintf('sinx for x=%d is %f',x,s(n))
%END
And here is a output
x=
5
Tolerence=
0.01
n =
1
t =
1.0000 -4.1667
s =
1.0000 -3.1667
n =
2
t =
1.0000 -4.1667
s =
1.0000 -3.1667
sinx for x=5 is -3.166667
But according to calculator sin(5)=0.08715
And I am confident that my recursion formula is correct.
Please help me.
Thanks