Element by Element Operation

1. Sum of a Series

This problem is about to finding the value of \(y\) given as:

\[ y = \frac{1}{1^2} + \frac{1}{2^2} + \frac{1}{3^2} + \cdots + \frac{1}{50^2}\]

This can be done in few lines of MATLAB codes, as below:

>> x=1:1:50;

>> y=1./x.^2;

>> sum(y)

ans

=1.6251
The above can also be done with a single line of code as below:
>> sum(1./[1:50].^2)

ans

=1.6251

Since MATLAB is capable of processing array variables, we can solve with one or few lines of code. Whereas with any other programming language we may have to make use of for loop.