function s = nTermSine4(x) % nTermSine4 Evaluate series approximation to sin(x). Use recursive % evaluation of terms, while loop and convergence che % % Synopsis: s = nTermSine4(x) % % Input: x = argument of sine(x) % % Output: s = approximation to sin(x) with a max of n terms. Stop when % abs(term/sum) < tol, where tol = 5e-6 term = x; s = term; % initialize the sum and the sign of the term tol = 5e-6; fprintf('\n i term s\n'); fprintf(' %4d %18.13f %8.5f\n',1,term,s); i = 1; while abs(term/s)>tol i = i + 2; term = -term*(x^2)/(i*(i-1)); s = s + term; fprintf(' %4d %18.13f %8.5f\n',i,term,s) end