what exactly norm(x) function do?
Mostra commenti meno recenti
Good Afternoon,
I have to convert a part of my matlab code into C++.
I would be great if you can explain me what exactly norm(x) do on a vector of complex number so that I can write a C++ code for it.
I just asked a similar question on stack overflow but could not get much response.
Thank you in advance.
5 Commenti
Manu Chaudhary
il 21 Set 2022
Spostato: Adam Danz
il 22 Set 2022
Steven Lord
il 22 Set 2022
Are you performing the conversion to C++ manually or using MATLAB Coder? According to the Extended Capabilities section on its documentation page you can automatically generate C or C++ code from the norm function using MATLAB Coder.
Manu Chaudhary
il 22 Set 2022
Manu Chaudhary
il 22 Set 2022
Modificato: Manu Chaudhary
il 22 Set 2022
Risposta accettata
Più risposte (1)
Assuming you only care about 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)
norm( [norm(real(x)), norm(imag(x)) ] )
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)
norm(abs(x),p)
Categorie
Scopri di più su Loops and Conditional Statements in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
