Lesson16 Norm computations

51 篇文章 7 订阅
22 篇文章 1 订阅

The (Euclidean a.k.a. $\ell^2$) squared norm of a vector can be obtained squaredNorm() . It is equal to the dot product of the vector by itself, and equivalently to the sum of squared absolute values of its coefficients.

Eigen also provides the norm() method, which returns the square root of squaredNorm() .

These operations can also operate on matrices; in that case, a n-by-p matrix is seen as a vector of size (n*p), so for example the norm() method returns the "Frobenius" or "Hilbert-Schmidt" norm. We refrain from speaking of the $\ell^2$ norm of a matrix because that can mean different things.

If you want other $\ell^p$ norms, use the lpNnorm<p>() method. The template parameter p can take the special value Infinityif you want the $\ell^\infty$ norm, which is the maximum of the absolute values of the coefficients.

The following example demonstrates these methods.

Example: Output:
#include <Eigen/Dense>
#include <iostream>
using namespace std;
using namespace Eigen;
int main()
{
VectorXf v(2);
MatrixXf m(2,2), n(2,2);
v << -1,
2;
m << 1,-2,
-3,4;
cout << "v.squaredNorm() = " << v. squaredNorm() << endl;
cout << "v.norm() = " << v.norm() << endl;
cout << "v.lpNorm<1>() = " << v.lpNorm<1>() << endl;
cout << "v.lpNorm<Infinity>() = " << v.lpNorm< Infinity>() << endl;
cout << endl;
cout << "m.squaredNorm() = " << m. squaredNorm() << endl;
cout << "m.norm() = " << m. norm() << endl;
cout << "m.lpNorm<1>() = " << m.lpNorm<1>() << endl;
cout << "m.lpNorm<Infinity>() = " << m.lpNorm< Infinity>() << endl;
}
v.squaredNorm() = 5
v.norm() = 2.23607
v.lpNorm<1>() = 3
v.lpNorm<Infinity>() = 2

m.squaredNorm() = 30
m.norm() = 5.47723
m.lpNorm<1>() = 10
m.lpNorm<Infinity>() = 4


1、向量范数

1-范数:,即向量元素绝对值之和,matlab调用函数norm(x, 1) 。

2-范数:,Euclid范数(欧几里得范数,常用计算向量长度),即向量元素绝对值的平方和再开方,matlab调用函数norm(x, 2)。

∞-范数:,即所有向量元素绝对值中的最大值,matlab调用函数norm(x, inf)。

-∞-范数:,即所有向量元素绝对值中的最小值,matlab调用函数norm(x, -inf)。

p-范数:,即向量元素绝对值的p次方和的1/p次幂,matlab调用函数norm(x, p)。


2、矩阵范数

1-范数:, 列和范数,即所有矩阵列向量绝对值之和的最大值,matlab调用函数norm(A, 1)。

2-范数:,谱范数,即A'A矩阵的最大特征值的开平方。matlab调用函数norm(x, 2)。

∞-范数:,行和范数,即所有矩阵行向量绝对值之和的最大值,matlab调用函数norm(A, inf)。

F-范数:,Frobenius范数,即矩阵元素绝对值的平方和再开平方,matlab调用函数norm(A, ’fro‘)。


附matlab中norm函数说明

The norm of a matrix is a scalar that gives some measure of the magnitude of the elements of the matrix. The norm function calculates several different types of matrix norms:

n = norm(A) returns the largest singular value of A, max(svd(A)).
n = norm(A,p) returns a different kind of norm, depending on the value of p.


When A is a vector:










  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值