Magnitude of a vector

2,590 ビュー (過去 30 日間)
Philosophaie
Philosophaie 2013 年 9 月 5 日
コメント済み: Steven Lord 2023 年 3 月 11 日
syms x y z
r = [x y z]
rmag???
rmag should equal (x^2 + y^2 + z^2)^0.5
  4 件のコメント
Prashant C
Prashant C 2015 年 6 月 3 日
use the function norm(r) or mag=sqrt(sum(r.*r))
Abdullraheem Diab
Abdullraheem Diab 2019 年 6 月 30 日
Sqrt(sum(r.^2))

サインインしてコメントする。

採用された回答

Shashank Prasanna
Shashank Prasanna 2013 年 9 月 5 日
編集済み: MathWorks Support Team 2019 年 5 月 22 日
This works perfectly fine on MATLAB R2013a:
>> syms x y z
r = [x y z];
norm(r)
  2 件のコメント
Shashank Prasanna
Shashank Prasanna 2013 年 9 月 5 日
編集済み: MathWorks Support Team 2019 年 5 月 22 日
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 2019 年 6 月 3 日
2015.a version >>which sym/nom C:\matlab\toolbox\symbolic\@!sym\norm.m

サインインしてコメントする。

その他の回答 (2 件)

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 9 月 5 日
m=sqrt(x^2+y^2+z^2)

Tariq Shajahan
Tariq Shajahan 2015 年 5 月 11 日
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!!
  2 件のコメント
John D'Errico
John D'Errico 2023 年 3 月 11 日
If r is an array of vectors, what would you expect? How does MATLAB know, for example, that you want to compute the norm of each row of an array, as opposed to a matrix norm? In fact, when MATLAB is given a double precision array, and you use norm, it computes the MATRIX norm.
A = magic(5)
A = 5×5
17 24 1 8 15 23 5 7 14 16 4 6 13 20 22 10 12 19 21 3 11 18 25 2 9
norm(A)
ans = 65
There is no reason to expect it should instead compute the norm of each row, or each column. That would be wrong.
norm(sym(A))
ans = 
65
And norm is able to do the same thing for a symbolic array. So there should be no surprise here.
Steven Lord
Steven Lord 2023 年 3 月 11 日
To compute the norm of each row or column of a numeric matrix use vecnorm instead of norm.
A = magic(5);
vecnorm(A, 2, 1) % default 2-norm in dimension 1
ans = 1×5
32.4808 33.2415 34.7131 33.2415 32.4808
vecnorm(A, 1, 2) % 1-norm in dimension 2
ans = 5×1
65 65 65 65 65

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLinear Algebra についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by