MATLAB Answers


Magnitude of a vector

Asked by Philosophaie on 5 Sep 2013
Latest activity Commented on by Abdullraheem Diab on 30 Jun 2019
syms x y z
r = [x y z]
rmag should equal (x^2 + y^2 + z^2)^0.5


Show 1 older comment
Philosophaie on 5 Sep 2013
I am looking for the magnitude of the vector r. It should be equal to r = (x^2 + y^2 + z^2)^0.5.
Prashant C on 3 Jun 2015
use the function norm(r) or mag=sqrt(sum(r.*r))

Sign in to comment.


3 Answers

Answer by Shashank Prasanna on 5 Sep 2013
Edited by MathWorks Support Team on 22 May 2019
 Accepted Answer

This works perfectly fine on MATLAB R2013a:
>> syms x y z
r = [x y z];


What version of MATLAB are you using? Can you confirm that you see the file when you run this:
>> which sym/norm
2015.a version >>which sym/nom C:\matlab\toolbox\symbolic\@!sym\norm.m

Sign in to comment.

Azzi Abdelmalek
Answer by Azzi Abdelmalek
on 5 Sep 2013



Sign in to comment.

Answer by Tariq Shajahan on 11 May 2015

if 'r' is a vector. norm(r), gives the magnitude only if the vector has values. If r is an array of vectors, then the norm does not return the magnitude, rather the norm!!


Sign in to comment.