Here is the code for calculating L2-norm of a vector in MATLAB:
main.m69 chars4 lines
In this code, a sample vector v
is defined and then norm()
function of MATLAB is used to calculate the L2-norm. The calculated L2-norm is then printed on the console using disp()
function.
Note: The norm()
function can also be used to calculate other types of norms like L1-norm, max-norm, etc. For example, to calculate L1-norm instead of L2-norm, replace the norm()
function with norm(v, 1)
in the code.
gistlibby LogSnag