Not sure how to continue/finish this problem
Ältere Kommentare anzeigen
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
1 Kommentar
Rena Berman
am 19 Okt. 2022
(Answers Dev) Restored edit
Antworten (1)
Walter Roberson
am 19 Okt. 2022
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
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!