Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
54
Task/Quaternion-type/Phix/quaternion-type.phix
Normal file
54
Task/Quaternion-type/Phix/quaternion-type.phix
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
function norm(sequence q)
|
||||
return sqrt(sum(sq_power(q,2)))
|
||||
end function
|
||||
|
||||
function conj(sequence q)
|
||||
q[2..4] = sq_uminus(q[2..4])
|
||||
return q
|
||||
end function
|
||||
|
||||
function add(object q1, object q2)
|
||||
if atom(q1)!=atom(q2) then
|
||||
if atom(q1) then
|
||||
q1 = {q1,0,0,0}
|
||||
else
|
||||
q2 = {q2,0,0,0}
|
||||
end if
|
||||
end if
|
||||
return sq_add(q1,q2)
|
||||
end function
|
||||
|
||||
function mul(object q1, object q2)
|
||||
if sequence(q1) and sequence(q2) then
|
||||
return { q1[1]*q2[1] - q1[2]*q2[2] - q1[3]*q2[3] - q1[4]*q2[4],
|
||||
q1[1]*q2[2] + q1[2]*q2[1] + q1[3]*q2[4] - q1[4]*q2[3],
|
||||
q1[1]*q2[3] - q1[2]*q2[4] + q1[3]*q2[1] + q1[4]*q2[2],
|
||||
q1[1]*q2[4] + q1[2]*q2[3] - q1[3]*q2[2] + q1[4]*q2[1] }
|
||||
else
|
||||
return sq_mul(q1,q2)
|
||||
end if
|
||||
end function
|
||||
|
||||
function quats(sequence q)
|
||||
return sprintf("%g + %gi + %gj + %gk",q)
|
||||
end function
|
||||
|
||||
constant
|
||||
q = {1, 2, 3, 4},
|
||||
q1 = {2, 3, 4, 5},
|
||||
q2 = {3, 4, 5, 6},
|
||||
r = 7
|
||||
|
||||
printf(1, "q = %s\n", {quats(q)})
|
||||
printf(1, "r = %g\n", r)
|
||||
printf(1, "norm(q) = %g\n", norm(q))
|
||||
printf(1, "-q = %s\n", {quats(-q)})
|
||||
printf(1, "conj(q) = %s\n", {quats(conj(q))})
|
||||
printf(1, "q + r = %s\n", {quats(add(q,r))})
|
||||
printf(1, "q * r = %s\n", {quats(mul(q,r))})
|
||||
printf(1, "q1 = %s\n", {quats(q1)})
|
||||
printf(1, "q2 = %s\n", {quats(q2)})
|
||||
printf(1, "q1 + q2 = %s\n", {quats(add(q1,q2))})
|
||||
printf(1, "q2 + q1 = %s\n", {quats(add(q2,q1))})
|
||||
printf(1, "q1 * q2 = %s\n", {quats(mul(q1,q2))})
|
||||
printf(1, "q2 * q1 = %s\n", {quats(mul(q2,q1))})
|
||||
Loading…
Add table
Add a link
Reference in a new issue