% Program to compute the cosine of input values for % a, b and c. These will be stored in ca, cb and cc fvec = [2,24,720,40320,3628800,479001600,87178291200,... 20922789888000,6402373705728000,... 2432902008176640000]; % Get input for a a = input('Input a: '); % The indented block is for readability. The block below computes % the cosine of a. x = a; x = mod(abs(x),2*pi); neg = 1; if(x > pi/2 && x <= pi) x = pi - x; neg = -1; elseif(x > pi && x <= 3*pi/2) x = x - pi; neg = -1; elseif(x > 3*pi/2 && x <= 2*pi) x = 2*pi - x; end xsq = x*x; y = 1; num = 1; for i = 1:10 num = -num*xsq; nexterm = num/fvec(i); y = y + nexterm; end y = neg*y; % Store computed cosine (y) into ca ca = y; ra = abs(ca-cos(a))/cos(a) % Repeat process for b b = input('Input b: '); x = b; x = mod(abs(x),2*pi); neg = 1; if(x > pi/2 && x <= pi) x = pi - x; neg = -1; elseif(x > pi && x <= 3*pi/2) x = x - pi; neg = -1; elseif(x > 3*pi/2 && x <= 2*pi) x = 2*pi - x; end xsq = x*x; y = 1; num = 1; for i = 1:10 num = -num*xsq; nexterm = num/fvec(i); y = y + nexterm; end y = neg*y; cb = y; rb = abs(cb-cos(b))/cos(b) c = input('Input c: '); x = c; x = mod(abs(x),2*pi); neg = 1; if(x > pi/2 && x <= pi) x = pi - x; neg = -1; elseif(x > pi && x <= 3*pi/2) x = x - pi; neg = -1; elseif(x > 3*pi/2 && x <= 2*pi) x = 2*pi - x; end xsq = x*x; y = 1; num = 1; for i = 1:10 num = -num*xsq; nexterm = num/fvec(i); y = y + nexterm; end y = neg*y; cc = y; rc = abs(cc-cos(c))/cos(c)