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

Please use Matlab for the following questions. Please do all of them. Thanks so

ID: 2267202 • Letter: P

Question

Please use Matlab for the following questions. Please do all of them. Thanks so much in advance!

Please show the code as well as the output. Thanks!

6. Consider the series rt Sn ! whose limit is Soo- for n oo. a) Write a MATLAB script that evaluates the sum numerically. The script asks the user for the value of n and prints the values of Sn. Is,-l and l(65n)1/2- b) Use the script to calculate Sn for n = 10, 20, 100, 200, 500. c) How many terms of the series are necessary to obtain an approximation of with 2 significant digits? How many are required for 3 significant digits?

Explanation / Answer

Following is the MATLAB script for the asked program

Sn is the actual series summation

Out2 is the value of |Sn-²/6|

Out3 is the value of |(6Sn) - |

a)

n = input('Enter n: '); %Enter the Number of iterations

Sn = 0; %Initialisation to avoid garbage value

for i = 1:n

   Sn = Sn + (1/(i*i));    %calculation of the series

end

% disp Display array.

% disp(X) displays the array, without printing the array name. In

% all other ways it's the same as leaving the semicolon off an

% expression except that empty arrays don't display.

X=sprintf('Output of Sn is %d',Sn);

disp(X);

% abs    Absolute value. abs(X) is the absolute value of the elements of X.

out2 = Sn - (pi*pi)/6;

out2 = abs(out2);

X = sprintf('Output1 is %d',out2);

disp(X);

out3 = sqrt(6*Sn)-pi;

out3 = abs(out3);

X = sprintf('Output2 is %d',out3);

disp(X);


b)

using the script to find the value of series at following indices:

chegg1 is the script name

>> chegg1

Enter n: 10

Output of Sn is 1.549768e+00

Output1 is 9.516634e-02

Output2 is 9.223102e-02

>> chegg1

Enter n: 20

Output of Sn is 1.596163e+00

Output1 is 4.877082e-02

Output2 is 4.692313e-02

>> chegg1

Enter n: 100

Output of Sn is 1.634984e+00

Output1 is 9.950167e-03

Output2 is 9.516122e-03

>> chegg1

Enter n: 200

Output of Sn is 1.639947e+00

Output1 is 4.987521e-03

Output2 is 4.766347e-03

>> chegg1

Enter n: 500

Output of Sn is 1.642936e+00

Output1 is 1.998001e-03

Output2 is 1.908530e-03

C) Following is the script to calculate the number of iterations required to find the approximation of upto ‘n’ significant places. Here n is the input from the user.

%Enter upto how many significant places

n = input('Approximation upto how many signicant places of pi: ');

%round(X, N, 'significant') rounds each element to its N most significant

%digits, counting from the most-significant or left side of the number.

%N must be a positive integer scalar.

piNew = round(pi, n, 'significant');

Sn = 0;

for i = 1:1000

   Sn = Sn + (1/(i*i));

   comValue = abs(round(sqrt(6*Sn),n,'significant') - piNew);

   if comValue == 0

       disp(i);

       break;

   end

end

For Upto 2 significant places:

>>Approximation upto how many significant places of pi: 2

Answer: 11

For Upto 3 significant places:

>>Approximation upto how many significant places of pi: 3

Answer: 145

Comment in case of doubts. Please upvote.