hi I want to solve this problem using posted script.
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Matthew Worker
el 2 de Sept. de 2021
Comentada: Walter Roberson
el 3 de Sept. de 2021
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 comentarios
N/A
el 3 de Sept. de 2021
Editada: N/A
el 3 de Sept. de 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.
Respuesta aceptada
Walter Roberson
el 2 de Sept. de 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 comentarios
Walter Roberson
el 2 de Sept. de 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
Más respuestas (0)
Ver también
Categorías
Más información sobre Function Creation en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!