Not sure how to continue/finish this problem
Show older comments
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 Comment
Rena Berman
on 19 Oct 2022
(Answers Dev) Restored edit
Answers (1)
Walter Roberson
on 19 Oct 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
Categories
Find more on Loops and Conditional Statements 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!