trig.m

来自「一个很好用的摄像机标定程序」· M 代码 · 共 61 行

M
61
字号
% Trigonometric function
% ---------------------- 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% function [fvec,J]=trig(n,m,x,option)
% Problem no. 26
% Dimensions -> n=variable, m=n
% Standard starting point -> x=(1/n,..,1/n)
% Minima -> f=0 
%                                     
% 11/21/94 by Madhu Lamba  
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function [fvec,J] = trig(n,m,x,option)  

  zero=0.d0;
  one=1.d0;

  if option==1
      sum1 = zero;
      for i=1:n
        xi   = x(i);
        cxi  = cos(xi);
        sum1  = sum1 + cxi;
        fvec(i) = n + (i)*(one - cxi) - sin(xi);
      end
      fvec=fvec';
      fvec=fvec-sum1;
   
  elseif option==2
      for j=1:n
        xj  = x(j);
        sxj = sin(xj);
        for i=1:n
          J( i, j) = sxj;
        end
        J(j, j) =  (j+1)*sxj - cos(xj);
      end

  elseif option==3
      sum1 = zero;
      for i=1:n
        xi   = x(i);
        cxi  = cos(xi);
        sum1  = sum1 + cxi;
        fvec(i) = n + (i)*(one - cxi) - sin(xi);
      end
      fvec=fvec';
      fvec=fvec-sum1;

      for j=1:n
        xj  = x(j);
        sxj = sin(xj);
        for i=1:n
          J( i, j) = sxj;
        end
        J(j, j) =  (j+1)*sxj - cos(xj);
      end

  else error('Error: trig.m : invalid option')
  end

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?