Magnitude of a vector
2,589 次查看(过去 30 天)
显示 更早的评论
syms x y z
r = [x y z]
rmag???
rmag should equal (x^2 + y^2 + z^2)^0.5
4 个评论
采纳的回答
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
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
更多回答(3 个)
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
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)
norm(A)
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))
And norm is able to do the same thing for a symbolic array. So there should be no surprise here.
Steven Lord
2023-3-11
A = magic(5);
vecnorm(A, 2, 1) % default 2-norm in dimension 1
vecnorm(A, 1, 2) % 1-norm in dimension 2
namal
2024-8-23
% Define the vector N = [-3, 7, -5]; % Calculate the magnitude of the vector magnitude = norm(N); % Calculate the unit vector unit_vector = N / magnitude; % Display the unit vector disp('Unit vector in the direction of N:'); disp(unit_vector);
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!