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

1.) The value of can be estimated using an infinite sum and the “Leibniz Formula

ID: 3783966 • Letter: 1

Question

1.) The value of can be estimated using an infinite sum and the “Leibniz Formula for Pi,” which states:

Therefore, your calculated value of will get closer to “true” the more terms you include in the sum. From scratch, or using the template provided (leibniz_template.m) write a MATLAB code that converges to within a prescribed value of pi.

2.) Estimate how many iterations it takes to achieve various levels of convergence precision by reproducing and completing the table above.

3.) Plot the absolute error between your calculated value of and “true” vs. the number of terms included in the sum. Comment on the results.

4.) Edit/amend your code to store the “new term” for each value of n. Plot the “new term” vs. n in a separate plot. Comment on results.

5.) Edit/amend your code to store the code’s estimate of at each step. Plot the current value of vs. n on a separate plot. Comment on results.

***I have the correct code for the values for error and estimation. I do not understand how to plot the information that I need in questions 3-5.

Here is my code:

%%Initialize environment

close all; clear; clc

format long g

%start timer

tic

%set the starting values for n, error and "code" value of pi.

n=0; %number of terms in the sum

error=1000; %the starting value of the error, why is it big?

code_pi=0; %the value the code currently returns for pi

new=0; %the new value of the sum

while abs(error) > .00001

%compute the "new" term in the sum

new = (4*((-1)^n))/(2*n+1);

%compute the new sum

code_pi = new + code_pi;

%compute the error

error = code_pi - pi;

a(1,n)=error;

%increase n by 1

n=n+1;

end

%stop timer

toc

(-1)" 2n + 1 such that: _4 -4 t 1-9 T 1-7 (2 15 0 1+3 13 1

Explanation / Answer

3) In this part you are required to plot a graph between error that you are calculating for each value of n and the n itself.

So within the loop you can directly add plot function for the after calculating "error" and plot graph with x and y as error and n

4) here you need to plot between n and the new term you are calculating