Spring 20116 ME32200-4PR Programming Assignment 02 Course Name ME32200-4PR Due D
ID: 3673856 • Letter: S
Question
Spring 20116 ME32200-4PR Programming Assignment 02 Course Name ME32200-4PR Due Date: 03/3/2016 Instructor Samaneh Farokhirad Semester Spring 2016 Problem. The number can be calculated from the following infinite series: Infinite Series Equation Viete's Series 2 r22 4 4 6 6 8-8 2 1 3 3 5 5 7 7 9 Wallis's Series Leibniz's Series 1 3 5 79 11 13 4 4 Nilakantha's Series | 3 + 2x3x4 4x5x6 6x7x8 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 [1]: viete's Series 121: Wallis's Sories 131: Leibniz's Series -- Sample Output [41: Nilakantha's Series Select the infinite series:1 Results: Viete's Infinite Series >> PI number with sig. figures >> The approximate relative error : >> The true relative ezror >> Number of iterationS >> Total elapsed tino 3-14159265 4.5966-009 -532e-009 14 0.001062 s Eiter 0 to STOP.1 to RKPEAT 0Explanation / Answer
disp('Enter your choice 1. Viete's 2. Wallie')
str = input("Enter your choice",'s')
str2= input('Enter the N value till where you want the series')
if str==1
vieteSeries(str2)
else wallisSeries(str2)
function Pi = vieteSeries(N)
m = 1/2;
Pi = 1;
for i = 1:N
k = sqrt(m);
for j=1:i-1
k = sqrt(k * m + m);
end
Pi = Pi * k;
end
Pi = 2/Pi;
function Pi = wallisSeries(N)
Pi = 2;
for i = 1:N
if (mod(i,2)==0)
U = i;
D = i+1;
else
U = i+1;
D = i;
end;
Pi = Pi * (U/D);
end
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.