133 lines
1.7 KiB
Plaintext
133 lines
1.7 KiB
Plaintext
'COMPLEX OPERATIONS
|
|
'=================
|
|
|
|
type tcomplex double x,y
|
|
|
|
class Complex
|
|
'============
|
|
|
|
has tcomplex
|
|
static sys i,pp
|
|
static tcomplex accum[32]
|
|
|
|
def operands
|
|
tcomplex*a,*b
|
|
@a=@accum+i
|
|
if pp then
|
|
@b=@a+sizeof accum
|
|
pp=0
|
|
else
|
|
@b=@this
|
|
end if
|
|
end def
|
|
|
|
method "load"()
|
|
operands
|
|
a.x=b.x
|
|
a.y=b.y
|
|
end method
|
|
|
|
method "push"()
|
|
i+=sizeof accum
|
|
end method
|
|
|
|
method "pop"()
|
|
pp=1
|
|
i-=sizeof accum
|
|
end method
|
|
|
|
method "="()
|
|
operands
|
|
b.x=a.x
|
|
b.y=a.y
|
|
end method
|
|
|
|
method "+"()
|
|
operands
|
|
a.x+=b.x
|
|
a.y+=b.y
|
|
end method
|
|
|
|
method "-"()
|
|
operands
|
|
a.x-=b.x
|
|
a.y-=b.y
|
|
end method
|
|
|
|
method "*"()
|
|
operands
|
|
double d
|
|
d=a.x
|
|
a.x = a.x * b.x - a.y * b.y
|
|
a.y = a.y * b.x + d * b.y
|
|
end method
|
|
|
|
method "/"()
|
|
operands
|
|
double d,v
|
|
v=1/(b.x * b.x + b.y * b.y)
|
|
d=a.x
|
|
a.x = (a.x * b.x + a.y * b.y) * v
|
|
a.y = (a.y * b.x - d * b.y) * v
|
|
end method
|
|
|
|
method power(double n)
|
|
operands
|
|
'Using DeMoivre theorem
|
|
double r,an,mg
|
|
r = hypot(b.x,b.y)
|
|
mg = r^n
|
|
if b.x=0 then
|
|
ay=.5*pi
|
|
if b.y<0 then ay=-ay
|
|
else
|
|
an = atan(b.y,b.x)
|
|
end if
|
|
an *= n
|
|
a.x = mg * cos(an)
|
|
a.y = mg * sin(an)
|
|
end method
|
|
|
|
method show() as string
|
|
return str(x,14) ", " str(y,14)
|
|
end method
|
|
|
|
end class
|
|
|
|
'#recordof complexop
|
|
|
|
'====
|
|
'TEST
|
|
'====
|
|
|
|
complex z1,z2,z3,z4,z5
|
|
|
|
'ENTER VALUES
|
|
|
|
z1 <= 0, 0
|
|
z2 <= 2, 1
|
|
z3 <= -2, 1
|
|
z4 <= 2, 4
|
|
z5 <= 1, 1
|
|
|
|
'EVALUATE COMPLEX EXPRESSIONS
|
|
|
|
z1 = z2 * z3
|
|
print "Z1 = "+z1.show 'RESULT -5.0, 0
|
|
|
|
z1 = z3+(z2.power(2))
|
|
print "Z1 = "+z1.show 'RESULT 1.0, 5.0
|
|
|
|
|
|
z1 = z5/z4
|
|
print "Z1 = "+z1.show 'RESULT 0.3, 0.1
|
|
|
|
z1 = z5/z1
|
|
print "Z1 = "+z1.show 'RESULT 2.0, 4.0
|
|
|
|
z1 = z2/z4
|
|
print "Z1 = "+z1.show 'RESULT -0.4, -0.3
|
|
|
|
z1 = z1*z4
|
|
print "Z1 = "+z1.show 'RESULT 2.0, 1.0
|