Post Reply 
(Feature Request) - Convert to polar (phasor) notation in CAS
03-31-2020, 09:16 PM (This post was last modified: 03-31-2020 09:19 PM by victorvbc.)
Post: #13
RE: (Feature Request) - Convert to polar (phasor) notation in CAS
(03-31-2020 08:14 PM)Dands Wrote:  I think something weird is happening, probably because you used the simplify command in the output. I removed it and it persisted, so I'm clueless. Both of these should provide an angle of 45deg. I think it is not handling it properly when coefficients a and b are not integers.

Also, is it normal to see the terminal showing so many alerts?


That is quite weird... I guess the CAS doesn't like converting angles from floating point complex numbers to degrees. Anyway, here's a quick & dirty fix:

Code:

//This program takes an expression or matrix and turns it into polar coordinates
#cas
toPolar(z):= 
BEGIN
LOCAL sizes,j,k;

IF type(z)=DOM_LIST THEN //check if is list/matrix
  sizes:=SIZE(z); //get dimension of rows and columns
  IF size(sizes)=1 THEN //row vector
    FOR j FROM 1 to sizes DO
      z[j]:=convert_polar(z[j]); //convert each element to polar
    END;
  ELSE //column vector or matrix
    FOR j FROM 1 to sizes(1) DO
      FOR k FROM 1 to sizes(2) DO
        z[j,k]:=convert_polar(z[j,k]); //convert each element to polar
      END; 
    END;
  END;
ELSE
  z:=convert_polar(z); //single element
END;

RETURN z;
END;

convert_polar(x):=
BEGIN
  IF type(IM(x))=DOM_FLOAT OR type(RE(x))=DOM_FLOAT THEN
    x:=exact(x);
      RETURN approx({ABS(x),ARG(x)});
  ELSE
    RETURN {ABS(x),ARG(x)};
  END;
END;
#end

It works for that case now. I don't know about the errors, I didn't get them.

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


Messages In This Thread
RE: (Feature Request) - Convert to polar (phasor) notation in CAS - victorvbc - 03-31-2020 09:16 PM



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