Use MATLAB to show that the sum of the series Sigma 1/n^2 converges to pi^2/6. D
ID: 3836093 • Letter: U
Question
Use MATLAB to show that the sum of the series Sigma 1/n^2 converges to pi^2/6. Do it by computing the sum using vectorization with "sum" for: n = 100 = 1,000 n = 10,000 For each part a vector n in which the first element is 1, the increment is 1 and the is 100, 1,000 or 10,000. Then, use element-by-element calculation to create a vector in which the elements are 1/n^2. Finally, use the function "sum" to add the terms of the series. Show the and answer of above three cases. Calculate pi^2/6, Do you see when n increase, the answer approaching to pi^2/6? (Don't forgot to type at the end of that otherwise will display large vectors.)Explanation / Answer
Please refer below code
clear all
close all
clc
format long %to print answers upto multiple digits after decimal points
ref = (pi * pi)/6 ; %calculating reference value
fprintf(' Reference value is : %3.15f ', ref);
%for loop for different values of n
for i = 1:3
n = input('Enter n :');
vec1 = linspace(1,n); %creating evenly spaced vector
rec_vec1 = zeros(1,n); %creating vector for 1/n^2
rec_vec1 = 1./(vec1.^2);
S = sum(rec_vec1); %sum of all elements of vector
fprintf(' calculated value for n = %i is : %3.15f ', n,S);
end
Output of the program is
Reference value is : 1.644934066848226
Enter n :100
calculated value for n = 100 is : 1.634983900184892
Enter n :1000
calculated value for n = 1000 is : 1.013993789016772
Enter n :10000
calculated value for n = 10000 is : 1.000157964524544
As n increases the answer is NOT approaching to reference value.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.