Quaternion Multiplication: What is the correct way of doing it? I am not very familiar with quaternions, I was just doing a programming homework were I had to implement quaternions' arithmetic, however I got puzzled by the multiplication of 2 quaternions.

Let's say I have the following:

$a = \alpha_1 + \beta_1i+\gamma_1j+\delta_1k$

$b = \alpha_2 + \beta_2i+\gamma_2j+\delta_2k$

I have been given the following rules $i^2=j^2=k^2=-1$, $ik=-j$, $ij=k$, $ji=-k$, $jk = i$, $ki = j$, $kj = -i$

Doing the algebra I get the following expression for the product of a and b:

$$\alpha_1\alpha_2 - \beta_1\beta_2 - \gamma_1\gamma_2 - \delta_1\delta_2 \\
+i(\alpha_1\beta_2+\beta_1\alpha_2+\gamma_1\delta_2-\delta_1\gamma_2)\\
+j(\alpha_1\gamma_2-\beta_1\gamma_2+\gamma_1\alpha_2+\delta_1\beta_2)\\
+k(\alpha_1\delta_2+\beta_1\gamma_2-\gamma_1\beta_2+\delta_1\alpha_2)$$

However, when I looked for documentation on this operation in some languages such as matlab, the quaternion product has other definition:

http://www.mathworks.com/help/aerotbx/ug/quatmultiply.html

So, when I test my implementation against the example given the result is different. So, Why is that? What is the correct definition?
Your expression for the $j$ term is wrong. It should be:
$$ \alpha_1 \gamma_2-\beta_1\delta_2 + \gamma_1 \alpha_2  + \delta_1 \beta_2 $$
I do not understand quaternions at all, but what I have been told is that multiplication does not commute with quaternions. I suggest perhaps using only the rules given, and not passing to the distributive law as you have done, although that sounds a bit insane.

I believe quaternions can be represented as a matrix algebra in some form, perhaps start with that idea or assume it is true to begin with. That would make computation a lot easier!

Oh yeah and is there a stray gamma in there? :)