Arithmetic/Complex: Difference between revisions
Arithmetic/Complex en BASIC - añadidas la conjugación compleja, resta y división
Drkameleon (talk | contribs) (Added Arturo implementation) |
(Arithmetic/Complex en BASIC - añadidas la conjugación compleja, resta y división) |
||
Line 284:
imag AS DOUBLE
END TYPE
DECLARE SUB
DECLARE SUB rest (a AS complex, b AS complex, c AS complex)
DECLARE SUB mult (a AS complex, b AS complex, c AS complex)
DECLARE SUB
DECLARE SUB neg (a AS complex, b AS complex)
DECLARE SUB inv (a AS complex, b AS complex)
DECLARE SUB conj (a AS complex, b AS complex)
CLS
DIM x AS complex
Line 296 ⟶ 301:
y.real = 2
y.imag = 2
CALL add(x, y, z)▼
PRINT
PRINT " e y = "; y.real; "+"; y.imag; "i"
PRINT
PRINT "x + y = "; z.real; "+"; z.imag; "i"
CALL rest(x, y, z)
PRINT "x - y = "; z.real; "+"; z.imag; "i"
CALL mult(x, y, z)
PRINT "x * y = "; z.real; "+"; z.imag; "i"
CALL
PRINT "x / y = "; z.real; "+"; z.imag; "i"
CALL neg(x, z)
PRINT " -x = "; z.real; "+"; z.imag; "i"
CALL inv(x, z)
PRINT "1 / x = "; z.real; "+"; z.imag; "i"
CALL conj(x, z)
PRINT " x* = "; z.real; "+"; z.imag; "i"
END
SUB
c.real = a.real + b.real
c.imag = a.imag + b.imag
Line 325 ⟶ 340:
b.real = -a.real
b.imag = -a.imag
END SUB
SUB conj (a AS complex, b AS complex)
b.real = a.real
b.imag = -a.imag
END SUB
SUB divi (a AS complex, b AS complex, c AS complex)
c.real = ((a.real * b.real + b.imag * a.imag) / (b.real ^ 2 + b.imag ^ 2))
c.imag = ((a.imag * b.real - a.real * b.imag) / (b.real ^ 2 + b.imag ^ 2))
END SUB
SUB rest (a AS complex, b AS complex, c AS complex)
c.real = a.real - b.real
c.imag = a.imag - b.imag
END SUB
</lang>
{{out}}
<pre>Siendo
e y = 5+ 2i
x + y = 6 + 5 i
-1 +-1 i</pre>▼
x - y = -4 + 1 i
x * y = -1 + 17 i
x / y = .3793103448275862 + .4482758620689655 i
-x = -1 +-3 i
1 / x = .1 +-.3 i
=={{header|BBC BASIC}}==
|