N=50;
x=pi; % Assumes x = pi for ease of verification
terms = [0:2:N];
facts = factorial(terms);
Power_Of_X = x.^terms;
signs = (-1).^(terms/2);
quotes = Power_Of_X ./facts;
series = signs .* quotes;
M_cos_N = cumsum(series);
plot (M_cos_N);
The problem then asks for the percent relative error or the algorithm. This can be done by updating the above code to include on the end:
%Percent Error
true = -1.0;
P_error = (true - M_cos_N)/true * 100;
figure(2);
plot(terms,(abs(P_error)));
This produces the graph:
Showing that the error inherent in the algorithm becomes largely negligible around 30 terms in
No comments:
Post a Comment