首页 > 解决方案 > sum elements of vector excluding the first element in Octave

问题描述

I want to sum the square of all elements in a vector except the first element of such vector in Octave.

I´ve tried:

sum(x(2)^2)

And

sum(x(2:end)^2)

标签: octave

解决方案


你很接近,你需要使用一个元素运算符,即.^

sum( x(2:end) .^ 2 )

您使用的 ( ^) 是“矩阵幂”运算符。

在您的控制台中键入help power和以获取详细信息。help mpower


推荐阅读