Taylor series with sin(x).... I need help setting up my while loop and error bound
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (2)
Roger Stafford
el 8 de Abr. de 2013
Editada: Roger Stafford
el 8 de Abr. de 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 comentarios
Roger Stafford
el 8 de Abr. de 2013
Editada: Roger Stafford
el 8 de Abr. de 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
el 30 de Dic. de 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 comentarios
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!