help me --> Taylor series cos(x)
Show older comments
cos(x) The value of can be represented by the following series.
--> cos(x) = 1 - 1-x^2/2!+x^4/4!-x^6/6! + . . . .
1. Write a mycos function that uses the above series to obtain the value of cos(x).
2. For the difference between the value of cos(2) and mycos(2) provided in Matlab to be 0.001 or less,
Write a code to determine the minimum number of terms of the critical series.
3. Configure the maximum number of iterations to be less than 10.
I'd like to know the matlab code for this problem. Please help me.
My English may be poor and my grammar may be wrong.
function cos(x) = mycos(x,n)
12 Comments
James Tursa
on 12 May 2021
Edited: James Tursa
on 12 May 2021
HInt: Given a value of x, write a loop to sum up those terms. Since this is an alternating series with monotonically decreasing magnitude terms for x=2, you can quit adding terms when the next term is less than the desired tolerance. Do you know how to write a loop and limit the number of iterations to less than 10?
Jan
on 12 May 2021
Please post what you have tried so far.
justlikethat
on 14 May 2021
Edited: justlikethat
on 14 May 2021
justlikethat
on 14 May 2021
David Hill
on 14 May 2021
for k=1:9
%your code
end
justlikethat
on 14 May 2021
David Hill
on 14 May 2021
Sounds like you should go through the MATLAB onramp.
justlikethat
on 14 May 2021
승현 표
on 30 Mar 2022
저 혹시... 어떤 책을 쓰셨는지 알 수 있을까요
Ayoub
on 7 Dec 2022
Help me please
Ayoub
on 7 Dec 2022
Cos(x)=sum (-1)^(k*2^2k)/(2k!) Sum[k n] K=0
Accepted Answer
More Answers (1)
Mahaveer Singh
on 19 May 2021
Edited: Mahaveer Singh
on 19 May 2021
0 votes
% n is required length of series.Give initial value of n as your imagination to speed up of %calculation.
function y = mycos(x,n)
y = 0;
for i= 0:2:2*n
y = y + ((-1)^(i/2)) *(x^(i)) / factiorial(i);
end
end
while y-cos(x)>0.001
n=n+1;
y=mycos(x,n);
end
Categories
Find more on Interpolation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!