angle function in matlab formula

Hi everyone,
I am trying to understand the functionality of angle function of matlab. I am trying to convert my matlab code(which we use for proof of concept) to C++ implementation.
input to angle function - 0.487936206701072 + 0.660466136142335i
output of angle function - 0.934517679414299
I know it must be tan-inverse(img/real) with some other constant.
Please help me with the formula?

답변 (1개)

Torsten
Torsten 2022년 9월 22일
편집: Torsten 2022년 9월 22일

1 개 추천

It's all written in the MATLAB documentation of "angle":
Algorithms
angle takes a complex number z = x + iy and uses the atan2 function to compute the angle between the positive x-axis and a ray from the origin to the point (x,y) in the xy-plane.
Here is the "proof":
format long
z = 0.487936206701072 + 0.660466136142335*1i;
angle(z)
ans =
0.934517679414299
atan2(imag(z),real(z))
ans =
0.934517679414299

댓글 수: 7

Manu Chaudhary
Manu Chaudhary 2022년 9월 22일
So, i am assuming that atan2 means a simple mathematical tan inverse?
Torsten
Torsten 2022년 9월 23일
편집: Torsten 2022년 9월 23일
Manu Chaudhary
Manu Chaudhary 2022년 9월 23일
It would be great help if you provide a mathematical formula or a small c/c++ code for it.
James Tursa
James Tursa 2022년 9월 23일
편집: James Tursa 2022년 9월 23일
It is an included function to the standard C++ math library. E.g., here is the C++ code:
#include <cmath>
// some code here to assign real_part and imag_part
result = atan2(imag_part,real_part);
Torsten
Torsten 2022년 9월 23일
편집: Torsten 2022년 9월 23일
atan2 is a c++ function.
So make an artificial mex-function that calls the c++ version of atan2 (or whatever you intend to do).
Manu Chaudhary
Manu Chaudhary 2022년 9월 23일
Yes, atan function works in c++ but not atan2.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Call C++ from MATLAB에 대해 자세히 알아보기

태그

질문:

2022년 9월 22일

편집:

2022년 9월 23일

Community Treasure Hunt

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

Start Hunting!

Translated by