Matlab 放置函数错误
Matlab place function error
这里有一个有趣的问题。在我们学校的Windows服务器上,Matlab可以完美执行下面代码中的place函数,return一个1x4的矩阵赋值给变量K。但是,Linux服务器,我的Matlab个人计算机 (Windows 8.1) 所有 return 多个错误。状态 space 矩阵的解是正确的。我也曾尝试简单地创建一个 A 和 B 矩阵,其值类型为 Double 而不是符号矩阵,但无济于事。错误如下:
Error using symengine
Cannot prove '(0.00000000000011152837950971767051666806677642 < 5.0227916840119976230900756087285) < 2' literally. To test the statement
mathematically, use isAlways.
Error in sym/logical (line 360)
X = mupadmex('symobj::logical',A.s,9);
Error in sym/any (line 417)
X = any(logical(A));
Error in place (line 77)
if any(mult>m)
我要执行的相关代码是这样的:
syms theta thetadot y ydot u s;
I2 = 0.05;
I1 = 0.2;
m2 = 2;
r = 0.11;
a = 0.1;
g = 9.81;
x0 = [20 * pi / 180 0.2 0 0];
W = [I1 + I2 + m2 * (y^2 + r^2) m2 * r + I2 / a; m2 * r + I2 / a m2 + I2 / a^2];
qdd = W^(-1) * ([u; 0] - (m2 * [2*y*thetadot*ydot; -y*thetadot^2] - m2*g* [r*sin(theta) + y*cos(theta); sin(theta)]));
qd = [thetadot; ydot];
xdot = [qd; qdd];
eq = [0 0 0 0 0 ];
x3bytheta = subs(diff(qdd(1), theta), {theta, y, thetadot, ydot, u}, eq);
x3byy = subs(diff(qdd(1), y), {theta, y, thetadot, ydot, u}, eq);
x3bythetadot = subs(diff(qdd(1), thetadot), {theta, y, thetadot, ydot, u}, eq);
x3byydot = subs(diff(qdd(1), ydot), {theta, y, thetadot, ydot, u}, eq);
x4bytheta = subs(diff(qdd(2), theta), {theta, y, thetadot, ydot, u}, eq);
x4byy = subs(diff(qdd(2), y), {theta, y, thetadot, ydot, u}, eq);
x4bythetadot = subs(diff(qdd(2), thetadot), {theta, y, thetadot, ydot, u}, eq);
x4byydot = subs(diff(qdd(2), ydot), {theta, y, thetadot, ydot, u}, eq);
x3byu = subs(diff(qdd(1), u), {theta, y, thetadot, ydot, u}, eq);
x4byu = subs(diff(qdd(2), u), {theta, y, thetadot, ydot, u}, eq);
A = [0 0 1 0; 0 0 0 1; x3bytheta x3byy x3bythetadot x3byydot; x4bytheta x4byy x4bythetadot x4byydot];
B = [0; 0; x3byu; x4byu];
K = place(vpa(A, 3), vpa(B, 3), [-1, -2, -1+2j, -1-2j]);
行为上的差异来自 R2015a update to the Symbolic Toolbox (last entry), and quoting from the current documentation of symbolic gt
:
In previous releases, gt
in some cases evaluated inequalities involving only symbolic numbers and returned logical 1
or 0
. To obtain the same results as in previous releases, wrap inequalities in isAlways
. For example, use isAlways(A > B)
.
即使两个操作数都是常量,符号比较也会持续;也就是说,没有参加架构会议,这是一个相当大的疏忽和古怪的行为。
不幸的是,由于 place
是从“double
-首先使用”的角度编写的,该函数依赖于逻辑求和来产生数字输出而不是符号表达式。
我可以看到两种方法来补救这种情况:
- 除非你真的需要可变精度算法,因为系统的 ill-conditioned 性质是不可避免的,否则只需将
A
和 B
转换为双精度数,你已经注意到它是有效的。
- 如果您确实需要可变精度算术,请创建
place
函数的本地副本并将所有相关的逻辑比较包装在 isAlways
中以评估比较。我发现的兴趣线是(如果不准确的话,接近于)60、105、117 和 123。
这里有一个有趣的问题。在我们学校的Windows服务器上,Matlab可以完美执行下面代码中的place函数,return一个1x4的矩阵赋值给变量K。但是,Linux服务器,我的Matlab个人计算机 (Windows 8.1) 所有 return 多个错误。状态 space 矩阵的解是正确的。我也曾尝试简单地创建一个 A 和 B 矩阵,其值类型为 Double 而不是符号矩阵,但无济于事。错误如下:
Error using symengine
Cannot prove '(0.00000000000011152837950971767051666806677642 < 5.0227916840119976230900756087285) < 2' literally. To test the statement
mathematically, use isAlways.
Error in sym/logical (line 360)
X = mupadmex('symobj::logical',A.s,9);
Error in sym/any (line 417)
X = any(logical(A));
Error in place (line 77)
if any(mult>m)
我要执行的相关代码是这样的:
syms theta thetadot y ydot u s;
I2 = 0.05;
I1 = 0.2;
m2 = 2;
r = 0.11;
a = 0.1;
g = 9.81;
x0 = [20 * pi / 180 0.2 0 0];
W = [I1 + I2 + m2 * (y^2 + r^2) m2 * r + I2 / a; m2 * r + I2 / a m2 + I2 / a^2];
qdd = W^(-1) * ([u; 0] - (m2 * [2*y*thetadot*ydot; -y*thetadot^2] - m2*g* [r*sin(theta) + y*cos(theta); sin(theta)]));
qd = [thetadot; ydot];
xdot = [qd; qdd];
eq = [0 0 0 0 0 ];
x3bytheta = subs(diff(qdd(1), theta), {theta, y, thetadot, ydot, u}, eq);
x3byy = subs(diff(qdd(1), y), {theta, y, thetadot, ydot, u}, eq);
x3bythetadot = subs(diff(qdd(1), thetadot), {theta, y, thetadot, ydot, u}, eq);
x3byydot = subs(diff(qdd(1), ydot), {theta, y, thetadot, ydot, u}, eq);
x4bytheta = subs(diff(qdd(2), theta), {theta, y, thetadot, ydot, u}, eq);
x4byy = subs(diff(qdd(2), y), {theta, y, thetadot, ydot, u}, eq);
x4bythetadot = subs(diff(qdd(2), thetadot), {theta, y, thetadot, ydot, u}, eq);
x4byydot = subs(diff(qdd(2), ydot), {theta, y, thetadot, ydot, u}, eq);
x3byu = subs(diff(qdd(1), u), {theta, y, thetadot, ydot, u}, eq);
x4byu = subs(diff(qdd(2), u), {theta, y, thetadot, ydot, u}, eq);
A = [0 0 1 0; 0 0 0 1; x3bytheta x3byy x3bythetadot x3byydot; x4bytheta x4byy x4bythetadot x4byydot];
B = [0; 0; x3byu; x4byu];
K = place(vpa(A, 3), vpa(B, 3), [-1, -2, -1+2j, -1-2j]);
行为上的差异来自 R2015a update to the Symbolic Toolbox (last entry), and quoting from the current documentation of symbolic gt
:
In previous releases,
gt
in some cases evaluated inequalities involving only symbolic numbers and returned logical1
or0
. To obtain the same results as in previous releases, wrap inequalities inisAlways
. For example, useisAlways(A > B)
.
即使两个操作数都是常量,符号比较也会持续;也就是说,没有参加架构会议,这是一个相当大的疏忽和古怪的行为。
不幸的是,由于 place
是从“double
-首先使用”的角度编写的,该函数依赖于逻辑求和来产生数字输出而不是符号表达式。
我可以看到两种方法来补救这种情况:
- 除非你真的需要可变精度算法,因为系统的 ill-conditioned 性质是不可避免的,否则只需将
A
和B
转换为双精度数,你已经注意到它是有效的。 - 如果您确实需要可变精度算术,请创建
place
函数的本地副本并将所有相关的逻辑比较包装在isAlways
中以评估比较。我发现的兴趣线是(如果不准确的话,接近于)60、105、117 和 123。