⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 calcderror.m

📁 无线传感器节点定位算法
💻 M
字号:
%|
%| PURPOSE:  Calculate the derivative of the error between the model and the data
%|

function [dError] = calcDError(guessBlindLocs)

global refDevices;    % number of reference nodes
global blindDevices;  % number of blind devices
global totalDevices;  % the total number of devices
global linearRefLocs; % locations of the reference devices
global dhat;          % estimated distance between devices based on the measured
                      % received power.
global dfuncEvals;    % counter for number of function evaluations.
dfuncEvals = dfuncEvals + 1;
TINY       = 1e-5;

x = [linearRefLocs(1:refDevices), guessBlindLocs(1:blindDevices)];
y = [linearRefLocs(refDevices+1:2*refDevices), guessBlindLocs(blindDevices+1:2*blindDevices)];
%x         = [0 0 1 1 0.5 0.75];
%y         = [0 1 1 0 0.75 0.5];

%| 1.  Do the preliminary calculations here in order to save time in the
%|     next loop.
for k = refDevices+1 : totalDevices,
   l = [1:k-1];
   modelDistSqr    = max(TINY, (x(k)-x(l)).^2 + (y(k)-y(l)).^2);
   commonTerm(k,l) = log( modelDistSqr ./ (dhat(k,l).^2)) ./ modelDistSqr;
end

commonTerm(:,totalDevices) = zeros(totalDevices,1);

%| 2.  For each device, calculate the partial derivatives.
for k = refDevices+1 : totalDevices,
   dFdx(k)  = sum(commonTerm(k,1:k-1).*(x(k)-x(1:k-1))) + ...
      sum(commonTerm(k+1:totalDevices, k)'.*(x(k)-x(k+1:totalDevices)));
   dFdy(k)  = sum(commonTerm(k,1:k-1).*(y(k)-y(1:k-1))) + ...
      sum(commonTerm(k+1:totalDevices, k)'.*(y(k)-y(k+1:totalDevices)));
end

dError = [dFdx(refDevices+1:totalDevices), dFdy(refDevices+1:totalDevices)];

⌨️ 快捷键说明

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