Application Center - Maplesoft

App Preview:

Quaternions

You can switch back to the summary page by clicking here.

Learn about Maple
Download Application


 

Image 

Overview on Hamilton Quaternions 

 

A Hamilton Quaternion is a hypercomplex number with one real part (the scalar) and three imaginary parts (the vector).  

 

This is an extension of the concept of numbers.  We have found that a real number is a one-part number that can be represented on a number line and a complex number is a two-part number that can be represented on a plane.  Extending that logic, we have also found that we can produce more numbers by adding more parts.     
Quaternion --> a + b*i + c*j + d*k, where the coefficients a, b, c, d are elements of the reals
 


The hypercomplex number-quaternion-is a non-commutative division ring.  This is what we call a four-dimensional number.  Here is an example of a quaternion:  5 + 2i + 3j + 4k.  The first term is called the scalar term; it is simply a real number.  The other terms consisting of, i, j, k. are called the imaginary terms. As a group, they are called the vector of the quaternion.  Vector algebra uses the same name vector as the quaternion number, but with a different meaning.  Although vector algebra is an offspring of quaternions, vectors are not numbers.  Starting with complex numbers, we lost the permanence of trichotomy.  The permanencies we lose with quaternion numbers are the trichotomy property and the commutative property under multiplication. In addition, the imaginary units are anti-commutative under multiplication.  Anti-commutative means the sign of the imaginary unit changes when we transpose the two operands under multiplication, e.g., i*j = -(j*i).  The imaginary elements, i, j, and k, give cyclic permutations with each other (see Behaviors of Quaternions).
  
If we set the coefficients of the imaginary elements j and k to zero, the quaternion number becomes an ordinary complex number.  We can deduce all of the other algebraic numbers and/or the transcendental numbers from the quaternions simply by setting all the coefficients of the imaginary elements to zero. 

Behaviors of Quaternions  

> with(Quaternions);
 

Warning, u, i, j, & k are protected for quaternion package
 

Warning, these protected names have been redefined and unprotected: `*`, `+`, `-`, `^`, eval, print, unprotect 

[`*`, `+`, `-`, Qabs, Qadd, Qamplitude, Qangle, Qarccos, Qarccosh, Qarccot, Qarccoth, Qarccsc, Qarccsch, Qarcsec, Qarcsech, Qarcsin, Qarcsinh, Qarctan, Qarctanh, Qargument, Qaxial, Qceil, Qcolatitude,...
[`*`, `+`, `-`, Qabs, Qadd, Qamplitude, Qangle, Qarccos, Qarccosh, Qarccot, Qarccoth, Qarccsc, Qarccsch, Qarcsec, Qarcsech, Qarcsin, Qarcsinh, Qarctan, Qarctanh, Qargument, Qaxial, Qceil, Qcolatitude,...
[`*`, `+`, `-`, Qabs, Qadd, Qamplitude, Qangle, Qarccos, Qarccosh, Qarccot, Qarccoth, Qarccsc, Qarccsch, Qarcsec, Qarcsech, Qarcsin, Qarcsinh, Qarctan, Qarctanh, Qargument, Qaxial, Qceil, Qcolatitude,...
[`*`, `+`, `-`, Qabs, Qadd, Qamplitude, Qangle, Qarccos, Qarccosh, Qarccot, Qarccoth, Qarccsc, Qarccsch, Qarcsec, Qarcsech, Qarcsin, Qarcsinh, Qarctan, Qarctanh, Qargument, Qaxial, Qceil, Qcolatitude,...
[`*`, `+`, `-`, Qabs, Qadd, Qamplitude, Qangle, Qarccos, Qarccosh, Qarccot, Qarccoth, Qarccsc, Qarccsch, Qarcsec, Qarcsech, Qarcsin, Qarcsinh, Qarctan, Qarctanh, Qargument, Qaxial, Qceil, Qcolatitude,...
[`*`, `+`, `-`, Qabs, Qadd, Qamplitude, Qangle, Qarccos, Qarccosh, Qarccot, Qarccoth, Qarccsc, Qarccsch, Qarcsec, Qarcsech, Qarcsin, Qarcsinh, Qarctan, Qarctanh, Qargument, Qaxial, Qceil, Qcolatitude,...
[`*`, `+`, `-`, Qabs, Qadd, Qamplitude, Qangle, Qarccos, Qarccosh, Qarccot, Qarccoth, Qarccsc, Qarccsch, Qarcsec, Qarcsech, Qarcsin, Qarcsinh, Qarctan, Qarctanh, Qargument, Qaxial, Qceil, Qcolatitude,...
 

> q := Qrand(-10,10);        # Typical quaternion
 

q := -4+7*i+8*j+10*k
 

> i*i; j*j; k*k;
 

-1
 

-1
 

-1
 

> i*j;
 

k
 

> j*k;
 

i
 

> j*i;
 

-k
 

> i*j*k;
 

-1
 

> q1 := Qrand(-10,10); q2 := Qrand(-20,20);
 

q1 := -6-8*i-5*j+7*k
 

q2 := -14-12*i-19*j-17*k
 

> q1*q2; # quaternion are usually not commutative
 

12+402*i-36*j+96*k
 

> q2*q1; #see the different
 

12-34*i+404*j-88*k
 

> q1 + q2; q2 + q1;
 

-20-20*i-24*j-10*k
 

-20-20*i-24*j-10*k
 

> q1; Qconjugate(q1);
 

-6-8*i-5*j+7*k
 

-6+8*i+5*j-7*k
 

> q * Qinverse(q);
 

1
 

> Qinverse(q) * q;
 

1
 

> i^0; j^0; k^0;
 

1. 

1.
 

1.
 

> i^1; j^1; k^1;
 

i
 

j
 

k
 

> i^2; j^2; k^2;
 

-1. 

-1. 

-1.
 

> i^3; j^3; k^3;
 

-1.*i 

-1.*j 

-1.*k
 

> Qround(%); Qround(%%); Qround(%%%);
 

-k
 

-k
 

-k
 

> i^4;
 

1.
 

> i*j*k; k*j*i;
 

-1
 

1
 

> q := Qdefine(1,2,3,4);
 

q := 1+2*i+3*j+4*k
 

> q^0;
 

1.
 

> q^1;
 

1+2*i+3*j+4*k
 

> q^2;
 

-28.+4.*i+6.*j+8.*k
 

> q^3;
 

-86.-52.*i-78.*j-104.*k
 

> q^4;
 

668.-224.*i-336.*j-448.*k
 

> q := Qdefine(1,2,3,4);
 

q := 1+2*i+3*j+4*k
 

> QtoMatrix(q);
 

Typesetting:-mrow(Typesetting:-mfenced(Typesetting:-mrow(Typesetting:-mtable(Typesetting:-mtr(Typesetting:-mtd(Typesetting:-mn(
 

> QtoMatrices(q);
 

Typesetting:-mrow(Typesetting:-mrow(Typesetting:-mfenced(Typesetting:-mrow(Typesetting:-mtable(Typesetting:-mtr(Typesetting:-mtd(Typesetting:-mn(
 

> Qscalar(q);
 

1
 

> Qvector(q);
 

2*i+3*j+4*k
 

> QisPure(q);
 

false
 

> QisPure(Qvector(q));
 

true
 

> QisScalar(5);
 

true
 

> QisScalar(i);
 

false
 

> QisScalar(i);
 

false
 

> type(I,complex);
 

true
 

> type(I,quaternion);
 

true
 

> type(5,quaternion);
 

true
 

> type(q,quaternion);
 

true
 

> type([1,2,3],quaternion);
 

false
 

> type({1,2,3},quaternion);
 

false
 

> Qunit(q);
 

1/30*30^(1/2)+1/15*30^(1/2)*i+1/10*30^(1/2)*j+2/15*30^(1/2)*k
 

> % * %;
 

-14/15+2/15*i+1/5*j+4/15*k
 

> q;
 

1+2*i+3*j+4*k
 

> Qconjugate(q);
 

1-2*i-3*j-4*k
 

> QisCommutable(5,5);
 

true
 

> QisCommutable(q,q);
 

true
 

> QisCommutable(i,i);
 

true
 

> q1 := Qrand(-100,100); q2 := Qrand(-100,100);
 

q1 := 41+58*i+82*j+21*k
 

q2 := 29-97*i-88*j+31*k
 

> QisCommutable(q1,q2);
 

false
 

> q1*q2;
 

13380+2095*i-5065*j+4730*k
 

> q2*q1;
 

13380-6685*i+2605*j-970*k
 

> q;
 

1+2*i+3*j+4*k
 

> Qnorm(q);
 

30^(1/2)
 

> Qnormalize(q);
 

1/30*30^(1/2)+1/15*30^(1/2)*i+1/10*30^(1/2)*j+2/15*30^(1/2)*k
 

> %^2;
 

-.9333333333+.1333333333*i+.1999999999*j+.2666666665*k
 

> QconvertToFrac(%);
 

-14/15+2/15*i+1/5*j+4/15*k
 

> Qunit(q);
 

1/30*30^(1/2)+1/15*30^(1/2)*i+1/10*30^(1/2)*j+2/15*30^(1/2)*k
 

> QisEqual(5,5);
 

true
 

> QisEqual(4,5);
 

false
 

> QisEqual(q,q);
 

true
 

> QisEqual(q1,q2);
 

false
 

> Qunit(q)*Qunit(q);
 

-14/15+2/15*i+1/5*j+4/15*k
 

> Qabs(-5);
 

5
 

> Qabs(i);
 

1
 

> Qabs(j);
 

1
 

> q := Qconjugate(Qdefine(4,-3,1,-2));
 

q := 4+3*i-j+2*k
 

> qx := Qsignum(q);
 

qx := 2/15*30^(1/2)+1/10*30^(1/2)*i-1/30*30^(1/2)*j+1/15*30^(1/2)*k
 

> qy := Qdefine(2*sqrt(2/15),sqrt(3/10),-sqrt(1/30),sqrt(2/15));
 

qy := 2/15*30^(1/2)+1/10*30^(1/2)*i-1/30*30^(1/2)*j+1/15*30^(1/2)*k
 

> QisEqual(qx,qy);
 

true
 

> Qabs(q);
 

30^(1/2)
 

> q := Qrand(-4,5);
 

q := 2+4*i+2*j+5*k
 

> Qicoeff(q);
 

4
 

> Qjcoeff(q);
 

2
 

> Qkcoeff(q);
 

5
 

> Qscalar(q);
 

2
 

> Qvector(q);
 

4*i+2*j+5*k
 

> i*j*k;
 

-1
 

> j*k*i;
 

-1
 

> k*i*j;
 

-1
 

> j*i*k;
 

1
 

> sin(I+1);
 

sin(1+I)
 

> evalf(%);
 

1.298457581+.6349639148*I
 

> Qsin(i+1);
 

sin(1)*cosh(1)+cos(1)*sinh(1)*i
 

> evalf(%);
 

1.298457582+.6349639150*i
 

> Qsin(j+1);
 

sin(1)*cosh(1)+cos(1)*sinh(1)*j
 

> evalf(%);
 

1.298457582+.6349639150*j
 

> exp(0);
 

1
 

> exp(1);
 

exp(1)
 

> exp(I);
 

exp(I)
 

> evalf(%);
 

.5403023059+.8414709848*I
 

> Qexp(i);
 

cos(1)+sin(1)*i
 

> evalf(%);
 

.5403023059+.8414709848*i
 

> Qexp(i+j+k);
 

cos(3^(1/2))+1/3*sin(3^(1/2))*3^(1/2)*i+1/3*sin(3^(1/2))*3^(1/2)*j+1/3*sin(3^(1/2))*3^(1/2)*k
 

> evalf(%);
 

-.1605565390+.5698600993*i+.5698600993*j+.5698600993*k
 

> q;
 

2+4*i+2*j+5*k
 

> QunitVector(q)^2;
 

-1.
 

> exp(-1);
 

exp(-1)
 

> Qexp(-1);
 

exp(-1)
 

> exp(-I);
 

exp(-I)
 

> evalf(%);
 

.5403023059-.8414709848*I
 

> Qexp(-i);
 

cos(1)-sin(1)*i
 

> evalf(%);
 

.5403023059-.8414709848*i
 

> argument( exp(I * 2*Pi/3) );
 

2/3*Pi
 

> evalf(%);
 

2.094395103
 

> Qangle( Qexp(i * 2*Pi/3) );
 

2/3*Pi
 

> argument(I);
 

1/2*Pi
 

> Qargument(i);
 

1/2*Pi
 

> argument(1+I);
 

1/4*Pi
 

> Qargument(1+k);
 

1/4*Pi
 

> Qargument(1+j+k);
 

arccos(1/3*3^(1/2))
 

> q := Qunit(Qrand(-100,100));
 

q := 80/20361*20361^(1/2)-18/6787*20361^(1/2)*i+47/20361*20361^(1/2)*j+94/20361*20361^(1/2)*k
 

> n := 4;
 

n := 4
 

> theta := Pi/3;
 

theta := 1/3*Pi
 

> w := QunitVector(q);
 

w := -18/94753307*284259921^(1/2)*20361^(1/2)*i+47/284259921*284259921^(1/2)*20361^(1/2)*j+94/284259921*284259921^(1/2)*20361^(1/2)*k
 

> evalf(Qexp(w*n*theta)); # note the next three commands are approximately equal
 

-.5000000000+.3957911946*i-.3444849286*j-.6889698570*k
 

> (Qcos(theta) + w*Qsin(theta))^n;
 

-.5000000000+.3957911945*i-.3444849286*j-.6889698571*k
 

> evalf(Qcos(n*theta) + w*Qsin(n*theta));
 

-.5000000000+.3957911946*i-.3444849286*j-.6889698570*k
 

Quaternion Procedures in Maple 

  • The following names are defined in the quaternion package:
 

type/quaternion  

*  

+  

-  

^  

Qabs  

Qadd  

Qamplitude  

Qangle  

Qarccos  

Qarccosh  

Qarccot  

Qarccoth  

Qarccsc  

Qarccsch  

Qarcsec  

Qarcsech  

Qarcsin  

Qarcsinh  

Qarctan  

Qarctanh
Qargument

 

Qaxial  

Qceil  

Qcolatitude  

Qconjugate
QconvertToFrac
 

Qcos  

Qcosh  

Qcot  

Qcoth  

Qcsc  

Qcsch  

Qdefine  

QdivLeft  

QdivRight  

Qdot  

Qeval  

Qexp  

Qfloor  

Qfrac  

Qicoeff  

Qinverse  

QisCommutable  

QisEqual  

QisPure
 

QisScalar  

Qjcoeff  

Qkcoeff  

Qlength  

Qln  

Qlongitude  

Qmagnitude  

Qmodulus  

QmuPart  

Qmult  

Qnorm  

Qnormalize
QphiPart
 

QpolarPart  

QpolarToRect  

Qpower
QpsiPart
 

Qrand  

QrectToPolar  

Qround
Qscalar
 

Qsec  

Qsech  

Qsignum
Qsin
 

Qsinh  

Qsqrt  

Qsubtract
 

Qtan  

Qtanh  

QthetaPart  

QtoMatrices
QtoMatrix
 

Qtrunc  

Qunit  

QunitVector
Qvector
 

History 


Sir William Rowan Hamilton was born in Dublin, Ireland either on August 3rd or on August 4th, 1805.  He was born at midnight, so there is some confusion about his birthday.  Hamilton was considered a prodigy.  For some years, he lived in Trim with his uncle, Reverend James Hamilton.  By the age of five, it is claimed that Hamilton knew Latin, Greek, and Hebrew, which he learned from his uncle.  Hamilton was exposed to mathematics at age twelve by Zerah Colburn (American).  Colburn was able to impress Hamilton by performing amazing mental arithmetic operations.

By age 13, Hamilton studied the algebra of the mathematician Alexis Claude Clairaut (Paris, France; 1713 - 1765).  Clairaut's Th?orie de la Figure de la Terra (1743), a treatise dealing with the shape of rotating solid bodies, might have been the driving force for Hamilton's direction toward quaternions.  At age 17, Hamilton discovered an error in Laplace's M?chanique C?leste, which brought Hamilton a lot of recognition.  At age 18, Hamilton became a student at Trinity College, Dublin.  He earned an award called Optime in Classics--awarded once every twenty years.
  
Hamilton married Helen Maria Bayly in Ireland and together they had two sons and a daughter.  On his publication of Theory of System of Rays (1832), he predicted conical refraction via the characteristic function on Fresnel's wave surface.  Hamilton received great fame after Humphrey Lloyd, his physics professor, confirmed experimentally this theoretical prediction.  In 1835, Hamilton received his knighthood.
  
The Royal Irish Academy provided an audience for Hamilton's paper on complex numbers as algebraic couples (ordered pairs of real numbers).  His paper was considered very difficult to understand (this was a curse that plagued all of Hamilton's publications).  However, his focus was expanding the algebra of the complex numbers to triplets.  He could add and subtract triplets, but could not multiply them.  For years his obsession even caught the attention of his children who would ask him every morning, "Well, Papa can you multiply triplets?"  On Monday, October 16, 1843, while Hamilton and his wife were walking along the Royal Canal on his way to a council meeting with the Royal Irish Academy, the idea of the quaternions sparked in his mind.  He carved the idea in the stone of Brougham Bridge:       i^2 = j^2 = k^2 = ijk = -1. 


Hamilton felt that his discovery of the quaternions in the 19th century was just as important as the fluxions (the calculus) were in the 17th century.  The rest of his life was devoted to elucidating the algebra of the quaternions.  However, being plagued with alcoholism and cursed with the inability to communicate his ideas clearly may have been the reasons quaternions were not taken seriously.  The mathematician, William Thomson (Ireland; 1824 - 1907) wrote:  
                                        Quaternions came from Hamilton after his really good work had been
                 done, and  though beautifully ingenious, have been an unmixed evil 

                 to those who have touched them in any way.
 

Applications 

Rotating objects are probably quaternion numbers' most practical application.  We have an alternate way of rotating objects with another non-commutative algebra, called matrix algebra.  However, matrix algebra, coupled with trigonometric functions, has a defect.  Sometimes we get what one calls a singular matrix.      Mechanical devices, such as gyroscopes, tracking, robot arms, etc., cannot afford to have a singular matrix in the software.  A singular matrix can cause gimbal (or robot) lock.   Gimbal lock is when the mechanical device simply locks up (stop working) because one degree of freedom, among the three axes, is lost..  This could be very hazardous for an air force fighter navigation system!  In addition, it could be very costly for an automobile factory that uses robotic arms.  Rotations, via quaternion numbers, do not exhibit the problem of gimbal lock.  Quaternion numbers also will require fewer programming steps than matrix rotation.  Fewer programming step equates to faster, efficient, and cost-effective software.
  
Rotation is also used in computer animation.  As computers are becoming faster, consumers need incentives to purchase the more expensive computers.  Video games offer strong incentives for those who take their leisure seriously.  Interactive video games need effective method of rotating virtual objects.  For example, both video games of Tomb Raider I, II, & III all take advantage of quaternions.   

 

Matrix algebra utilizes angles called Euler angles.  Euler angles are the rotation angles of the Euclidean (rectangle) coordinate system.  Euler angles specify the rotation of the X, Y, and Z rotation axes.  The Euler angle is the culprit of the singularities in matrix algebra.  In addition, Euler angles produce a jerky and unnatural type of movement.  With quaternions, the rotations are smooth and natural.  This is why Microsoft's programming development software offers software engineers quaternion tools.  Remember quaternions are four dimensions; this is the reason quaternions are more effective and efficient then matrices.  Euler angles only work with three dimensions of height, length, and width.  However, quaternions have the super ability to produce a rotation on any, of the infinite, axes of a sphere.  For a rotation of two axes, one would need several operations, with matrices, and only one operation, with quaternions.
  
Quaternions are also utilized in MRI (Magnetic Resonance Images) and CAT (Computed Axial Tomography), also known as CT (Computed Tomography).  MRI technology utilizes magnetic energy and radio waves in order to produce cross-sectional slice images of the human body.  CAT technology utilizes the x-ray principal.  As x-rays pass through the body they are attenuated at different levels; this produces a profile of different slices.  MRI and CAT scans perform rigid transformations that are represented by quaternions.  Each quaternion is iterated as an interpolated change that is computed for position and orientation.  In addition, the interpolated rotation is a small-angle approximation of a rotation quaternion that is linear in three parameters.
 

References 

Maxfield, John E., and Maxfield, Margaret W.  Abstract Algebra and Solution by Radicals.  New York:  Dover, 1971.
  
Meserve, Bruce E.  Fundamental Concepts Of Algebra.  New York:  Dover, 1981.
  
Parker, Sybil P.  Dictionary of Mathematics.  New York:  McGraw, 1997.
  
Rucker, Rudy.  The Fourth Dimension:  A Guided Tour of the Higher Universes.   Boston:          Houghton, 1984.
  
Russell, Bertrand.  Introduction to Mathematical Philosophy.  New York:  Dover, 1933.
  
Sanchez, Julio, and Maria Canton.  DirectX 3D Graphics Programming Bible.  Foster City, CA:  IDG Books Worldwide, 2000.
               
Shapiro, Max S.  Mathematics Encyclopedia.  Garden City:  Doubleday, 1977.
  
Smith, D. E.  History of Mathematics.  2 vols.  New York:  Dover, 1958.
  
Sweetser, Doug.  Doing Physics with Quaternions.  n.p., n.d.  Online.  Internet.  12 December 2000.
Available http://world.std.com/~sweetester/quarternions/qindex.html.
  
Taylor, Edwin F., and John Archibald Wheeler.  Spacetime Physics:  Introduction to Special Relativity.  2nd ed.  New York:  W. H. Freeman, 1996.
  
Wright, Richard S., Jr., and Sweet, Michael.  OpenGL Super Bible.  2nd ed.  Indianapolis:  Waite Group, 2000.
  
Wunsch, David A.  Complex Variables with Applications.  2nd ed.  Massachusetts: Addison-Wesley, 1994. 

Credits 

School:.........................Purdue University Calumet
Department:.................Mathematics, Computer Science, and Statistics
Course:........................CS 206 - Computer Algebra and Programming
Professor:.....................Roger Kraft, PhD
Student:........................Michael Carter (Laureice@wideopenwest.com)
Project:........................Quaterion Package
Platform:......................Windows 2000/XP
Computer Algebra:........Maple 8 updated to Maple 9.5 copyrights reserved except for Maplesoft.
Date:............................Friday, August 15, 2003 updated March 12, 2005
Purpose:.......................To receive credit for Maple programming in CS 206. 

Email:...........................Laureice@wideopenwest.com 

 

 

Profile 

 

Image 

 

I received my first bachelor of science in biology (minor in chemistry) from Lewis University. I received my second B.S. from Purdue University Calumet. I am now pursuing a M.S. in Software Engineering at Purdue University West Lafayette  Years ago, I received a certificate in computer programming from the College of Automation in Chicago and a post-bachelor degree in information systems with the programming option at Purdue.  I am very happy about several projects throughout my quests.  To name a few, I designed an assembler language computer emulator as two applications, one in C and the other in C#.  Here, I coded both the assembler and the emulator.  Next, I designed an animated mechanical man in Java3D (using quaternions); this course had only one student in it; guess who?me.  Finally, in two of my courses, I had to design a linear programming package and a grammar analyzer package, both of which were written in C#.  I was exposed to quaternions, octonions, and sedenions while studying at the University of Ǻalborg in Denmark a few years back.  Later, quaternions became my project while enrolled in a Maple programming course in the spring of 2003. It was originally written for Maple 8.  Two years later my professor gave me my code back, and I decided to update it to Maple 9.5.  My favorite languages are Microsoft Macro Assembler, C#, Java, and Python. 

 

Legal Notice: The copyright for this application is owned by the author(s). Neither Maplesoft nor the author are responsible for any errors contained within and are not liable for any damages resulting from the use of this material. This application is intended for non-commercial, non-profit use only. Contact the author for permission if you wish to use this application in for-profit activities. 

Image