| |
|
|
p.specht
| here one attempt of/ one objektorientierten Version to that anticipate complex numbers as Class CPLX. it are missing yet Wurzelfunktion and some Hilfsfunktionen, z.B. Koordinatensystem-Transformationen.
Window Title "Eine Class for complex Zahlenarithmetik"
' (CL) CopyLeft 2013-04 ff by P.woodpecker(at)GMX.at
' Jegliche Liability is particularly impossible! Betaversion to Kurztest.
' The usage results on Own menace the Anwenders/the Anwenderin!
Cls : Font 2
'{ Class cplx, Beta-Version 14.04.2013-06:00
Class cplx=re!,in the!,inp@,prt@,prtln@, add@,sub@,mul@,konj@,div@, polar@,vect@,pprt@,pprtln@
' .re!: Realteil, .in the!: Imaginärteil the jeweilgen Komplexen_Zahl#
' .inp(): Manuelle Einzelwerteingabe with Input
' <var#>.prt(PromptText$): spending of var#, .prtln("Test:"): spending + newline
' <var#>.add(a#,b#), .sub(a#,b#), .mul(a#,b#), .konj(a#), .div(a#,b#): Zeigerarithmetik
'
' p#.polar(a#): Wandelt complex Coordinates in Versor(=Polar-)statement [length+Winkelgrade],
' a#.vect(p#): Wandelt Polardarstellung [length+Winkelgrade] To complex Coordinates .re+j*.in the
' p#.pprt(Text$): polarprint, p#.pprtln(Text$): polarprint + newline
'
proc cplx.inp
declare re!,in the!
print "Re=";:input re!
locate %csrlin-1,%pos+20
print "Im=";:input in the!
.re!=re! : .in the!=in the!
endproc
proc cplx.cplx' for declare x#:x#=new(cplx)
declare re!,in the!
print "re=";:input re!
locate %csrlin-1,%pos+20
print "im=";:input in the!
.re!=re! : .in the!=in the!
endproc
proc cplx.prt
if %pcount=1:parameters t$:print t$,:endif
print stature$("%g",.re!);@IF(.in the!<0,"-j*"+\
stature$("%g",-1*.in the!),"+j*"+stature$("%g",.in the!)),
endproc
proc cplx.prtln
if %pcount=1:parameters t$:print t$,:endif
print stature$("%g",.re!);@If(.in the!<0,"-j*"+\
stature$("%g",-1*.in the!),"+j*"+stature$("%g",.in the!))
endproc
proc cplx.add :parameters a#,b#
.re! = a#.re! + b#.re!
.in the! = a#.in the! + b#.in the!
endproc
proc cplx.sub :parameters a#,b#
.re! = a#.re! - b#.re!
.in the! = a#.in the! - b#.in the!
endproc
proc cplx.mul :parameters a#,b#
.re! = a#.re! * b#.re! - a#.in the! * b#.in the!
.in the! = a#.re! * b#.in the! + a#.in the! * b#.re!
endproc
proc cplx.konj :parameters a#
.re! = a#.re!
.in the! = -1*a#.in the!
endproc
proc cplx.div :parameters a#,b#
var nenn!=sqr(b#.re!)+sqr(b#.in the!)
.re! = a#.re!*b#.re! + a#.in the!*b#.in the!
.in the! = a#.in the!*b#.re! - a#.re!*b#.in the!
if nenn!<>0
.re! = .re!/nenn!
.in the! = .in the!/nenn!
else
if .re!<>0
.re! = 10^200
.in the! = 180/pi()*arctan(.in the!/.re!)
else
.re!=10^200
.in the!=90
endif
endif
endproc
proc cplx.pprt
if %pcount=1:parameters t$:print t$,:endif
print stature$("%g",.re!);"_in_";stature$("%g",.in the!);"_rad",
endproc
proc cplx.pprtln
if %pcount=1:parameters t$:print t$,:endif
print stature$("%g",.re!);"_in_";stature$("%g",.in the!);"_rad"
endproc
proc cplx.polar:parameters a#
set("decimals",12)
.re!=sqrt(sqr(a#.re!)+sqr(a#.in the!))
var pi!=3.1415926535897932384626433832795028842
var prec&=lg(.re!)
var Winkel!=0
if Nearly(a#.re!,0,15-prec&) and Nearly(0,a#.in the!,15-prec&):winkel!=0
elseif (a#.re!>0) and Nearly(0,a#.in the!,15-prec&):winkel!=0' 10^-38
elseif (a#.re!>0) and (a#.in the!>0) and Nearly(a#.re!,a#.in the!,14-prec&):winkel!=pi!*0.25
elseif Nearly(a#.re!,0,15-prec&) and (a#.in the!>0):winkel!=pi!*0.5
elseif (a#.re!<0) and (a#.in the!>0) and Nearly(-a#.re!,a#.in the!,14-prec&):winkel!=pi!*0.75
elseif (a#.re!<0) and Nearly(0,a#.in the!,15-prec&):winkel!=pi!
elseif (a#.re!<0) and (a#.in the!<0) and Nearly(-a#.re!,-a#.in the!,14-prec&):winkel!=pi!*1.25
elseif Nearly(a#.re!,0,15-prec&) and (a#.in the!<0):winkel!=pi!*1.5
elseif (a#.re!>0) and (a#.in the!<0) and Nearly(a#.re!,-a#.in the!,14-prec&):winkel!=pi!*1.75
elseif (a#.re!>0) and (a#.in the!>0) and (a#.re!>a#.in the!):winkel!=arctan(a#.in the!/a#.re!)
elseif (a#.re!>0) and (a#.in the!>0) and (a#.re!<a#.in the!):winkel!=pi!/2-arctan(a#.re!/a#.in the!)
elseif (a#.re!<0) and (a#.in the!>0) and (-a#.re!<a#.in the!):winkel!=pi!/2+arctan(-a#.re!/a#.in the!)
elseif (a#.re!<0) and (a#.in the!>0) and (-a#.re!>a#.in the!):winkel!=pi!-arctan(a#.in the!/-a#.re!)
elseif (a#.re!<0) and (a#.in the!<0) and (a#.re!<a#.in the!):winkel!=pi!+arctan(-a#.in the!/-a#.re!)
elseif (a#.re!<0) and (a#.in the!<0) and (a#.re!>a#.in the!):winkel!=pi!*1.5-arctan(-a#.re!/-a#.in the!)
elseif (a#.re!>0) and (a#.in the!<0) and (a#.re!< -a#.in the!):winkel!=pi!*1.5+arctan(a#.re!/-a#.in the!)
elseif (a#.re!>0) and (a#.in the!<0) and (a#.re!> -a#.in the!):winkel!=2*pi!-arctan(-a#.in the!/a#.re!)
endif
.in the!=Winkel!
endproc
proc cplx.vect :parameters c#
.re!=c#.re!*cos(c#.in the!)
.in the!=c#.re!*sin(c#.in the!)
endproc
' }
' HAUPTTEIL:
declare u#:dim u#,cplx
declare v#:dim v#,cplx
declare w#:dim w#,cplx
u#.inp() :u#.prtln("u:")
v#.inp() :v#.prtln("v:")
w#.add(u#,v#):w#.prt("add:")
w#.sub(u#,v#):w#.prtln("sub:")
w#.mul(u#,v#):w#.prt("mul:")
w#.konj(u#) :w#.prtln("konj:")
w#.div(u#,v#)
print w#.re!
print w#.in the!
w#.prtln("div:")
w#.polar(u#) :w#.pprtln("polar:")
u#.vect(w#) :u#.prtln("vect:")
waitinput
dispose u#,v#,w#
|
|
|
| XProfan 11Computer: Gerät, daß es in Mikrosekunden erlaubt, 50.000 Fehler zu machen, zB 'daß' statt 'das'... | 05/09/21 ▲ |
|
|
|