This program evaluates cosine function using "Taylor Series Expansion".
x=input('x= '); %Number that we will calculate its cosineN=input('N= '); %Number of iteraritonscosx=1; %Initial value cos(0)truecos=cos(x) %True value of cos(x) calculated by Matlab commandfor k=2:Nfact=1; %Initial value to calculate factorialfor i=1:(2*(k-1)) %for loop to calculate required factorialfact=fact*i;endcosx=cosx+(-1)^(k+1)*x^(2*(k-1))/fact %calculation of cos(x)error=(truecos-cosx)/truecos*100 %calculation of relative errorend