I have to approximate cos(x) using taylor series expansion with a while loop to run until .00001 accuracy. the taylor series expansion for cos(x) is sum from n=0 –> inf (((-1)^n)*x^(2n))/((2n)!) I have included the code that I've been attempting but I keep having errors with the while loop
x=input('Enter the value of the angle in radians: ');error=1;count=0;while error>=1*(10^-4) count=count+1; terms(count)=(-1)^(count)*(x^(2*count))/(factorial(count)); Cosx=sum(terms); error=abs((cos(x)-Cosx)/cos(x));endfprintf('cos(%d)=%6.6f \n',x,sn);
Best Answer