Please show exactly how it is in MATLAB The cosine function can be evaluated by
ID: 3753531 • Letter: P
Question
Please show exactly how it is in MATLAB
The cosine function can be evaluated by the following infinite series: cos = 1 ^2/ 2! + ^4/ 4! ^6 /6! + Create an M-file to compute cos(1.2345 rad) for up to and including eight terms, which is up to the term x^14/14!.
a) Your program should compute and display the values of cos as each term in the series is added, e.g.
cos = 1
cos = 1 ^2/ 2!
cos = 1 ^2 /2! + ^4/ 4!
b) Compute and display the true relative error as a percentage = true valueseries approximation true value × 100%
Explanation / Answer
ANS:
CODE:
clc;
clear all;
close all;
n=input(' Enter the number of terms u want in expantion ');
% % let x= pi/6
x=pi/3;
sum=0;
for k=0:n
sum=sum+(-1)^k*x^(2*k)/factorial(2*k);
cosx=sum;
cosx
p_err=abs(cos(x)-cosx)/cosx*100
end
output:
Enter the number of terms u want in expantion 3
cosx =
1
p_err =
50.0000
cosx =
0.4517
p_err =
10.6957
cosx =
0.5018
p_err =
0.3580
cosx =
0.5000
p_err =
0.0071
IF YOU HAVE ANY DOUBTS COMMENT BELOW RATE THUMBSUP PLZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.