MATLAB: How to calculate the magnitude of n-dimensional vector by Matlab’s commands

magnitudevector

Is there any specific command for calculating the magnitude of n-dimensional vector?

Best Answer

I'll assume by "magnitude", you mean the norm. You can just do
norm(x)
but there are different norms with different results
x = randn(10,1);
norm(x,2)
norm(x,1)
norm(x,inf)
So you have to know which one you want. Just
norm(x)
gives the 2-norm by default.