Hi, the following code is an initial version of a library of complex functions
Thanks HPprime TEAM, improve the CAS environment =)
/!\ The CAS functions must be covered in a block # cas ... # end
and must be run from the entry line, not because they do not operate from the editor programs =(
file: complexAlgebraLibrary.hpprgm
Code:
#cas
// © complex algebra library
// © complex numbers and functions
// © version 0.01 January 2015
// © By JaiMeza www.jaimeza.org
// © test CAS Version: 1.1.2-11 and Operating System: version 6.2.9200
cplxA := 3+4*; // numeric complex 3+4*i
cplxB := x+y*; // symbolic complex
// © modulus of a complex number given in standard form
modulus(z)
begin
return abs(z);
end;
// © real part of a complex number given in standard form
realPart(z)
begin
return re(z);
end;
// © imaginary part of a complex number given in standard form
imagPart(z)
begin
return im(z);
end;
// © conjugate of a complex number given in standard form
conjugat(z)
begin
return conj(z);
end;
// © argument of a complex number given in cartesian form (x,y)
cartArg(x,y)
begin
// © arguments (x, y)
if getMode_angle() == "RADIAN" then
return ((π/2)*sign(y) - atan(x/y));
else
return ((90)*sign(y) - atan(x/y));
end;
end;
// © argument of a complex number given in cartesian form
argument(z)
begin
// ©
Return arg(z)
end;
// © conversion from polar to cartesian form
polarRθtoCartXY(r, θ)
begin
return ( [[ r*cos(θ), r*sin(θ) ]] )
end;
exeSample()
begin
cplx1 := 3+4*;
cplx2 := x+y*;
print();
print( "*** Examples ***" ); freeze;
print( "cplx1 = " + cplx1 );
print( "cplx2 = " + cplx2 );
print("");
print( "modulus( " + cplx1 + ") = " + modulus(cplx1) );
print( "modulus( " + cplx2 + ") = " + modulus(cplx2) );
print("");
print( "realpart( " + cplx1 + ") = " + realPart(cplx1) );
print( "realpart( " + cplx2 + ") = " + realPart(cplx2) );
print("");
print( "imagpart( " + cplx1 + ") = " + imagPart(cplx1) );
print( "imagpart( " + cplx2 + ") = " + imagPart(cplx2) );
print("");
print( "conjugat( " + cplx1 + ") = " + conjugat(cplx1) );
print( "conjugat( " + cplx2 + ") = " + conjugat(cplx2) );
print("");
print("RADIAN");
setMode_angle( "RADIAN" );
print( "polarRθtoCartXY( 5, 0.927295218002_r ) = " + polarRθtoCartXY( 5, 0.927295218002) );
print( "cartArg( 3, 4 ) = " + cartArg( 3, 4 ) );
print( "argument( " + cplx1 + ") = " + approx( argument(cplx1) ) );
print("");
print("DEG");
setMode_angle( "DEG" );
print( "polarRθtocartXY( 5, 53.1301023542_° ) = " + polarRθtoCartXY( 5, 53.1301023542) );
print( "cartArg( 3, 4 ) = " + cartArg( 3, 4) );
print( "argument( " + cplx1 + ") = " + approx( argument(cplx1) ) );
freeze;
return "Done";
end;
#end
//#home
export getMode_angle()
begin
if AAngle == 1 then
return( "RADIAN" );
else
if AAngle == 2 then
return( "DEG" );
else
return( "SYS_ANGLE" );
end;
end;
end;
export setMode_angle( angle_mode )
begin
if angle_mode == "RADIAN" then
AAngle := 1
else
if angle_mode == "DEG" then
AAngle := 2
else
AAngle := 0
end;
end;
end;
//#end;
Run on ENTRY LINE the function exeSample() to show the operation of the functions I'm programming
PD: The character "
i" and not displayed on this forum =(, and in the PC program editor (Hp Conn Kit) a empty box is shown =(
I think it is a problem of the font text, please confirm this on their computers.
Please provide an updated text font
Note: the function list are displayed by pressing the [VAR] key after CAS Menu
To edit function by function press MEM [Shift]+[Tools], as a requirement HPPrime TEAm please make it show in full screen, currently editing in one line =(, another request is to allow copy all output from the terminal view, the purpose of pasting it into a tutorial or in this forum for example