I cannot find the distance between two matrices with respect to the Frobenius inner product.

70 ビュー (過去 30 日間)
Hello everyone,
I am doing an assignment in MatLAB and I do not understand how to get the dist_AB value. I have tried using the norm command with inside the difference between A - B and the difference between the Frobenius form, but in each case the asnwer is not correct. I do not understand if I am using a wrong Matlab command or my math logic is wrong. Can someone help me?
%To find the Euclidean distance between two vectors, find the 2-norm of the difference of
%those vectors. Enter column vectors u and v. Then use the norm() command to find d(u,v), storing
%it in dist_uv.
u = [4; 3]
v = [-4; -12]
two_norm_u = norm(u, 2)
two_norm_v = norm(v, 2)
dist_uv = norm(u - v)
%To find the distance between two matrices with respect to the Frobenius inner product,
%find the Frobenius norm of the difference of those matrices. Enter matrices A and B.
%Then use the norm() command to find d(A,B), storing it in dist_AB.
A = [3 -7 4 3; -2 4 -5 0]
B = [1 -7 2 5; 0 0 -5 2]
fro_A = norm(A, 'fro')
fro_B = norm(B, 'fro')
%Below are the variables used for the last requirement, each are wrong.
fro_difference = norm(fro_A - fro_B)
dist_AB = norm(A - B)

採用された回答

Bruno Luong
Bruno Luong 2020 年 8 月 4 日
編集済み: Bruno Luong 2020 年 8 月 4 日
Distance in frobenius scalar product:
dist_AB = norm(A - B, 'fro')
which is the same as this
norm(A(:)-B(:),2)
  2 件のコメント
Bruno Luong
Bruno Luong 2020 年 8 月 4 日
編集済み: Bruno Luong 2020 年 8 月 4 日
norm(a) - norm(b)
doesn't measure the distance between a and b; regardless a, b are vector or matrix, or even number:
a = 1
b = -1
norm(a)-norm(b)
Matteo Geraci
Matteo Geraci 2020 年 8 月 4 日
I didn't realize that, I feel so dumb now. Thank you so much.

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by