ํ•„ํ„ฐ ์ง€์šฐ๊ธฐ
ํ•„ํ„ฐ ์ง€์šฐ๊ธฐ

Write a matlab function for approximating the value of pi (certain equation)

์กฐํšŒ ์ˆ˜: 1 (์ตœ๊ทผ 30์ผ)
Jin
Jin 2023๋…„ 4์›” 12์ผ
ํŽธ์ง‘: Torsten 2023๋…„ 4์›” 12์ผ
Hi.
Task:
Write a program that calculates the approximation of pi when it is given an upper limit of the sum ๐‘.
Code that I'm trying to use:
function p = fun_my(n)
p = 0;
for k = 1:n
p = p + sqrt(8 + sum(16./((2*(1:n) - 1).^2 .* (2*(1:n) + 1).^2)));
end
Thanks for advance!

์ฑ„ํƒ๋œ ๋‹ต๋ณ€

Torsten
Torsten 2023๋…„ 4์›” 12์ผ
ํŽธ์ง‘: Torsten 2023๋…„ 4์›” 12์ผ
You sum twice.
And
(2*n-1)^2*(2*n+1)^2 = (4*n^2-1)^2
Either use
n = 20;
p = 0;
for k = 1:n
p = p + 1/(4*k^2-1)^2;
end
p = sqrt(8 + 16*p)
p = 3.1416
or use
n = 20;
p = sum(1./(4*(1:n).^2-1).^2);
p = sqrt(8+16*p)
p = 3.1416

์ถ”๊ฐ€ ๋‹ต๋ณ€ (0๊ฐœ)

์นดํ…Œ๊ณ ๋ฆฌ

Help Center ๋ฐ File Exchange์—์„œ Logical์— ๋Œ€ํ•ด ์ž์„ธํžˆ ์•Œ์•„๋ณด๊ธฐ

Community Treasure Hunt

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

Start Hunting!

Translated by