Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

B. (7 points) The mathematician Euler proved the following: pi squared-6 (1 1/4

ID: 3801415 • Letter: B

Question

B. (7 points) The mathematician Euler proved the following: pi squared-6 (1 1/4 1/9 1/16 1/25 a. Write a matlab function called "EulerPI" that takes a single argument, the number of terms in the above summation, and calculates and returns the value of PI. Design will be done in lecture or lab. b. Will your function work if you call it with the n argument as a vector? Why or why not? c. How could you determine how many terms are sufficient to calculate PI this way as accurately as possible on your computer?

Explanation / Answer

function [c] = EulerPi(n)
p=0;
for i=1:n
p=p+1/(i^2);
end
c=sqrt(6*p);
end

outputtttttttttttttttttttt % command =EulerPi(10000)

command =

3.1415

b)no my function wont work if the n is vector because it already has n elements to get the sum we had to add all the numbers of the format 1/n^2 in the vector

but my function takes only n and by using loop we achive 1/n^2 format

c)upto four decimal to get 3.146

by giving the arbitary inputs and compare the result

for n=100:1:1000000
PI=Eulerpi(n)
end