## Squared difference of each element in a vector

For questions regarding programming in the EViews programming language.

Moderators: EViews Gareth, EViews Jason, EViews Moderator, EViews Matt

elmst616
Posts: 32
Joined: Fri Apr 29, 2016 2:36 pm

### Squared difference of each element in a vector

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 (20.89 KiB) Viewed 1520 times

EViews Matt
EViews Developer
Posts: 410
Joined: Thu Apr 25, 2013 7:48 pm

### Re: Squared difference of each element in a vector

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))`

elmst616
Posts: 32
Joined: Fri Apr 29, 2016 2:36 pm

Thank you Matt!