need matlab code and which is in working condition and give
need matlab code and which is in working condition and give right output..
this is very basic
Solution
function [ actual_val,approx,n ] = approx_cos( x,error)
 actual_val=cos(x); %Actual value of cos(x)
 approx=0;   %Initial approximation is zero
 i=0;        %Counter for summation
 while(abs(actual_val-approx)>error) %Check if error is within range
     approx=approx+(-1)^i*x^(2*i)/factorial(2*i);    %If not, add new term
     i=i+1; %Add to counter
 end
n=i-1; %Output n as the number of iterations required
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~END OF PROGRAM~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sample usage:
 [a,b,c]=approx_cos(pi/3,0.0001)
a will output the actual value of cos(x)
 b will output the approximated value
 c will give the number of iterations required
![need matlab code and which is in working condition and give right output.. this is very basicSolutionfunction [ actual_val,approx,n ] = approx_cos( x,error) act need matlab code and which is in working condition and give right output.. this is very basicSolutionfunction [ actual_val,approx,n ] = approx_cos( x,error) act](/WebImages/5/need-matlab-code-and-which-is-in-working-condition-and-give-984771-1761505831-0.webp)
