hi I want to solve this problem using posted script.

조회 수: 1 (최근 30일)
Matthew Worker
Matthew Worker 2021년 9월 2일
댓글: Walter Roberson 2021년 9월 3일
Problem: Another formula for computing "pi" can be deduced from the identity pi/4 = 4arctan1/5— arctan1/239. Determine the number of terms that must be summed to ensure an approximation to pi to within 1e-3.
Can some one tell me how to use a script to solve the problem.
  댓글 수: 6
N/A
N/A 2021년 9월 3일
편집: N/A 2021년 9월 3일
I understand I mistakenly deleted the equation too. I didn’t mean it. I just wanted make the question clear. But I re-edited that part and posted the equation. The only thing I wanted to delete was the Bisection script and the part that no one discussed nor has anything to do with matlab. I can leave the script if you think it’s important there. But before completely change something that I posted I think it would have been nice to comment and ask me to leave it as it was. Or ask me why I did that. Because being rude or hiding this question was not my intention at all. Thank you a lot for helping me out. I will leave the script if you think it’s not confusing there and i will only delete the non related second question. No one commented on that part anyway.
Walter Roberson
Walter Roberson 2021년 9월 3일
I discussed the script as the very first thing in my Answer.

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2021년 9월 2일
That script cannot be used to solve that problem. That script is for the case where a continuous variable x must be found such that f(x) is close to 0.
However, the current problem instead requires that you find the discrete variable n such that
4 * (approximating arctan 1/5 by n terms) - (approximating arctan 1/239 by n terms)
is within 1e-3 of pi/4
It is a completely different kind of problem.
  댓글 수: 8
Walter Roberson
Walter Roberson 2021년 9월 2일
format long g
tol=1e-3;
arctan = @(x,n) (-1).^(n+1).*((x.^(2*n-1))./(2*n-1));
a1 = 0;
a2 = 0;
for n = 1:20
a1 = a1 + arctan(1/5,n);
a2 = a2 + arctan(1/239,n);
approximate_pi = 4*((4*a1) - a2)
if abs(pi - approximate_pi)<tol
fprintf('converges to %15.10f in %3d iterations\n', approximate_pi, n)
break
end
end
approximate_pi =
3.18326359832636
approximate_pi =
3.14059702932606
converges to 3.1405970293 in 2 iterations
N/A
N/A 2021년 9월 2일
Thank you so much for your kind help. I really appreciate it.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Function Creation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by