Search code examples
matlabvectorkalman-filter

vector as output for matlab function


I am new to Matlab.

I am doing Extended Kalman Filter simulation which requires calculating Jacobians(partial differenciation functions) for a given function. I am using a function to get the Jacobian values:

function [H] = jacobH(x1,x2)
H = [ -(2*x1(1,:,:) - 2*x2(1,:,:))/(8*pi*((x1(1,:,:) - x2(1,:,:))^2 + (x1(3,:,:) - x2(3,:,:))^2)^(3/2)), 0,
      -(2*x1(3,:,:) - 2*x2(3,:,:))/(8*pi*((x1(1,:,:) - x2(1,:,:))^2 + (x1(3,:,:) - x2(3,:,:))^2)^(3/2)), 0];
end

The Jacobian basically differenciates 1/(4*pi*sqrt((x1-x2)^2+(y1-y2)^2)) wrt x,y

Eg, If I am passing jacobH(x1(:,1,1), x2(:,1,1)) then I should get H as a 1x4 matrix with [value1, 0, value2, 0]. value1 and value2 varies for different inputs.

But I am getting only one value. I don't know where I went wrong.

I searched for similar questions but none of them are relevant to my issue.

Also, Is there a more efficient way to do this?

Any help is appreciated!


Solution

  • With your function I obtain the correct behavior when I try:

    x1 = ones(3,3,3);
    x2 = ones(3,3,3);    
    jacobH(x1(:,1,1), x2(:,1,1))
    
    ans =
    
       NaN     0   NaN     0