what did i do wrong here

1 visualización (últimos 30 días)
Mutaz Alsomali
Mutaz Alsomali el 27 de Feb. de 2018
Respondida: KSSV el 27 de Feb. de 2018
if true
clear, clc
x1=unput('Enter the angel in dgree');
x=x1*pi/180;
tol=10^(-7);
f=(0);
for n=0:100
f=f+(-1)^(n)*x^(2*n)/factorial(2*n);
s(n+1)=f;
if(n>1)
err=abs((s(n+1)-s(n))/s(n));
if err<tol
break;
end
end
end
f1=cos(x);
fprintf('cos(%d)=%f\n',x1s(end));
fprintf('Actual Value of cos(%d)=%1.8f\n'x1,f1);
end

Respuestas (1)

KSSV
KSSV el 27 de Feb. de 2018
x1=input('Enter the angel in dgree');
x=x1*pi/180;
tol=10^(-7);
f=(0);
for n=0:100
f=f+(-1)^(n)*x^(2*n)/factorial(2*n);
s(n+1)=f;
if(n>1)
err=abs((s(n+1)-s(n))/s(n));
if err<tol
break;
end
end
end
f1=cos(x);
fprintf('cos(%d)=%f\n',s(end));
fprintf('Actual Value of cos(%d)=%1.8f\n',x1,f1);

Categorías

Más información sobre Numeric Types en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by