Data update
This commit is contained in:
parent
72eb4943cb
commit
4d5544505c
2347 changed files with 62432 additions and 16731 deletions
|
|
@ -1,27 +1,29 @@
|
|||
main:(
|
||||
FORMAT compl fmt = $g(-7,5)"⊥"g(-7,5)$;
|
||||
BEGIN
|
||||
|
||||
PROC compl operations = VOID: (
|
||||
LONG COMPL a = 1.0 ⊥ 1.0;
|
||||
LONG COMPL b = 3.14159 ⊥ 1.2;
|
||||
COMPL a = 1.0 I 1.0;
|
||||
COMPL b = 3.14159 I 1.2;
|
||||
|
||||
LONG COMPL c;
|
||||
COMPL c;
|
||||
|
||||
printf(($x"a="f(compl fmt)l$,a));
|
||||
printf(($x"b="f(compl fmt)l$,b));
|
||||
PROC show compl = ( STRING legend, COMPL v )VOID:
|
||||
print( ( legend, fixed( re OF v, -8, 5 ), " I ", fixed( im OF v, -8, 5 ), newline ) );
|
||||
|
||||
show compl(" a=",a);
|
||||
show compl(" b=",b);
|
||||
|
||||
# addition #
|
||||
c := a + b;
|
||||
printf(($x"a+b="f(compl fmt)l$,c));
|
||||
show compl("a+b=",c);
|
||||
# multiplication #
|
||||
c := a * b;
|
||||
printf(($x"a*b="f(compl fmt)l$,c));
|
||||
show compl("a*b=",c);
|
||||
# inversion #
|
||||
c := 1.0 / a;
|
||||
printf(($x"1/c="f(compl fmt)l$,c));
|
||||
show compl("1/c=",c);
|
||||
# negation #
|
||||
c := -a;
|
||||
printf(($x"-a="f(compl fmt)l$,c))
|
||||
show compl(" -a=",c)
|
||||
);
|
||||
compl operations
|
||||
)
|
||||
END
|
||||
|
|
|
|||
|
|
@ -0,0 +1,67 @@
|
|||
import ballerina/io;
|
||||
|
||||
class Complex {
|
||||
float re;
|
||||
float im;
|
||||
|
||||
function init(float re, float im) {
|
||||
self.re = re;
|
||||
self.im = im;
|
||||
}
|
||||
|
||||
function neg() returns Complex {
|
||||
return new Complex(-self.re, -self.im);
|
||||
}
|
||||
|
||||
function inv() returns Complex {
|
||||
float denom = self.re * self.re + self.im * self.im;
|
||||
return new Complex(self.re / denom, -self.im / denom);
|
||||
}
|
||||
|
||||
function add(Complex other) returns Complex {
|
||||
return new Complex(self.re + other.re, self.im + other.im);
|
||||
}
|
||||
|
||||
function sub(Complex other) returns Complex {
|
||||
return self.add(other.neg());
|
||||
}
|
||||
|
||||
function mul(Complex other) returns Complex {
|
||||
return new Complex(
|
||||
self.re * other.re - self.im * other.im,
|
||||
self.re * other.im + self.im * other.re
|
||||
);
|
||||
}
|
||||
|
||||
function div(Complex other) returns Complex {
|
||||
return self.mul(other.inv());
|
||||
}
|
||||
|
||||
function conj() returns Complex {
|
||||
return new Complex(self.re, -self.im);
|
||||
}
|
||||
|
||||
function toString() returns string {
|
||||
if self.re === -0.0 { self.re = 0.0; }
|
||||
if self.im === -0.0 { self.im = 0.0; }
|
||||
if self.im >= 0.0 {
|
||||
return string `${self.re} + ${self.im}i`;
|
||||
} else {
|
||||
return string `${self.re} - ${-self.im}i`;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function main() {
|
||||
var x = new Complex(1, 3);
|
||||
var y = new Complex(5, 2);
|
||||
io:println("x = ", x);
|
||||
io:println("y = ", y);
|
||||
io:println("x + y = ", x.add(y));
|
||||
io:println("x - y = ", x.sub(y));
|
||||
io:println("x * y = ", x.mul(y));
|
||||
io:println("x / y = ", x.div(y));
|
||||
io:println("-x = ", x.neg());
|
||||
io:println("1 / x = ", x.inv());
|
||||
io:println("x* = ", x.conj());
|
||||
}
|
||||
15
Task/Arithmetic-Complex/Crystal/arithmetic-complex.cr
Normal file
15
Task/Arithmetic-Complex/Crystal/arithmetic-complex.cr
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
require "complex"
|
||||
|
||||
a = Complex.new(1, 2)
|
||||
b = 3 + 4.i
|
||||
|
||||
puts "a = #{a}, b = #{b}"
|
||||
puts
|
||||
puts "a + b = #{a + b}"
|
||||
puts "a - b = #{a - b}"
|
||||
puts "a * b = #{a * b}"
|
||||
puts "a / b = #{a / b}"
|
||||
puts
|
||||
puts "-a = #{-a}"
|
||||
puts "1/a = #{a.inv}"
|
||||
puts "ā = #{a.conj}"
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
module tstComplex {
|
||||
// Var one as complex=(1,0i), A as complex=(8, -3i)
|
||||
one=(1,0i)
|
||||
A=(8, -3i)
|
||||
Print "A=";A
|
||||
Print " r=";Abs(A);" θ=";Arg(A);" rad"
|
||||
B=one/A
|
||||
Print "B=";B
|
||||
Print " r=";Abs(B);" θ=";Arg(B);" rad"
|
||||
Print A;"*";B;"=";A*B
|
||||
Print one;"/";B;"=";one/B
|
||||
Print A;"/";A;"=";A/A
|
||||
Print A;"+";A;"=";A+A
|
||||
Print A;"-";A;"=";A-A
|
||||
Print "-"+A+"=";-A
|
||||
Print "(round exp to 13th decimal)"
|
||||
I=round(exp((0, pi i)),13)+1
|
||||
Print "e^(πi)+1=";i
|
||||
Print "(without rounding)"
|
||||
I=exp((0, pi i))+1
|
||||
Print "e^(πi)+1=";i
|
||||
Print type$(i) = "Complex"
|
||||
Dim a(10) as Complex=(1,0i)
|
||||
Print (a(3)+a(3))^2=(4, 0i)
|
||||
Print (a(3)+a(3))^2=4
|
||||
|
||||
Print cos(a)
|
||||
Print sin(a)
|
||||
Print atn(tan(a))
|
||||
Print tan(atn(a))
|
||||
Print Polar(abs(a), arg(a))=(8, -3i)
|
||||
Print str$(a ,"0.00")
|
||||
Print str$((8,-3i) ,"0.00")
|
||||
}
|
||||
tstComplex
|
||||
|
|
@ -1,38 +1,53 @@
|
|||
-- 19 May 2025
|
||||
include Settings
|
||||
|
||||
say version; say 'Arithmetic numbers'; say
|
||||
numeric digits 9
|
||||
divi. = 0; a = 0; c = 0
|
||||
do i = 1
|
||||
/* Is the number arithmetic? */
|
||||
if Arithmetic(i) then do
|
||||
a = a+1
|
||||
/* Is the number composite? */
|
||||
if divi.0 > 2 then
|
||||
c = c+1
|
||||
/* Output control */
|
||||
if a <= 100 then do
|
||||
if a = 1 then
|
||||
say 'First 100 arithmetic numbers are'
|
||||
call Charout ,Right(i,4)
|
||||
if a//10 = 0 then
|
||||
say
|
||||
if a = 100 then
|
||||
say
|
||||
end
|
||||
if a = 100 | a = 1000 | a = 10000 | a = 100000 | a = 1000000 then do
|
||||
say 'The' a'th arithmetic number is' i
|
||||
say 'Of the first' a 'numbers' c 'are composite'
|
||||
say
|
||||
end
|
||||
/* Max 1m, higher takes too long */
|
||||
if a = 1000000 then
|
||||
leave
|
||||
end
|
||||
end
|
||||
say Format(Time('e'),,3) 'seconds'
|
||||
say 'COMPLEX ARITHMETIC'
|
||||
say version
|
||||
say
|
||||
a = '1 2'; b = '3 4'; c = '5 6'; d = '7 8'; i = I()
|
||||
say 'VALUES'
|
||||
say 'a =' crec2form(a)
|
||||
say 'b =' crec2form(b)
|
||||
say 'c =' crec2form(c)
|
||||
say 'd =' crec2form(d)
|
||||
say
|
||||
say 'BASICS'
|
||||
say 'i*i =' crec2form(Csquare(i()))
|
||||
say 'a+b =' crec2form(Cadd(a,b))
|
||||
say 'a-b =' crec2form(Csub(a,b))
|
||||
say 'a*b =' crec2form(Cmul(a,b))
|
||||
say 'a/b =' crec2form(Cdiv(a,b))
|
||||
say 'a^2 =' crec2form(Csquare(a,2))
|
||||
say 'a^5 =' crec2form(Cpow(a,5))
|
||||
say '-a =' crec2form(Cneg(a))
|
||||
say '1/a =' crec2form(Cinv(a))
|
||||
say 'a+b+c+d =' crec2form(Cadd(a,b,c,d))
|
||||
say 'a-b-c-d =' crec2form(Csub(a,b,c,d))
|
||||
say 'a*b*c*d =' crec2form(Cmul(a,b,c,d))
|
||||
say 'a/b/c/d =' crec2form(Cnormal(Cdiv(a,b,c,d)))
|
||||
say
|
||||
say 'FORMULA'
|
||||
say 'a^2-2ab+3c-4ad^4+5 =' ,
|
||||
crec2form(Cadd(Csquare(a),Cmul(-2,a,b),Cmul(3,c),Cmul(-4,a,Cpower(d,4)),5))
|
||||
say
|
||||
say 'BONUS'
|
||||
say 'Argument(a) =' Carg(a)+0
|
||||
say 'Conjugate(a) =' crec2form(Cconj(a))
|
||||
say 'Imag(a) =' Cim(a)
|
||||
say 'Modulus(a) =' Cmod(a)+0
|
||||
say 'Polar(a) =' Cpol2form(Cnormal(Crec2pol(a)))
|
||||
say 'Real(a) =' Cre(a)
|
||||
say
|
||||
say 'MORE'
|
||||
say 'Arcsin(a) =' crec2form(Cnormal(Carcsin(a)))
|
||||
say 'Exp(a) =' crec2form(Cnormal(Cexp(a)))
|
||||
say 'Ln(a) =' crec2form(Cnormal(Cln(a)))
|
||||
say 'Sin(a) =' crec2form(Cnormal(Csin(a)))
|
||||
say 'Sqrt(a) =' crec2form(Cnormal(Csqrt(a)))
|
||||
say 'i^i =' crec2form(Cnormal(Cpower(i,i)))
|
||||
exit
|
||||
|
||||
include Numbers
|
||||
include Complex
|
||||
include Functions
|
||||
include Constants
|
||||
include Abend
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue