📄 complex_hss.pas
字号:
tmp:= 1/(sqr(Z1.x) + sqr(Z1.y) + SmallLimit) ;
result.x:= Z1.x*tmp;
result.y:=-Z1.y*tmp;
End;
Procedure C_RevV(var Z1: TComplex); {Z1:=1/Z1}
var tmp: CmxFloat;
Begin
tmp := 1/(sqr(Z1.x) + sqr(Z1.y) + SmallLimit);
Z1.x := Z1.x*tmp;
Z1.y :=-Z1.y*tmp;
End;
Function C_Chs (const Z1: TComplex): TComplex; {Z:=-Z1} {求负}
begin
result.x:=-Z1.x;
result.y:=-Z1.y
end;
Procedure C_ChsV (var Z1: TComplex); {Z1:=-Z1} {求负}
begin
Z1.x:=-Z1.x;
Z1.y:=-Z1.y;
end;
Function C_Rev2 (const Z1: TComplex;const Z2: TComplex): TComplex; {Z:=1/(Z1-Z2)}
var a,b,tmp: CmxFloat;
Begin
a:=Z1.x-Z2.x;
b:=Z2.y-Z1.y;
tmp:= 1/(sqr(a) + sqr(b) + SmallLimit) ;
result.x:= a*tmp;
result.y:= b*tmp;
End;
Procedure C_Rev2V(var Z1: TComplex; const Z2: TComplex); {Z1:=1/(Z1-Z2)}
var a,b,tmp: CmxFloat;
Begin
a:=Z1.x-Z2.x;
b:=Z2.y-Z1.y;
tmp:= 1/(sqr(a) + sqr(b) + SmallLimit) ;
Z1.x := a*tmp;
Z1.y := b*tmp;
End;
function C_Sgn (const Z1: TComplex):TComplex; {Z:=Sgn(Z1)}
begin
if Z1.x>0 then
result.x:=1
else if Z1.x<0 then
result.x:=-1
else
result.x:=0;
if Z1.y>0 then
result.y:=1
else if Z1.y<0 then
result.y:=-1
else
result.y:=0;
end;
Procedure C_SgnV (var Z1: TComplex); {Z1:=Sgn(Z1)}
begin
if Z1.x>0 then
Z1.x:=1
else if Z1.x<0 then
Z1.x:=-1
else
Z1.x:=0;
if Z1.y>0 then
Z1.y:=1
else if Z1.y<0 then
Z1.y:=-1
else
Z1.y:=0;
end;
Procedure C_Xchg (var Z1: TComplex;var Z2: TComplex); {交换值Z1<=>Z2)}
var tmp: CmxFloat;
begin
tmp:=Z1.x;
Z1.x:=Z2.x;
Z2.x:=tmp;
tmp:=Z1.y;
Z1.y:=Z2.y;
Z2.y:=tmp;
end;
Procedure C_Xchg (var Z1: TComplex);
var
tmp : CmxFloat;
begin
tmp:=Z1.x;
Z1.x:=Z1.y;
Z1.y:=tmp;
end;
function C_Max (const Z1:TComplex;const Z2:TComplex):TComplex; overload; {由绝对值决定}
begin
if sqr(Z1.x)+sqr(Z1.y)>sqr(Z2.x)+sqr(Z2.y) then
result:=Z1
else
result:=Z2;
end;
function C_Min (const Z1:TComplex;const Z2:TComplex):TComplex; overload; {由绝对值决定}
begin
if sqr(Z1.x)+sqr(Z1.y)<sqr(Z2.x)+sqr(Z2.y) then
result:=Z1
else
result:=Z2;
end;
function C_MaxX (const Z1:TComplex;const Z2:TComplex):TComplex; overload; {由实部值决定}
begin
if Z1.x>Z2.x then
result:=Z1
else
result:=Z2;
end;
function C_MinX (const Z1:TComplex;const Z2:TComplex):TComplex; overload; {由实部值决定}
begin
if Z1.x<Z2.x then
result:=Z1
else
result:=Z2;
end;
//==============================================================================
//{复数函数_次方}
Function C_Sqr (const Z1: TComplex): TComplex; {Z:=Z1*Z1}
Begin
result.x:=(Sqr(Z1.x)-Sqr(Z1.y));
result.y:= (Z1.x*Z1.y) * 2;
End;
Procedure C_SqrV(var Z1: TComplex); {Z1:=Z1*Z1}
var tmp: CmxFloat;
Begin
tmp :=(Sqr(Z1.x)-Sqr(Z1.y));
Z1.y:= Z1.x*Z1.y * 2;
Z1.x:=tmp;
End;
Function C_Sqr3 (const Z1: TComplex): TComplex; {Z:=Z1^3}
Begin
result.x:=Z1.x*(sqr(Z1.x) - 3*sqr(Z1.y));
result.y:=Z1.y*(3*sqr(Z1.x) - sqr(Z1.y));
End;
Procedure C_Sqr3V(var Z1: TComplex); {Z1:=Z1^3}
var tmp: CmxFloat;
Begin
tmp :=Z1.x*(sqr(Z1.x) - 3*sqr(Z1.y));
Z1.y:=Z1.y*(3*sqr(Z1.x) - sqr(Z1.y));
Z1.x:=tmp;
End;
Function C_Sqr4 (const Z1: TComplex): TComplex; {Z:=Z1^4}
var tmp1: CmxFloat;
tmp2: CmxFloat;
Begin
tmp1:=(Sqr(Z1.x)-Sqr(Z1.y));
tmp2:= Z1.x*Z1.y * 2;
result.x:=(sqr(tmp1)-Sqr(tmp2));
result.y:= tmp1*tmp2 * 2;
End;
Procedure C_Sqr4V(var Z1: TComplex); {Z1:=Z1^4}
var tmp1: CmxFloat;
tmp2: CmxFloat;
Begin
tmp1:=(Sqr(Z1.x)-Sqr(Z1.y));
tmp2:= Z1.x*Z1.y * 2;
Z1.x:=(sqr(tmp1)-sqr(tmp2));
Z1.y:= tmp1*tmp2 * 2;
End;
Function C_Power (const Z1: TComplex;const Z2: TComplex;const K:integer=0): TComplex; {Z:=Z1^Z2}
var tmph1x: CmxFloat;
tmph1y: CmxFloat;
tmph2x: CmxFloat;
tmph2y: CmxFloat;
tmpf : CmxFloat;
s,c : CmxFloat;
Begin
tmph1x:=0.5*Ln(sqr(Z1.x)+sqr(Z1.y) + SmallLimit); //2003.3.29 Error!!! sqr(sqr(Z1.y))
tmph1y:=ArcTan2(Z1.y, Z1.x)+(2*PI)*K;
tmph2x:=tmph1x*Z2.x-tmph1y*Z2.y;
tmph2y:=tmph1y*Z2.x+tmph1x*Z2.y;
tmpf :=Exp(tmph2x);
sincos(tmph2y,s,c);
result.x :=tmpf*c;
result.y :=tmpf*s;
End;
Procedure C_PowerV(var Z1: TComplex;const Z2: TComplex;const K:integer=0); {Z1:=Z1^Z2}
var tmph1x: CmxFloat;
tmph1y: CmxFloat;
tmph2x: CmxFloat;
tmph2y: CmxFloat;
tmpf : CmxFloat;
s,c : CmxFloat;
Begin
tmph1x:=0.5*Ln(sqr(Z1.x)+sqr(Z1.y) + SmallLimit);
tmph1y:=ArcTan2(Z1.y, Z1.x)+(2*PI)*K;
tmph2x:=tmph1x*Z2.x-tmph1y*Z2.y;
tmph2y:=tmph1y*Z2.x+tmph1x*Z2.y;
tmpf :=Exp(tmph2x);
sincos(tmph2y,s,c);
Z1.x :=tmpf*c;
Z1.y :=tmpf*s;
End;
Function C_Power (const Z1:TComplex;const x: CmxFloat;const K:integer=0): TComplex; {Z:=Z1^x}
var tmp1: CmxFloat;
tmp2: CmxFloat;
tmpf: CmxFloat;
c,s : CmxFloat;
Begin
tmp1:=0.5*x*Ln(sqr(Z1.x)+sqr(Z1.y) + SmallLimit);
tmp2:=x*(ArcTan2(Z1.y,Z1.x)+(2*PI)*K);
tmpf:=Exp(tmp1);
sincos(tmp2,s,c);
result.x:=tmpf*C;
result.y:=tmpf*S;
End;
Procedure C_PowerV(var Z1: TComplex;const x: CmxFloat;const K:integer=0); {Z1:=Z1^x}
var tmp1: CmxFloat;
tmp2: CmxFloat;
tmpf: CmxFloat;
c,s : CmxFloat;
Begin
tmp1:=0.5*x*Ln(sqr(Z1.x)+sqr(Z1.y) + SmallLimit);
tmp2:=x*(ArcTan2(Z1.y,Z1.x)+(2*PI)*K);
tmpf:=Exp(tmp1);
sincos(tmp2,s,c);
Z1.x:=tmpf*C;
Z1.y:=tmpf*S;
End;
//------------------------------------------------------------------------------
Function C_Sqrt (const Z1: TComplex;const K:integer=0): TComplex; {Z:=Sqrt(Z1)}
var tmp1: CmxFloat;
tmp2: CmxFloat;
c,s : CmxFloat;
Begin
With Z1 do
begin
tmp1:=Sqrt(Sqrt(sqr(X)+sqr(Y)));
tmp2:=0.5*(ArcTan2(Y,X)+(2*PI)*K);
sincos(tmp2,s,c);
result.x:=tmp1*c;
result.y:=tmp1*s;
end;
End;
Procedure C_SqrtV(var Z1: TComplex;const K:integer=0); {Z1:=Sqrt(Z1)}
var tmp1: CmxFloat;
tmp2: CmxFloat;
c,s : CmxFloat;
Begin
With Z1 do
begin
tmp1:=Sqrt(Sqrt(sqr(X)+sqr(Y)));
tmp2:=0.5*(ArcTan2(Y,X)+(2*PI)*K);
sincos(tmp2,s,c);
X:=tmp1*c;
Y:=tmp1*s;
end;
End;
Procedure C_Sqrt(const Z1:TComplex;var Z:array of TComplex);{Z(i):=Sqrt(Z1)}
var tmp1: CmxFloat;
tmp2: CmxFloat;
c,s : CmxFloat;
Begin
With Z1 do
begin
tmp1:=Sqrt(Sqrt(sqr(X)+sqr(Y)));
tmp2:=0.5*(ArcTan2(Y,X));
sincos(tmp2,s,c);
Z[0].x:=tmp1*c;
z[0].y:=tmp1*s;
tmp2:=tmp2+PI;
sincos(tmp2,s,c);
Z[1].x:=tmp1*c;
z[1].y:=tmp1*s;
end;
End;
Function C_SqrtN (const Z1: TComplex;const N:CmxFloat;const K:integer=0): TComplex; {Z:=Z1^(1/N)}
var tmp1: CmxFloat;
tmp2: CmxFloat;
tmpf: CmxFloat;
c,s : CmxFloat;
Begin
tmpf:=N;
if tmpf=0 then tmpf:=SmallLimit;
tmpf:=1.0/tmpf;
tmp1:=0.5*Ln(sqr(Z1.x)+sqr(Z1.y) + SmallLimit)*tmpf;
tmp2:=(ArcTan2(Z1.y,Z1.x)+(2*PI)*K)*tmpf;
tmpf:=Exp(tmp1);
sincos(tmp2,s,c);
result.x:=tmpf*C;
result.y:=tmpf*S;
end;
Procedure C_SqrtNV(var Z1: TComplex;const N:CmxFloat;const K:integer=0); {Z1:=Sqrt(Z1)}
var tmp1: CmxFloat;
tmp2: CmxFloat;
tmpf: CmxFloat;
tmpN: CmxFloat;
c,s : CmxFloat;
Begin
tmpN:=N;
if tmpN=0 then tmpN:=SmallLimit;
tmpN:=1/tmpN;
tmp1:=0.5*Ln(sqr(Z1.x)+sqr(Z1.y) + SmallLimit)*tmpN;
tmp2:=(ArcTan2(Z1.y,Z1.x)+(2*PI)*K)*tmpN;
tmpf:=Exp(tmp1);
sincos(tmp2,s,c);
Z1.x:=tmpf*C;
Z1.y:=tmpf*S;
end;
Procedure C_SqrtN (const Z1:TComplex;const N:integer;var Z:array of TComplex);overload;{Z(i):=Z1^(1/N)}
var tmp1: CmxFloat;
tmp2: CmxFloat;
tmpf: CmxFloat;
tmpN: CmxFloat;
tmpd: CmxFloat;
i : integer;
c,s : CmxFloat;
Begin
tmpN:=N;
if tmpN=0 then tmpN:=SmallLimit;
tmpN:=1.0/tmpN;
tmp1:=0.5*Ln(sqr(Z1.x)+sqr(Z1.y) + SmallLimit)*tmpN;
tmp2:=ArcTan2(Z1.y,Z1.x)*tmpN;
tmpd:=2*PI*tmpN;
tmpf:=Exp(tmp1);
for i:=0 to N-1 do
begin
tmp2:=tmp2+i*tmpd;
sincos(tmp2,s,c);
Z[i].x:=tmpf*C;
Z[i].y:=tmpf*S;
end;
end;
Function C_Exp (const Z1: TComplex): TComplex; {Z:=Exp(Z1)}
var tmp: CmxFloat;
c,s : CmxFloat;
Begin
tmp :=Exp(Z1.x);
sincos(Z1.y,s,c);
result.x:=tmp*C;
result.y:=tmp*S;
End;
Procedure C_ExpV (var Z1: TComplex); {Z1:=Exp(Z1)}
var tmp: CmxFloat;
c,s : CmxFloat;
Begin
tmp :=Exp(Z1.x);
sincos(Z1.y,s,c);
Z1.x:=tmp*C;
Z1.y:=tmp*S;
End;
Function C_Power (const xBase: CmxFloat;const Z1: TComplex): TComplex;{Z:=x^Z1}
var tmp1: CmxFloat;
tmp2: CmxFloat;
tmp3: CmxFloat;
c,s : CmxFloat;
Begin
tmp1:=Ln(xBase);
tmp2:=Exp(Z1.x*tmp1);
tmp3:=Z1.y*tmp1;
sincos(tmp3,s,c);
result.x:=tmp2*C;
result.y:=tmp2*S;
End;
Procedure C_PowerV(const xBase: CmxFloat;var Z1: TComplex);{Z1:=x^Z1}
var tmp1: CmxFloat;
tmp2: CmxFloat;
tmp3: CmxFloat;
c,s : CmxFloat;
Begin
tmp1:=Ln(xBase);
tmp2:=Exp(Z1.x*tmp1);
tmp3:=Z1.y*tmp1;
sincos(tmp3,s,c);
Z1.x:=tmp2*C;
Z1.y:=tmp2*S;
End;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -