How to resolve the algorithm Quaternion type step by step in the Arturo programming language
How to resolve the algorithm Quaternion type step by step in the Arturo programming language
Table of Contents
Problem Statement
Quaternions are an extension of the idea of complex numbers.
A complex number has a real and complex part, sometimes written as a + bi,
where a and b stand for real numbers, and i stands for the square root of minus 1.
An example of a complex number might be -3 + 2i,
where the real part, a is -3.0 and the complex part, b is +2.0.
A quaternion has one real part and three imaginary parts, i, j, and k.
A quaternion might be written as a + bi + cj + dk.
In the quaternion numbering system:
The order of multiplication is important, as, in general, for two quaternions:
An example of a quaternion might be 1 +2i +3j +4k
There is a list form of notation where just the numbers are shown and the imaginary multipliers i, j, and k are assumed by position.
So the example above would be written as (1, 2, 3, 4)
Given the three quaternions and their components: And a wholly real number r = 7.
Create functions (or classes) to perform simple maths with quaternions including computing:
If a language has built-in support for quaternions, then use it.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Quaternion type step by step in the Arturo programming language
Source code in the arturo programming language
qnorm: $ => [sqrt fold & [x y] -> x + y*y]
qneg: $ => [map & => neg]
qconj: $[q] [@[q\0] ++ qneg drop q]
qaddr: function [q r][
[a b c d]: q
@[a+r b c d]
]
qadd: $ => [map couple & & => sum]
qmulr: $[q r] [map q'x -> x*r]
qmul: function [q1 q2][
[a1 b1 c1 d1]: q1
[a2 b2 c2 d2]: q2
@[
(((a1*a2) - b1*b2) - c1*c2) - d1*d2,
(((a1*b2) + b1*a2) + c1*d2) - d1*c2,
(((a1*c2) - b1*d2) + c1*a2) + d1*b2,
(((a1*d2) + b1*c2) - c1*b2) + d1*a2
]
]
; --- test quaternions ---
q: [1 2 3 4]
q1: [2 3 4 5]
q2: [3 4 5 6]
r: 7
print ['qnorm q '= qnorm q]
print ['qneg q '= qneg q]
print ['qconj q '= qconj q]
print ['qaddr q r '= qaddr q r]
print ['qmulr q r '= qmulr q r]
print ['qadd q1 q2 '= qadd q1 q2]
print ['qmul q1 q2 '= qmul q1 q2]
print ['qmul q2 q1 '= qmul q2 q1]
You may also check:How to resolve the algorithm FizzBuzz step by step in the NATURAL programming language
You may also check:How to resolve the algorithm Digital root step by step in the BBC BASIC programming language
You may also check:How to resolve the algorithm Collections step by step in the D programming language
You may also check:How to resolve the algorithm Permutations step by step in the VBA programming language
You may also check:How to resolve the algorithm Stack step by step in the Elixir programming language