MATLAB 中向量数组的向量范数 [英] Vector norm of an array of vectors in MATLAB

查看:45
本文介绍了MATLAB 中向量数组的向量范数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在调用 norm 时MATLAB 中的矩阵,它返回所谓的矩阵范数"(标量值),而不是向量范数数组.有没有什么方法可以不循环利用MATLAB的向量化来获得矩阵中每个向量的范数?

When calling norm on a matrix in MATLAB, it returns what's known as a "matrix norm" (a scalar value), instead of an array of vector norms. Is there any way to obtain the norm of each vector in a matrix without looping and taking advantage of MATLAB's vectorization?

推荐答案

您可以使用 按元素算术运算符 和定义为在给定矩阵维度上操作的函数(如 SUM最大).以下是计算矩阵 M 的一些列范数的方法:

You can compute the norm of each column or row of a matrix yourself by using element-wise arithmetic operators and functions defined to operate over given matrix dimensions (like SUM and MAX). Here's how you could compute some column-wise norms for a matrix M:

twoNorm = sqrt(sum(abs(M).^2,1)); %# The two-norm of each column
pNorm = sum(abs(M).^p,1).^(1/p);  %# The p-norm of each column (define p first)
infNorm = max(M,[],1);            %# The infinity norm (max value) of each column

通过将维度参数从 ...,1 更改为 ...,2,可以轻松地使这些规范对行而不是列进行操作.

These norms can easily be made to operate on the rows instead of the columns by changing the dimension arguments from ...,1 to ...,2.

这篇关于MATLAB 中向量数组的向量范数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆