Post Reply 
Unreliable complex calculation in CAS? Bug?
04-07-2020, 09:14 PM (This post was last modified: 04-07-2020 09:16 PM by Dands.)
Post: #1
Unreliable complex calculation in CAS? Bug?
Hello,

Please follow my steps and let me know if I did anything wrong or if there's really a bug here. The same calculation in Home gave me the expected result.

I am using the matrix "MA" in terms of "a" to find the symmetrical components of a current vector as follows:

[Image: Screen-Shot-2020-04-07-at-3-01-43-PM.png]

First I declare my variables. "a" is the phasor 1∠120°
[Image: 1a.png]

Here's MA times the vector from the example above.
[Image: 1b.png]

Now I copy and bring this result in rectangular form to Home since CAS is unfortunately not able to change it to polar (frustrating). As you can see, the third value is completely off.
[Image: 1c.png]

And here is the same calculation when executed completely in Home, providing the expected (approximate) result:
[Image: 1d.png]

Any ideas?

Thanks
Find all posts by this user
Quote this message in a reply
04-07-2020, 11:53 PM (This post was last modified: 04-08-2020 12:33 AM by victorvbc.)
Post: #2
RE: Unreliable complex calculation in CAS? Bug?
It's a numerical precision thing. Both real and imaginary parts are in the order of 10^-14. Since you have to calculate the arc tangent of the ratio of these coordinates to get the angle, for such small values it depends on the numerical error.
Find all posts by this user
Quote this message in a reply
04-08-2020, 01:08 AM
Post: #3
RE: Unreliable complex calculation in CAS? Bug?
(04-07-2020 11:53 PM)victorvbc Wrote:  It's a numerical precision thing. Both real and imaginary parts are in the order of 10^-14. Since you have to calculate the arc tangent of the ratio of these coordinates to get the angle, for such small values it depends on the numerical error.

So it's a bug or something wrong with my CAS settings?
Find all posts by this user
Quote this message in a reply
04-08-2020, 02:14 AM (This post was last modified: 04-08-2020 02:26 AM by victorvbc.)
Post: #4
RE: Unreliable complex calculation in CAS? Bug?
(04-08-2020 01:08 AM)Dands Wrote:  So it's a bug or something wrong with my CAS settings?

I think the problem is that the polar input in CAS doesn't give results in exact form... not much you can do abt that, maybe it's a bug. Wouldn't be hard to write your own routine for that in PPL though.

If you input all the phasors in exact form (cos(x)+i*sin(x) or complex exponential) the CAS gives the correct exact result vector:

[[1443*√3/100],[-1443*√3/100],[0]]
Find all posts by this user
Quote this message in a reply
04-08-2020, 04:10 AM (This post was last modified: 04-08-2020 04:24 AM by Dands.)
Post: #5
RE: Unreliable complex calculation in CAS? Bug?
(04-08-2020 02:14 AM)victorvbc Wrote:  
(04-08-2020 01:08 AM)Dands Wrote:  So it's a bug or something wrong with my CAS settings?

I think the problem is that the polar input in CAS doesn't give results in exact form... not much you can do abt that, maybe it's a bug. Wouldn't be hard to write your own routine for that in PPL though.

If you input all the phasors in exact form (cos(x)+i*sin(x) or complex exponential) the CAS gives the correct exact result vector:

[[1443*√3/100],[-1443*√3/100],[0]]

The problem is that if you're in degrees mode, the exponential form will only take arguments in radians. I say that because I tried to input 14.43∠30° as 14.43e^i30 and did not get the answer.

I probably found another good example showing why the polar capabilities in CAS need to be improved asap.

Thanks
Find all posts by this user
Quote this message in a reply
04-08-2020, 04:02 PM (This post was last modified: 04-08-2020 04:07 PM by victorvbc.)
Post: #6
RE: Unreliable complex calculation in CAS? Bug?
(04-08-2020 04:10 AM)Dands Wrote:  The problem is that if you're in degrees mode, the exponential form will only take arguments in radians. I say that because I tried to input 14.43∠30° as 14.43e^i30 and did not get the answer.

I probably found another good example showing why the polar capabilities in CAS need to be improved asap.

Thanks

Complex exponentials are always in radians. You have to do the conversion for radians.

The problem is the CAS doesn't support operations directly in polar notation (someone correct me if I'm wrong), which makes phasors a bit inconvenient.

Anyway, here's something that might help you with that:

Code:

#cas
phasor(mag,phase):=
BEGIN

IF HAngle=1 THEN
  phase=pi*phase/180;
END

RETURN QPI(mag)*simplify(e^(QPI(phase)*i));

END;
#end

Here I use QPI instead of exact, because I like it better. I also like to throw a simplify in there, but you can remove it if you want.

I like to put this kind of function in a user key, so that it's easily accessible by pressing shift+user+mult(angle).


Code:

KEY K_Mul()
BEGIN
RETURN "phasor()";
END;

By using this you make sure the operations with phasors in CAS are always exact. After simplifying, you can use approx() to get your answer in decimal.

   

Just be careful, if there's even a single float in your matrix operation it will default to numeric mode.

   
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)