function [SN] = sintaylorfunction(A, tol)k = 0; error = 0 ;sin = 0;SN = sin; sinplus1 = 0;SM = sinplus1; while E <= tol sin = (-1)^k * A^(2*k+1)/factorial(2*k+1); SN = SN + sin; sinplus1 = (-1)^(k+1) * A^(2*(k+1)+1)/factorial(2*(k+1)+1); SM = SM + sinplus1; error= abs( max(SM - SN)); endend
I wrote the sin function in this way. When I calculate sin(pi/2), I get sin(pi/2) = 1.5708. However, we know that sin(pi/2) = 1. Where is my mistake in my function?
Best Answer