Page 1 of 1

Squared difference of each element in a vector

Posted: Wed Mar 08, 2017 9:52 am
by elmst616
Hi I'm sorry this is such a basic question, but I cannot find the answer in Eviews help forum.

I have a 1x10 vector of eigenvalues and I have a scalar mean of those eigenvalues. For each element of the vector, I'd like to subtract the mean, square the difference and sum the squared differences.

In Matlab the syntax would be:

sum((eigen-mean_eigen).^2)

I thought the EViews syntax would be simple and I've been trying this:

Code: Select all

vector C1F3 = @sum((eig_d4 - mean_eig_d4)^2)
But, I'm getting an error message that states "Vector raised to scalar." Which is odd. The result should indeed be a scalar, but I don't understand the problem here.
eviews_error.png
eviews_error.png (20.89 KiB) Viewed 5402 times

Re: Squared difference of each element in a vector

Posted: Wed Mar 08, 2017 11:30 am
by EViews Matt
Hello,

The ^ operator doesn't perform element by element exponentiation, but the @epow function does.

Code: Select all

scalar C1F3 = @sum(@epow(eig_d4 - mean_eig_d4, 2))

Re: Squared difference of each element in a vector

Posted: Wed Mar 08, 2017 2:38 pm
by elmst616
Thank you Matt!