Formula for norm(x)

3 ビュー (過去 30 日間)
Manu Chaudhary
Manu Chaudhary 2022 年 9 月 22 日
編集済み: Matt J 2022 年 9 月 22 日
Hi everyone, please describe me the formula for norm (x) where x is a complex vector?
  1 件のコメント
James Tursa
James Tursa 2022 年 9 月 22 日

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

採用された回答

James Tursa
James Tursa 2022 年 9 月 22 日
編集済み: James Tursa 2022 年 9 月 22 日
This question appears to be a follow-up to this post:
You gave your attempt in that post, but it didn't do the sum properly. Here is a corrected version of your code with some edits. I would recommend to use double for the sum and normalized value:
double norm = 0.0;
for(int i=0;i < data_size; i++){
// real_number and img_number are the vectors
norm = norm + real_number[i]*real_number[i] + img_number[i]*img_number[i];
}
norm = sqrt(norm);
If there is the possibility that the int*int result could overflow (I don't know the range of your numbers), then cast those numbers to doubles first. E.g.,
norm = norm + (double)real_number[i]*(double)real_number[i] + (double)img_number[i]*(double)img_number[i];
  1 件のコメント
Manu Chaudhary
Manu Chaudhary 2022 年 9 月 22 日
Thank you Sir. I will change everything to double for avoid any unnecessary error. Thank you for great help.

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

その他の回答 (1 件)

Matt J
Matt J 2022 年 9 月 22 日
編集済み: Matt J 2022 年 9 月 22 日
Assuming you're only interested in p=2, if you already have code that computes norm(x) for real x, you can extend it to complex x via,
norm(x) = norm( [norm(real(x)), norm(imag(x)) ] )
which is easily verified below,
x=complex(rand(5,1), rand(5,1));
norm(x)
ans = 1.5694
norm( [norm(real(x)), norm(imag(x)) ] )
ans = 1.5694
Alternatively, if you have an implementation of abs, you could do norm(abs(x),p) which will work for any p-norm
p=3;
norm(x,p)
ans = 1.2935
norm(abs(x),p)
ans = 1.2935

カテゴリ

Find more on Linear Algebra in Help Center and File Exchange

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by