MHKiT-Software / MHKiT-MATLAB

MHKiT-MATLAB provides the marine renewable energy (MRE) community tools for data processing, visualization, quality control, resource assessment, and device performance.
https://mhkit-software.github.io/MHKiT/
BSD 3-Clause "New" or "Revised" License
15 stars 23 forks source link

Addressing issue #59 magnitude and phase function for Matlab #76

Closed Alex-McVey closed 2 years ago

Alex-McVey commented 2 years ago

Magnitude and phase function developed in Matlab with identical function to the one available in Python.

The following code can be used to test 2D function in Matlab magnitude = 9; y = sqrt(1/2*magnitude^2);, x=y; phase = atan2(y,x); [mag, theta] = magnitude_phase({x; y}); assert(all(magnitude == mag)) assert(all(phase == theta)) xx = [x,x]; yy = [y,y]; [mag, theta] = magnitude_phase({xx; yy}); assert(all(magnitude == mag)) assert(all(phase == theta))

The following code can be used to test 3D function in Matlab magnitude = 9; y = sqrt(1/3*magnitude^2);, x=y;, z=y; phase1 = atan2(y,x); phase2 = atan2(sqrt(x.^2 + y.^2),z); [mag, theta, phi] = magnitude_phase({x; y; z}); assert(all(magnitude == mag)) assert(all(phase1 == theta)) assert(all(phase2 == phi)) xx = [x,x]; yy = [y,y]; zz = [z,z]; [mag, theta, phi] = magnitude_phase({xx; yy; zz}); assert(all(magnitude == mag)) assert(all(phase1 == theta)) assert(all(phase2 == phi))

rpauly18 commented 2 years ago

@Alex-McVey similarly to your other PR, this will need test(s) written.