I have an application that works with complex number. It simply asks the user to input 3 numbers (magnitude and phase for all 3) and then performs a computation. However it computes the incorrect result.
When I perform the same computation by hand or using Matlab I get a zero phase for the result. But using the C++ code I get a phase of 2.02 degrees. Is there a problem with the C++ class that could cause this?
1 2 3 4
a=polar ( 1.0, 120 * PI / 180 );
a2=polar ( 1.0, 240 * PI / 180 );
Result = (First_Complex + (a2*Sec_Complex) + ( a*Third_Complex)) / 3.0;
To test my code I input 3 values: 93<0, 93<-120, 93<120
These three put through that computation should give a result of ~0 magnitude and exactly 0 phase.
Since the * and / same operator precedence/priority, may be it is calculating as not desired.
In terms of formula (which I am not familiar with), is it 120*PI / 180 or 120 * PI/180 ??
Try enclosing them in brackets and run again.
Like:
a = polar (1.0, (120*PI)/180)
or
a = polar (1.0, 120*(PI/180))
Just a note to this, I am looking at the result in polar form using abs() and arg(). The abs is returning the correct result but the arg() is returning 2.02 rad. This cooresponds to 115.74 degrees. Not exactly zero as it should be.
The brackets segmenting the operator in the polar call does not change the result. The formula is just a conversion from degrees (120) to rad which is: degrees * PI / 180. The order of the division and multiplication does not change the resultant.