Question

How can I calculate the norm of quaternion in matlab?

I tried this example

a = [1 4 4 -4];
norm = quatnorm(a)

My expected output is 7 but matlab returns 49.

What am I doing wrong?

Was it helpful?

Solution

As @Dan points out, using the native implementation, you are probably getting the square of the formal norm definition. For some reason quatnorm returns the square, after estimating the Euclidean norm (square root of sum of squares).

q = [1 4 4 -4];

MATLABquatnorm:

for index = size(q, 1):-1:1
    qnorm(index,:) = norm(q(index,:), 2);
end    
qout = qnorm.*qnorm;

Alternative (for vectors):

sqrt(q*q')

This is equivalent to getting sqrt(quatnorm(q)). As you will note above, quatnorm is also adapted to estimate norms for quaternions stored in successive matrix rows (estimates the norm of each row and then squares)

Alternative (for matrices N x 4):

Q = [q; 2*q]; % example

sqrt(diag(Q*Q'))

OTHER TIPS

You can either take square root of the returned number, or you can use function quatmod(q) instead, which calculates the proper Euclidean norm (modulus) of the complex number by not taking square of it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top