octave - 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)
解决方案
你很接近,你需要使用一个元素运算符,即.^
sum( x(2:end) .^ 2 )
您使用的 ( ^
) 是“矩阵幂”运算符。
在您的控制台中键入help power
和以获取详细信息。help mpower
推荐阅读
- jquery - 引导可折叠面板在 ng-if 内不起作用
- for-loop - 批处理文件:如何在 for 循环中保存文件夹名称
- jsf - 日程表在 Calender Primeface JSF 上显示错误的结束日期
- flutter - Flutter:NestedScrollView Header TabBar 阻碍/重叠 TabBarView 元素
- python - 如何在后台模式下在android上的python kivy中启动服务?
- amazon-web-services - AWS SNS 版本不同区域
- java - AWS Java SDK 2.0 仅获取 s3 对象元
- java - Android Retrofit2 泛型方法
- python - 在 python 中删除一个 DataFrame 列
- typescript - 使用多个管道时 RXJS 类型推断如何工作