Not sure how to continue/finish this problem

function [n, precision, y] = MyCos(tolerance, N, x)
SUM = 0;
for n = 0:N
SUM = SUM + (-1)^n*(x^2*n)/factorial(2*n);
end
I don't think I need the SUM. I think I should replace it with cos(x), but not sure. Not sure where it would go after that. Please include an explanation if possible.
Thank you

Antworten (1)

Walter Roberson
Walter Roberson am 19 Okt. 2022

0 Stimmen

No, you do need the sum.
The task is
initialize variables
start a for loop
generate the next term
if the absolute value of the term is less than the tolerance then break
otherwise add the term to sum
after the for loop, also call cos() and report how close the estimate was to the actual value

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange

Tags

Gefragt:

am 19 Okt. 2022

Kommentiert:

am 19 Okt. 2022

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by