是否可以提高MatLab的精度? [英] Is it possible to increase MatLab's precision?

查看:228
本文介绍了是否可以提高MatLab的精度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要过滤旋转矩阵,然后首先将其转换为旋转角度,然后过滤这些角度并将答案转换回旋转矩阵形式.问题在于,即使在两次转换之间都没有进行过滤(即angl2rot(rot2angl(rotationMatrix))),将这两个转换链接在一起也会导致严重的错误,因为执行转换所需的所有触发函数都缺乏精度.

I need to filter a rotation matrix and to do that I need to first convert it to rotation angles, then filter those and convert the answer back to a rotation matrix form. The problem is that chaining those two conversions together even without the filtering in between (i.e. angl2rot(rot2angl(rotationMatrix))) introduces a significant error due to the lack of precision in all the trig functions required to do the conversions.

一般有没有办法提高MatLab的精度?还是特别可以使trig函数(我使用sin(),cos()和atan2())更精确?

Is there a way to increase the precision of MatLab in general? Or maybe in particular is it possible to make the trig functions (I use sin(), cos() and atan2()) more precise?

负责将功能从旋转矩阵转换为欧拉角,反之亦然的函数的实现:

There go the implementations of functions responsible for converting from rotation matrices to Euler angles and vice versa:

function [ rotationM ] = eul2rot( a, b, c )
%EUL2ROT This function converts euler rotation angles to a 3x3 rotaton
%matrix

    X = zeros(3,3,size(a,1));
    Y = zeros(3,3,size(a,1));
    Z = zeros(3,3,size(a,1));
    rotationM = zeros(3,3,size(a,1));

    for count = 1:size(a,1)

        X(:,:,count) = [1 0 0; ...
            0 cos(a(count)) -sin(a(count)); ...
            0 sin(a(count)) cos(a(count))];

        Y(:,:,count) = [cos(b(count)) 0 sin(b(count)); ...
            0 1 0; ...
            -sin(b(count)) 0 cos(b(count))];

        Z(:,:,count) = [cos(c(count)) -sin(c(count)) 0; ...
            sin(c(count)) cos(c(count)) 0; ...
            0 0 1];

        rotationM(:,:,count) = Y(:,:,count)*Z(:,:,count);
        rotationM(:,:,count) = X(:,:,count)*rotationM(:,:,count);

    end

end

function [ th ] = rot2eul( rot )
%ROT2EUL Converts a 3x3 rotation matrix into a vector of three euler angles
        th = [atan2(rot(3,2,:),rot(3,3,:)); ...
            atan2(-rot(3,1,:),sqrt(rot(3,2,:).^2+rot(3,3,:).^2)); ...
            atan2(rot(2,1,:),rot(1,1,:))];
end

他们使用在此处找到的方程式.

They use the equations found here.

推荐答案

您链接的站点为您的来源将旋转矩阵R定义为:

The site you link as your source defines rotation matrix R as:

R = Z*Y*X;

其中X, Y, Z是三个单独的旋转矩阵.

Where X, Y, Z are the three individual rotation matrices.

但是,在您的代码中您正在执行以下操作:

However, in your code you are doing this:

rotationM(:,:,count) = Y(:,:,count)*Z(:,:,count);
rotationM(:,:,count) = X(:,:,count)*rotationM(:,:,count);

等同于:

R = X*Y*Z;

这两个不相等,因为矩阵乘法不是可交换的.更改乘积顺序等同于更改旋转顺序(3D旋转也不是可交换的),从而获得与预期不同的结果.

These two are not equivalent, because matrix multiplication is not commutative. Changing the order is of multiplication is equivalent to changing the order in which the rotations are performed (and rotations in 3D are also not commutative), giving you a different result than you were expecting.

这篇关于是否可以提高MatLab的精度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆