The following algorithm for computing ? is due to Archimedes:
1. Start with ? = 1 and ? = 6.
2. Replace ? by 2?.
3. Replace ? by sqrt(2 − sqrt(4 − ?))
4. Let ? = ??/2.
5. Let ? = na/2
6. Let ? = (? + ?)/2 (estimate of ?)
7. Let ? = (? − ?)/2 (estimate of error)
8. Repeat steps 2 – 7 until ? becomes smaller than a given tolerance ???.
9. Output ? and ?
Write a function that implements this algorithm. Use your function to determine ? and ? for ??? = 10^(=k)
, ? = 2, 3, … , 10.
I have written a code but i do not know how to write it so that if the value of e is larger than tol then steps 2-7 repeated. I have written this :
```
function [p,e] = algorithmPi(tol)
a = 1;
n = 6;
e = inf;
n = 2*n;
a = sqrt(2-sqrt(4-(a^2)));
l = (n*a)/2;
u = l/(sqrt((1-(a)^2)/2));
p = (u+l)/2;
e = (u-l)/2;
if e < tol
done = true;
disp('Complete: Error below tolerance')
end
end
9 Comments
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/506975-algorithm-for-computing-is-due-to-archimedes-how-steps-can-be-repeated#comment_800925
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/506975-algorithm-for-computing-is-due-to-archimedes-how-steps-can-be-repeated#comment_800925
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/506975-algorithm-for-computing-is-due-to-archimedes-how-steps-can-be-repeated#comment_800929
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/506975-algorithm-for-computing-is-due-to-archimedes-how-steps-can-be-repeated#comment_800929
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/506975-algorithm-for-computing-is-due-to-archimedes-how-steps-can-be-repeated#comment_801064
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/506975-algorithm-for-computing-is-due-to-archimedes-how-steps-can-be-repeated#comment_801064
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/506975-algorithm-for-computing-is-due-to-archimedes-how-steps-can-be-repeated#comment_801073
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/506975-algorithm-for-computing-is-due-to-archimedes-how-steps-can-be-repeated#comment_801073
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/506975-algorithm-for-computing-is-due-to-archimedes-how-steps-can-be-repeated#comment_801076
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/506975-algorithm-for-computing-is-due-to-archimedes-how-steps-can-be-repeated#comment_801076
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/506975-algorithm-for-computing-is-due-to-archimedes-how-steps-can-be-repeated#comment_801097
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/506975-algorithm-for-computing-is-due-to-archimedes-how-steps-can-be-repeated#comment_801097
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/506975-algorithm-for-computing-is-due-to-archimedes-how-steps-can-be-repeated#comment_801103
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/506975-algorithm-for-computing-is-due-to-archimedes-how-steps-can-be-repeated#comment_801103
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/506975-algorithm-for-computing-is-due-to-archimedes-how-steps-can-be-repeated#comment_801105
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/506975-algorithm-for-computing-is-due-to-archimedes-how-steps-can-be-repeated#comment_801105
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/506975-algorithm-for-computing-is-due-to-archimedes-how-steps-can-be-repeated#comment_801107
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/506975-algorithm-for-computing-is-due-to-archimedes-how-steps-can-be-repeated#comment_801107
Sign in to comment.