Hello, I am trying to find the error in my code...I am trying to write the macla
ID: 3528449 • Letter: H
Question
Hello, I am trying to find the error in my code...I am trying to write the maclaurin series with max interactions of 100 and relative error of .000001. The problem with my code is that it does not change with error?? Please Help!!!!!!!!!!!! x=pi/3; error=.000001; N=100; sum=0; for k=0:1:100 k1=((-1)^k)*(x^(2*k)/(factorial(2*k))); sum =sum+k1; if (((abs(sum-k)/(sum))*100 <=R_error)) break end end fprintf('It took %d terms before the error was within %f of cos(x)',k,error); disp('This is the estimated answer') sumExplanation / Answer
x=pi/3;
error=.000001;
N=100;
sum=0;
for k=0:1:100
k1=((-1)^k)*(x^(2*k)/(factorial(2*k)));
sum =sum+k1;
if (((abs(sum-k)/(sum))*100 <=R_error))
break ;
end
end
fprintf('It took %d terms before the error was within %f of cos(x)',k,error);
disp('This is the estimated answer') ;
sum ;
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.