八度fminunc不更新

时间:2018-08-23 21:06:33

标签: octave

我有以下八度脚本:

clear;

T0 = [...
    1.0, 1.0, 5.0; ...
    1.0, 2.0, 3.0; ...
    -1.0,0.0, 6.0];

option = optimset('Display','Iter','GradObj','on','MaxIter','300','TolFun',10-5);
[t f] = fminunc(@flatTriangle,T0(:),option);

t = reshape(t,3,3);

并遵循八度音程功能

function [cost grad] = flatTriangle(T)
  T = reshape(T,3,3);

  Q = T(1,:)';
  P = T(2,:)';
  R = T(3,:)';

  e3 = [0;0;1];

  nf = cross(R - Q,P - Q);

  cost = 0.5*(e3'*nf - norm(nf))^2;

  grad = zeros(9,1);

  commonStuff = (e3'*nf - norm(nf))*(e3 - nf/norm(nf))';

  grad(1:3) = (commonStuff*skew(P - R)')';
  grad(4:6) = (commonStuff*skew(R - Q)')';
  grad(7:9) = (commonStuff*skew(Q - P)')';

endfunction

function Vhat = skew(V)
  Vhat = [...
   0.0 -V(3) V(2); ...
   V(3) 0.0 -V(1); ...
   -V(2) V(1) 0.0];
endfunction

现在,尽管grad向量不为0,但最终输出与初始输入完全没有变化。

我使用不正确的东西吗?也许我配置不正确? 该代码可以运行,但似乎什么也没做。

0 个答案:

没有答案