Taylor series with sin(x).... I need help setting up my while loop and error bound
2 views (last 30 days)
Show older comments
This is what I have so far....it is not giving me anything, and I know there are things wrong with it, but I am not sure what: ---------------------
---------------------- Thank you!
0 Comments
Answers (2)
Roger Stafford
on 8 Apr 2013
Edited: Roger Stafford
on 8 Apr 2013
I see three mistakes here.
1. You reference sin_approx(count-1) but you aren't storing sin_approx in an array so there is no such entity. You need to either create an array or else create a temporary "previous" value.
2. You ask for the angle in degrees but your series expansion is only good for radian measure.
3. The inequality in the while loop is in the wrong direction. You need
while abs(E)>=0.000001
5 Comments
Roger Stafford
on 8 Apr 2013
Edited: Roger Stafford
on 8 Apr 2013
Yes, you do need to convert to radians because that is what the Taylor series assumes. It would be invalid for angles in degrees. The Taylor series for 'sind' is altogether different.
sanjeeb
on 30 Dec 2019
I writen above mention like below
clc
x=input('Enter the value of x in degree: ');
xr=x*pi/180;
n=0;
s=0;
while err>=0.000001
a=(-1)^n*(xr)^(2*n+1)/factorial(2*n+1);
s=s+a;
err=abs(a/s);
n=n+1;
end
fprintf('The value of taylor series sinx %f for specific value of x %f',s,x)
fprintf('The value of MATLAB function sindx %f for specific value of x %f',sind(x))
but it shown error as per below
Undefined function or variable 'err'.
Error in Practice2 (line 7)
while err>=0.000001
Please correct it
0 Comments
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!