hi I want to solve this problem using posted script.

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 commentaires

Rik
Rik le 3 Sep 2021
I recovered the removed content from the Google cache (something which anyone can do). Editing away your question is very rude. Someone spent time reading your question, understanding your issue, figuring out the solution, and writing an answer. Now you repay that kindness by ensuring that the next person with a similar question can't benefit from this answer.
N/A
N/A le 3 Sep 2021
The reason I deleted that was because it’s the wrong script I posted there. First person who answered my question told me that and I removed it only to avoid misunderstandings for whoever going to read this question and answers later. Just the question I left and answer thread would give a full understanding for future students like me when they read it. But it will be really confusing to see a totally unrelated script middle of them. I am going to delete it again. It’s I’m trying to make my question and time of that person’s who helped me to write the correct script more useful. Not rude.
N/A
N/A le 3 Sep 2021
Also second question that you pasted there again has nothing to do with matlab. That was my mistake as well. You probably did not see when I edit I also edited misspelled symbols like “pi”. Sometimes you can repay kindness by ensuring that other people do get the right thing and right thing only.
However, the Answer that I posted does not make any sense without that first posted script. The comments I posted later do not make sense without the image of the summation equation.
I spent my time answering the question you actually asked, so that question should remain posted.
N/A
N/A le 3 Sep 2021
Modifié(e) : N/A le 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.
I discussed the script as the very first thing in my Answer.

Connectez-vous pour commenter.

 Réponse acceptée

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 commentaires

N/A
N/A le 2 Sep 2021
Could you please explain me how to solve this using MATLAB then? If it’s not this script?
Determine the number of terms of what ? There is nothing there which has terms. There used to be, but my memory is not what it once was.
N/A
N/A le 2 Sep 2021
the number of terms that must be summed to ensure an approximation to “pi” to within 1e-3.
Start with a small function. The function should be passed x and i, and it should return just the i'th term of the expansion of arctan(x)
Now you can:
start with running total 0
loop over i values
ask the function for the i'th term of arctan(1/5)
ask the function for the i'th term of arctan(1/239)
multiply the first of those by 4 and add the second of them
add the result to the running total
check to see if the running total is now within the required tolerance.
If it is, then leave the loop
otherwise let yourself go back to the next i
N/A
N/A le 2 Sep 2021
Thank you I will try to follow your instructions. Hope it will workout well!
Can you tell me if this is correct? and can you tell me how to write missing two lines.
tol=1e-3;
arctan = @(x,n) (-1).^(n+1).*((x.^(2*n-1))./(2*n-1));
a1 = 0;
a2 = 0;
for n = 1:10
a1 = a1 + arctan(1/5,n);
a2 = a2 + arctan(1/239,n);
pi = 4*((4*a1) - a2)
if abs( -pi)<tol %%%%%%% % what should i give here?
fprintf('converges to %15.10f in %3d iterations\n',y,i)
break
else
........; %%%%%%% % what should i give here?
end
end
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 le 2 Sep 2021
Thank you so much for your kind help. I really appreciate it.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur MATLAB dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by