hi I want to solve this problem using posted script.

1 次查看(过去 30 天)
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-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