hi I want to solve this problem using posted script.

1 view (last 30 days)
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 Comments
N/A
N/A on 3 Sep 2021
Edited: N/A on 3 Sep 2021
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 on 3 Sep 2021
I discussed the script as the very first thing in my Answer.

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 2 Sep 2021
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 Comments
Walter Roberson
Walter Roberson on 2 Sep 2021
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 on 2 Sep 2021
Thank you so much for your kind help. I really appreciate it.

Sign in to comment.

More Answers (0)

Categories

Find more on Function Creation 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!