The Taylor series expansion for cos(x) is cos(x) = 1 - x^2/2! + x^4/4! - x^6/6! + ... = sigma_n = 0^infinity (-1)^n/(2n)! x^2n where x is in radians Write a user-defined function y = lastname_cos_taylor(x, n, er) where the input angle x is in degrees, n number of terms and er is error. Use loop to add the terms of the Taylor series. Calculate the error E = |sn - sn - 1/sn - 1| and stop when E lessthanorequalto 0.0000001 or when user provided n is reached. Input and output must be in the main program script.
following is the matlab program
clc;
close all;
clear all;
theta=pi*60/180;
e=1;
n=1;
S(1)=1;
while abs(e)>=.000001
S(n+1)=S(n)+(-1)^(n).*theta^(2*(n))./factorial(2*(n));
e=(S(n+1)-S(n))/(S(n));
n=1+n;
end
disp(S);