function [A] = computeA(l, b, s, theta)
%UNTITLED Summary of this function goes here
%   Detailed explanation goes here

n_meas = length(l); % number of measurements

A = zeros(n_meas, 9); % for each row

for i_row = 1:n_meas

    theta_xy = theta(1); theta_xz = theta(2); theta_yz = theta(3);
    Sx = s(1); Sy = s(2); Sz = s(3);
    Bx = b(1); By = b(2); Bz = b(3);
    Vx = l(i_row, 1); Vy = l(i_row, 2); Vz = l(i_row, 3);

    term_1 = (2*Bx - 2*Vx)/Sx^2 - (2*(sin(theta_xz)/Sx - (cos(theta_xz)*sin(theta_xy)*sin(theta_yz))/(Sx*cos(theta_xy)))*((Bz - Vz)/Sz - (sin(theta_xz)*(Bx - Vx))/Sx + (cos(theta_xz)*sin(theta_yz)*(Vy - By + (Sy*sin(theta_xy)*(Bx - Vx))/Sx))/(Sy*cos(theta_xy))))/(cos(theta_xz)^2*cos(theta_yz)^2) + (2*sin(theta_xy)*(Vy - By + (Sy*sin(theta_xy)*(Bx - Vx))/Sx))/(Sx*Sy*cos(theta_xy)^2); % df/dBx
    term_2 = - (2*Vy - 2*By + (2*Sy*sin(theta_xy)*(Bx - Vx))/Sx)/(Sy^2*cos(theta_xy)^2) - (2*sin(theta_yz)*((Bz - Vz)/Sz - (sin(theta_xz)*(Bx - Vx))/Sx + (cos(theta_xz)*sin(theta_yz)*(Vy - By + (Sy*sin(theta_xy)*(Bx - Vx))/Sx))/(Sy*cos(theta_xy))))/(Sy*cos(theta_xy)*cos(theta_xz)*cos(theta_yz)^2); % df/dBy
    term_3 = (2*((Bz - Vz)/Sz - (sin(theta_xz)*(Bx - Vx))/Sx + (cos(theta_xz)*sin(theta_yz)*(Vy - By + (Sy*sin(theta_xy)*(Bx - Vx))/Sx))/(Sy*cos(theta_xy))))/(Sz*cos(theta_xz)^2*cos(theta_yz)^2); % df/dBz
    term_4 = (2*((sin(theta_xz)*(Bx - Vx))/Sx^2 - (cos(theta_xz)*sin(theta_xy)*sin(theta_yz)*(Bx - Vx))/(Sx^2*cos(theta_xy)))*((Bz - Vz)/Sz - (sin(theta_xz)*(Bx - Vx))/Sx + (cos(theta_xz)*sin(theta_yz)*(Vy - By + (Sy*sin(theta_xy)*(Bx - Vx))/Sx))/(Sy*cos(theta_xy))))/(cos(theta_xz)^2*cos(theta_yz)^2) - (2*(Bx - Vx)^2)/Sx^3 - (2*sin(theta_xy)*(Bx - Vx)*(Vy - By + (Sy*sin(theta_xy)*(Bx - Vx))/Sx))/(Sx^2*Sy*cos(theta_xy)^2); % df/dSx
    term_5 = (2*sin(theta_xy)*(Bx - Vx)*(Vy - By + (Sy*sin(theta_xy)*(Bx - Vx))/Sx))/(Sx*Sy^2*cos(theta_xy)^2) - (2*((cos(theta_xz)*sin(theta_yz)*(Vy - By + (Sy*sin(theta_xy)*(Bx - Vx))/Sx))/(Sy^2*cos(theta_xy)) - (cos(theta_xz)*sin(theta_xy)*sin(theta_yz)*(Bx - Vx))/(Sx*Sy*cos(theta_xy)))*((Bz - Vz)/Sz - (sin(theta_xz)*(Bx - Vx))/Sx + (cos(theta_xz)*sin(theta_yz)*(Vy - By + (Sy*sin(theta_xy)*(Bx - Vx))/Sx))/(Sy*cos(theta_xy))))/(cos(theta_xz)^2*cos(theta_yz)^2) - (2*(Vy - By + (Sy*sin(theta_xy)*(Bx - Vx))/Sx)^2)/(Sy^3*cos(theta_xy)^2); % df/dSy
    term_6 = -(2*(Bz - Vz)*((Bz - Vz)/Sz - (sin(theta_xz)*(Bx - Vx))/Sx + (cos(theta_xz)*sin(theta_yz)*(Vy - By + (Sy*sin(theta_xy)*(Bx - Vx))/Sx))/(Sy*cos(theta_xy))))/(Sz^2*cos(theta_xz)^2*cos(theta_yz)^2); % df/dSz
    term_7 = (2*((cos(theta_xz)*sin(theta_yz)*(Bx - Vx))/Sx + (cos(theta_xz)*sin(theta_xy)*sin(theta_yz)*(Vy - By + (Sy*sin(theta_xy)*(Bx - Vx))/Sx))/(Sy*cos(theta_xy)^2))*((Bz - Vz)/Sz - (sin(theta_xz)*(Bx - Vx))/Sx + (cos(theta_xz)*sin(theta_yz)*(Vy - By + (Sy*sin(theta_xy)*(Bx - Vx))/Sx))/(Sy*cos(theta_xy))))/(cos(theta_xz)^2*cos(theta_yz)^2) + (2*sin(theta_xy)*(Vy - By + (Sy*sin(theta_xy)*(Bx - Vx))/Sx)^2)/(Sy^2*cos(theta_xy)^3) + (2*(Bx - Vx)*(Vy - By + (Sy*sin(theta_xy)*(Bx - Vx))/Sx))/(Sx*Sy*cos(theta_xy)); % df/d theta_xy
    term_8 = (2*sin(theta_xz)*((Bz - Vz)/Sz - (sin(theta_xz)*(Bx - Vx))/Sx + (cos(theta_xz)*sin(theta_yz)*(Vy - By + (Sy*sin(theta_xy)*(Bx - Vx))/Sx))/(Sy*cos(theta_xy)))^2)/(cos(theta_xz)^3*cos(theta_yz)^2) - (2*((cos(theta_xz)*(Bx - Vx))/Sx + (sin(theta_xz)*sin(theta_yz)*(Vy - By + (Sy*sin(theta_xy)*(Bx - Vx))/Sx))/(Sy*cos(theta_xy)))*((Bz - Vz)/Sz - (sin(theta_xz)*(Bx - Vx))/Sx + (cos(theta_xz)*sin(theta_yz)*(Vy - By + (Sy*sin(theta_xy)*(Bx - Vx))/Sx))/(Sy*cos(theta_xy))))/(cos(theta_xz)^2*cos(theta_yz)^2); % df/d theta_xz
    term_9 = (2*sin(theta_yz)*((Bz - Vz)/Sz - (sin(theta_xz)*(Bx - Vx))/Sx + (cos(theta_xz)*sin(theta_yz)*(Vy - By + (Sy*sin(theta_xy)*(Bx - Vx))/Sx))/(Sy*cos(theta_xy)))^2)/(cos(theta_xz)^2*cos(theta_yz)^3) + (2*((Bz - Vz)/Sz - (sin(theta_xz)*(Bx - Vx))/Sx + (cos(theta_xz)*sin(theta_yz)*(Vy - By + (Sy*sin(theta_xy)*(Bx - Vx))/Sx))/(Sy*cos(theta_xy)))*(Vy - By + (Sy*sin(theta_xy)*(Bx - Vx))/Sx))/(Sy*cos(theta_xy)*cos(theta_xz)*cos(theta_yz)); % df/d theta_yz

    A(i_row, :) = [term_1 term_2 term_3 term_4 term_5 term_6 term_7 term_8 term_9];

end

end