Arithmetic/Complex: Difference between revisions
Content added Content deleted
Drkameleon (talk | contribs) (Added Arturo implementation) |
(Arithmetic/Complex en BASIC - añadidas la conjugación compleja, resta y división) |
||
Line 284: | Line 284: | ||
imag AS DOUBLE |
imag AS DOUBLE |
||
END TYPE |
END TYPE |
||
DECLARE SUB |
DECLARE SUB suma (a AS complex, b AS complex, c AS complex) |
||
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 mult (a AS complex, b AS complex, c AS complex) |
||
DECLARE SUB |
DECLARE SUB divi (a AS complex, b AS complex, c AS complex) |
||
DECLARE SUB neg (a AS complex, b AS complex) |
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 |
CLS |
||
DIM x AS complex |
DIM x AS complex |
||
Line 296: | Line 301: | ||
y.real = 2 |
y.real = 2 |
||
y.imag = 2 |
y.imag = 2 |
||
⚫ | |||
PRINT |
PRINT "Siendo x = "; x.real; "+"; x.imag; "i" |
||
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) |
CALL mult(x, y, z) |
||
PRINT z.real; "+"; z.imag; "i" |
PRINT "x * y = "; z.real; "+"; z.imag; "i" |
||
CALL |
CALL divi(x, y, z) |
||
PRINT z.real; "+"; z.imag; "i" |
PRINT "x / y = "; z.real; "+"; z.imag; "i" |
||
CALL neg(x, z) |
CALL neg(x, z) |
||
PRINT z.real; "+"; z.imag; "i" |
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 |
SUB suma (a AS complex, b AS complex, c AS complex) |
||
c.real = a.real + b.real |
c.real = a.real + b.real |
||
c.imag = a.imag + b.imag |
c.imag = a.imag + b.imag |
||
Line 325: | Line 340: | ||
b.real = -a.real |
b.real = -a.real |
||
b.imag = -a.imag |
b.imag = -a.imag |
||
END SUB |
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}} |
{{out}} |
||
<pre> |
<pre>Siendo x = 1+ 3i |
||
e y = 5+ 2i |
|||
0 + 4 i |
|||
.5 +-.5 i |
|||
x + y = 6 + 5 i |
|||
⚫ | |||
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}}== |
=={{header|BBC BASIC}}== |