Data update
This commit is contained in:
parent
ed705008a8
commit
0df55f9f24
2196 changed files with 32999 additions and 3075 deletions
63
Task/Quaternion-type/Dart/quaternion-type.dart
Normal file
63
Task/Quaternion-type/Dart/quaternion-type.dart
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
import 'dart:math' as math;
|
||||
|
||||
class Quaternion {
|
||||
final double a, b, c, d;
|
||||
|
||||
Quaternion(this.a, this.b, this.c, this.d);
|
||||
|
||||
Quaternion operator +(Object other) {
|
||||
if (other is Quaternion) {
|
||||
return Quaternion(a + other.a, b + other.b, c + other.c, d + other.d);
|
||||
} else if (other is double) {
|
||||
return Quaternion(a + other, b, c, d);
|
||||
}
|
||||
throw ArgumentError('Invalid type for addition: ${other.runtimeType}');
|
||||
}
|
||||
|
||||
Quaternion operator *(Object other) {
|
||||
if (other is Quaternion) {
|
||||
return Quaternion(
|
||||
a * other.a - b * other.b - c * other.c - d * other.d,
|
||||
a * other.b + b * other.a + c * other.d - d * other.c,
|
||||
a * other.c - b * other.d + c * other.a + d * other.b,
|
||||
a * other.d + b * other.c - c * other.b + d * other.a,
|
||||
);
|
||||
} else if (other is double) {
|
||||
return Quaternion(a * other, b * other, c * other, d * other);
|
||||
}
|
||||
throw ArgumentError('Invalid type for multiplication: ${other.runtimeType}');
|
||||
}
|
||||
|
||||
Quaternion operator -() => Quaternion(-a, -b, -c, -d);
|
||||
|
||||
Quaternion conj() => Quaternion(a, -b, -c, -d);
|
||||
|
||||
double norm() => math.sqrt(a * a + b * b + c * c + d * d);
|
||||
|
||||
@override
|
||||
String toString() => '($a, $b, $c, $d)';
|
||||
}
|
||||
|
||||
void main() {
|
||||
var q = Quaternion(1.0, 2.0, 3.0, 4.0);
|
||||
var q1 = Quaternion(2.0, 3.0, 4.0, 5.0);
|
||||
var q2 = Quaternion(3.0, 4.0, 5.0, 6.0);
|
||||
var r = 7.0;
|
||||
print("q = $q");
|
||||
print("q1 = $q1");
|
||||
print("q2 = $q2");
|
||||
print("r = $r\n");
|
||||
print("norm(q) = ${q.norm().toStringAsFixed(6)}");
|
||||
print("-q = ${-q}");
|
||||
print("conj(q) = ${q.conj()}\n");
|
||||
print("r + q = ${q + r}");
|
||||
print("q + r = ${q + r}");
|
||||
print("q1 + q2 = ${q1 + q2}\n");
|
||||
print("r * q = ${q * r}");
|
||||
print("q * r = ${q * r}");
|
||||
var q3 = q1 * q2;
|
||||
var q4 = q2 * q1;
|
||||
print("q1 * q2 = $q3");
|
||||
print("q2 * q1 = $q4\n");
|
||||
print("q1 * q2 != q2 * q1 = ${q3 != q4}");
|
||||
}
|
||||
61
Task/Quaternion-type/EasyLang/quaternion-type.easy
Normal file
61
Task/Quaternion-type/EasyLang/quaternion-type.easy
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
func qnorm q[] .
|
||||
for i to 4
|
||||
s += q[i] * q[i]
|
||||
.
|
||||
return sqrt s
|
||||
.
|
||||
func[] qneg q[] .
|
||||
for i to 4
|
||||
q[i] = -q[i]
|
||||
.
|
||||
return q[]
|
||||
.
|
||||
func[] qconj q[] .
|
||||
for i = 2 to 4
|
||||
q[i] = -q[i]
|
||||
.
|
||||
return q[]
|
||||
.
|
||||
func[] qaddreal q[] r .
|
||||
q[1] += r
|
||||
return q[]
|
||||
.
|
||||
func[] qadd q[] q2[] .
|
||||
for i to 4
|
||||
q[i] += q2[i]
|
||||
.
|
||||
return q[]
|
||||
.
|
||||
func[] qmulreal q[] r .
|
||||
for i to 4
|
||||
q[i] *= r
|
||||
.
|
||||
return q[]
|
||||
.
|
||||
func[] qmul q1[] q2[] .
|
||||
res[] &= q1[1] * q2[1] - q1[2] * q2[2] - q1[3] * q2[3] - q1[4] * q2[4]
|
||||
res[] &= q1[1] * q2[2] + q1[2] * q2[1] + q1[3] * q2[4] - q1[4] * q2[3]
|
||||
res[] &= q1[1] * q2[3] - q1[2] * q2[4] + q1[3] * q2[1] + q1[4] * q2[2]
|
||||
res[] &= q1[1] * q2[4] + q1[2] * q2[3] - q1[3] * q2[2] + q1[4] * q2[1]
|
||||
return res[]
|
||||
.
|
||||
q[] = [ 1 2 3 4 ]
|
||||
q1[] = [ 2 3 4 5 ]
|
||||
q2[] = [ 3 4 5 6 ]
|
||||
r = 7
|
||||
#
|
||||
print "q = " & q[]
|
||||
print "q1 = " & q1[]
|
||||
print "q2 = " & q2[]
|
||||
print "r = " & r
|
||||
print "norm(q) = " & qnorm q[]
|
||||
print "neg(q) = " & qneg q[]
|
||||
print "conjugate(q) = " & qconj q[]
|
||||
print "q+r = " & qaddreal q[] r
|
||||
print "q1+q2 = " & qadd q1[] q2[]
|
||||
print "qr = " & qmulreal q[] r
|
||||
print "q1q2 = " & qmul q1[] q2[]
|
||||
print "q2q1 = " & qmul q2[] q1[]
|
||||
if q1[] <> q2[]
|
||||
print "q1 != q2"
|
||||
.
|
||||
Loading…
Add table
Add a link
Reference in a new issue