Lesson16 Norm computations

来源:互联网 发布:mysql my.cnf 路径 编辑:程序博客网 时间:2024/06/16 11:43

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() = 5v.norm() = 2.23607v.lpNorm<1>() = 3v.lpNorm<Infinity>() = 2m.squaredNorm() = 30m.norm() = 5.47723m.lpNorm<1>() = 10m.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
原创粉丝点击