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

a search 03 Feb 18%2C 20,6Programing Assig mert ttpswww.dropbox.comshiprzwdopto

ID: 1718611 • Letter: A

Question

a search 03 Feb 18%2C 20,6Programing Assig mert ttpswww.dropbox.comshiprzwdopto A4C6br9 PeyDWit-Dba-q07a/03 Session 03 Feb 1820 ing Assignment ,02.pdf Problem. The number can be calculated from the following infinite series: Infinite Series Equation Viete's Series 2 2 2 224466 -=-X-X-X-X-X-X-X-X Wallis's Series 2 1 3 3 5 5 7 7 9 Leibniz's Series 1 3 5 79 11 13 4 4 4 4 Nilakantha's Series | =34 2×3x4 4x5x6 6×7x8 8x9x10 Write a MATLAB program to calculate number with 8 significant figures (considering 10000 as the maximum iterations) using the above sequences. The selection of infinite series (Viete's, Wallis's, Leibniz's, Nilakantha's Series) should be asked from user by the input command. Print the approximate number, approximate relative error, true relative error, number of iterations, and total elapsed time for the selected method in Command Windows. PI Number Approximation Program Viete's Series [1]: (2]: Wallis's Series [31: Leibniz's series … Sample Output --“ 141: Nilakantha's Series Select the infinite series 1 Results: viete's Infinite Series 0

Explanation / Answer

Matlab Code

series = input('Type of Series: ','s');
if(strcmp(series,'viete'))
    m = 1/2;
    Pi = 1;
    for i = 1:10000
        k = sqrt(m);
        for j=1:i-1
            k = sqrt(k * m + m);
        end
        Pi = Pi * k;
    end
    Pi = 2/Pi
elseif(strcmp(series,'wallis'))
    Pi = 2;
    for i = 1:10000
        if (mod(i,2)==0)
            U = i;
            D = i+1;
        else
            U = i+1;
            D = i;
        end;
        Pi = Pi * (U/D)
    end
elseif(strcmp(series,'leibniz'))
    p=0;
    for i = 0:10000
        p = p + (4*((-1)^i))/(2*i + 1);
        if rem(i,2) == 0
            p1 = p;
        else
            p2 = p;
        end
    end
    fprintf(' %s Iterations: Pi is approximately equal to %f... ',num2str(i),(p1+p2)/2)
end

Sample Output

Type of Series: leibniz

10000 Iterations: Pi is approximately equal to 3.141593...