📄 norm.m
字号:
function n = norm(S,varargin)% NORM -- norm function for symbolic variables%% n = norm(x,type)%% This is the same as the usual NORM function, but for vectors% or matrices of symbolic constants (not symbolic variables).%% There should be no problem for vectors and for the 1-,% infinity-, or Frobenius-norm of matrices. However, it is likely % to be VERY slow and result in a VERY messy expression for % 2-norms of matrices larger than 2x2.% Copyright (c) 2004 by Fritz Keinert (keinert@iastate.edu),% Dept. of Mathematics, Iowa State University, Ames, IA 50011.% This software may be freely used and distributed for non-commercial% purposes, provided this copyright statement is preserved, and% appropriate credit for its use is given.%% Last update: Feb 20, 2004m = size(S);S = reshape(simplify(S(:)),m);if issymbolic(S) error('NORM is not defined for symbolic variables');endif (length(m) > 2) error('NORM is only defined for vectors and two-dimensional matrices');endif (nargin < 2) p = 2;else p = varargin{1};endif (m(1) == 1 | m(2) == 1)% S is a vector switch p case {inf,'inf'} n = simplify(max(abs(S))); case {-inf,'-inf'} n = simplify(min(abs(S))); case 1 n = simplify(sum(abs(S))); otherwise if ~isnumeric(p) error('P must be a number, ''inf'', or ''-inf'''); end if (p < 1) error('P must be between >= 1'); end n = simplify((sum(abs(S).^p))^(1/p)); endelse% S is a matrix switch p case {inf,'inf'} n = max(sum(abs(S.'))); case 1 n = max(sum(abs(S))); case 'fro' n = sqrt(sum(diag(S'*S))); case 2 n = max(svd(S)); otherwise error('P must be 1, 2, ''inf'' or ''fro'''); endend
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -