In [ ]:
a = 1;
In [ ]:
b = 2;
In [ ]:
c = 3
Sum of squares: Return the sum of squares of elements for a given input vector $a$.
\begin{align} a &= \begin{bmatrix} a_1 & a_2 & \cdots & a_n \end{bmatrix} \\ x &= \sum_{i=1}^n a_i^2 \end{align}Also, plot the cumulative sum.
One possible implementation:
sumsq = 0;
for i = 1:length(a)
sumsq = [sumsq sumsq(end)+a(i)^2];
end
Let's try it:
In [ ]:
a = [1 2 3 3 2 1];
sumsq = 0;
for i = 1:length(a)
sumsq = [sumsq sumsq(end)+a(i)^2];
end
plot(sumsq)
xlabel('No. of elements accumulated')
ylabel('Sum of squares of elements')