Exercise 4 The nunber can be defined as a limit of various converging series of
ID: 2252145 • Letter: E
Question
Exercise 4 The nunber can be defined as a limit of various converging series of num!bers. Among them Simon Plouffe (1995), (4) 0016k8k1 8k +4 8k +5 8k +6 k-0 2 Euler (1735). k-1 Write a Matlab/Octave function pi.series.m retuns the first 10 partial sums of the scrics (4)-(5), i.c., the vectors P and E with components 710.) 16k8k+1 8k +4 8k +5 8k 6 k-0 The function should be of the following form function [P,E,n1,n2]-pi series() Output P, E: row vectors with 10 components defined by the first 10 partial sums in (6) and (7) nl, n2: see the Extra Credit exercise hercafter. If you do not want to code the extra credit part, just set n1-0 and n2-0 in the function pi series.m. Extra Credit: At the end of the Matlab function pi series.m, write a code that returns the smallest integer numbers n1 and n2 such that To determine ni and n2, you can use a for loop combined with an if statement or, cquivalently, a while loop.Explanation / Answer
pi_series.m
function [P,E,n1,n2] = pi_series()
P = zeros(1,10);
E = zeros(1,10);
n1 = 0; n2 = 0;
% P
for n=0:1:9
for k=0:n
P(n+1) = P(n+1)+((4/(8*k+1))-(2/(8*k+4))-(1/8*k+5)-(1/8*k+6))/(16^k);
end
if abs(P(n+1)-pi) < 1e-5
if n1==0
n1 = n;
end
end
end
% E
for n=1:1:10
for k=1:n
E(n) = E(n)+(1/(k*k));
end
E(n) = sqrt(6*E(n));
if abs(E(n)-pi) < 1e-5
if n2==0
n2 = n;
end
end
end
end
code for testing above function
[P,E,n1,n2] = pi_series()
output
P =
-7.5000 -8.1858 -8.2302 -8.2330 -8.2332 -8.2332 -8.2332 -8.2332 -8.2332 -8.2332
E =
2.4495 2.7386 2.8577 2.9226 2.9634 2.9914 3.0118 3.0273 3.0395 3.0494
n1 =
0
n2 =
0
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.