Syntax
LL=vecnormr(VL)
Input Parameter
VL : | | vector [n x 2] or [n x 3] as rows |
Output Parameter
LL : | | vector norm of the rows |
Examples
v=rand(20,3), vecnormr(v), vecnorm(v')', vecnorm(v,2,2)
v=rand(10,2), vecnormr(v)
tic; a=vecnormr(rand(1e7,3)); toc
tic; a=vecnorm(rand(1e7,3),2,2); toc
Copyright 2019-2025 Tim C. Lueth. All rights reserved. The code is the property of Tim C. Lueth and may not be redistributed or modified without explicit written permission. This software may be used free of charge for academic research and teaching purposes only. Commercial use, redistribution, modification, or reverse engineering is strictly prohibited. Access to source code is restricted and granted only under specific agreements. For licensing inquiries or commercial use, please contact: Tim C. Lueth
Algorithm (Workflow)
This function, vecnormr
, is designed to compute the vector norm of each row in a matrix, where each row represents a vector. It is particularly useful for matrices where vectors are stored as rows, as opposed to the default column format used by MATLAB's built-in vecnorm
function.
Input Parameters
- VL: A matrix of size [n x 2] or [n x 3], where each row represents a vector. The function is designed to handle vectors in 2D or 3D space.
Output Results
- LL: A column vector containing the norm of each row vector in the input matrix
VL
.
Algorithm Steps
- The function first checks if the input matrix
VL
has more than one row using size(VL,1) > 1
.
- If
VL
has more than one row, it computes the norm of each row using vecnorm(VL,2,2)
. This calculates the Euclidean norm (2-norm) for each row vector.
- If
VL
has only one row, it computes the norm using vecnorm(VL)
, which defaults to the 2-norm.
- The result,
LL
, is a column vector where each element corresponds to the norm of a row vector from VL
.
Example Usage
Here are some examples demonstrating how to use the vecnormr
function:
- For a matrix
v
with random values: v=rand(20,3); vecnormr(v);
- Comparing performance with MATLAB's
vecnorm
: tic; a=vecnormr(rand(1e7,3)); toc;
and tic; a=vecnorm(rand(1e7,3),2,2); toc;
Algorithm explaination created using ChatGPT on 2025-08-18 23:24. (Please note: No guarantee for the correctness of this explanation)
Last html export of this page out of FM database by TL: 2025-09-21