MATLAB Answers

Magnitude of a vector

4,782 views (last 30 days)
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
Prashant C on 3 Jun 2015
use the function norm(r) or mag=sqrt(sum(r.*r))
Abdullraheem Diab
Abdullraheem Diab on 30 Jun 2019

Sign in to comment.

Accepted Answer

Shashank Prasanna
Shashank Prasanna on 5 Sep 2013
Edited: MathWorks Support Team on 22 May 2019
This works perfectly fine on MATLAB R2013a:
>> syms x y z
r = [x y z];


Shashank Prasanna
Shashank Prasanna on 5 Sep 2013
What version of MATLAB are you using? Can you confirm that you see the file when you run this:
>> which sym/norm
Bhuvana Krishnaraj
Bhuvana Krishnaraj on 3 Jun 2019
2015.a version >>which sym/nom C:\matlab\toolbox\symbolic\@!sym\norm.m

Sign in to comment.

More Answers (2)

Azzi Abdelmalek
Azzi Abdelmalek on 5 Sep 2013


Sign in to comment.

Tariq Shajahan
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.

Sign in to answer this question.