function [] = make_all_partial_derivates_A_matrix()
%This function creates symbolix derivated with respect to all unknown
%parameters

    fx_d_o=derive_fx_d_o() %partial derivative of fx with respect to omega 
    fy_d_o=derive_fy_d_o() %partial derivative of fy with respect to omega
    fx_d_p=derive_fx_d_p() %partial derivative of fx with respect to phi
    fy_d_p=derive_fy_d_p() %partial derivative of fy with respect to phi
    fx_d_k=derive_fx_d_k() %partial derivative of fx with respect to kappa
    fy_d_k=derive_fy_d_k() %partial derivative of fy with respect to kappa
    fx_d_X0=derive_fx_d_X0() %partial derivative of fx with respect to X0
    fy_d_X0=derive_fy_d_X0() %partial derivative of fy with respect to X0
    fx_d_Y0=derive_fx_d_Y0() %partial derivative of fx with respect to Y0
    fy_d_Y0=derive_fy_d_Y0() %partial derivative of fy with respect to Y0
    fx_d_Z0=derive_fx_d_Z0() %partial derivative of fx with respect to Z0
    fy_d_Z0=derive_fy_d_Z0() %partial derivative of fy with respect to Z0
    
    %Writing the results as functions
    fileID = fopen('partial_derivatives_EO.m','w');
    fprintf(fileID,'function [fx_d_o] = make_fx_d_o(c,o,p,k,X0,Y0,Z0,X,Y,Z)\r\nfx_d_o=%s;\r\nend\r\n',char(fx_d_o)) 
    fprintf(fileID,'function [fy_d_o] = make_fy_d_o(c,o,p,k,X0,Y0,Z0,X,Y,Z)\r\nfy_d_o=%s;\r\nend\r\n',char(fy_d_o)) 
    fprintf(fileID,'function [fx_d_p] = make_fx_d_p(c,o,p,k,X0,Y0,Z0,X,Y,Z)\r\nfx_d_p=%s;\r\nend\r\n',char(fx_d_p)) 
    fprintf(fileID,'function [fy_d_p] = make_fy_d_p(c,o,p,k,X0,Y0,Z0,X,Y,Z)\r\nfy_d_p=%s;\r\nend\r\n',char(fy_d_p))
    fprintf(fileID,'function [fx_d_k] = make_fx_d_k(c,o,p,k,X0,Y0,Z0,X,Y,Z)\r\nfx_d_k=%s;\r\nend\r\n',char(fx_d_k)) 
    fprintf(fileID,'function [fy_d_k] = make_fy_d_k(c,o,p,k,X0,Y0,Z0,X,Y,Z)\r\nfy_d_k=%s;\r\nend\r\n',char(fy_d_k))
    fprintf(fileID,'function [fx_d_X0] = make_fx_d_X0(c,o,p,k,X0,Y0,Z0,X,Y,Z)\r\nfx_d_X0=%s;\r\nend\r\n',char(fx_d_X0)) 
    fprintf(fileID,'function [fy_d_X0] = make_fy_d_X0(c,o,p,k,X0,Y0,Z0,X,Y,Z)\r\nfy_d_X0=%s;\r\nend\r\n',char(fy_d_X0))
    fprintf(fileID,'function [fx_d_Y0] = make_fx_d_Y0(c,o,p,k,X0,Y0,Z0,X,Y,Z)\r\nfx_d_Y0=%s;\r\nend\r\n',char(fx_d_Y0)) 
    fprintf(fileID,'function [fy_d_Y0] = make_fy_d_Y0(c,o,p,k,X0,Y0,Z0,X,Y,Z)\r\nfy_d_Y0=%s;\r\nend\r\n',char(fy_d_Y0)) 
    fprintf(fileID,'function [fx_d_Z0] = make_fx_d_Z0(c,o,p,k,X0,Y0,Z0,X,Y,Z)\r\nfx_d_Z0=%s;\r\nend\r\n',char(fx_d_Z0)) 
    fprintf(fileID,'function [fy_d_Z0] = make_fy_d_Z0(c,o,p,k,X0,Y0,Z0,X,Y,Z)\r\nfy_d_Z0=%s;\r\nend\r\n',char(fy_d_Z0))
end

function [ fx_d_o ] = derive_fx_d_o()
%this function creates symbolic equation for partial derivative with respect
%to omega from the upper collinearity equation fx

%define a variables as symbols

syms o p k X0 Y0 Z0 c X Y Z;
syms r11 r12 r13 r21 r22 r23 r31 r32 r33;

r11=cos(p)*cos(k);
r12=cos(o)*sin(k)+sin(o)*sin(p)*cos(k);
r13=sin(o)*sin(k)-cos(o)*sin(p)*cos(k);
r21=-cos(p)*sin(k);
r22=cos(o)*cos(k)-sin(o)*sin(p)*sin(k);
r23=sin(o)*cos(k)+cos(o)*sin(p)*sin(k);
r31=sin(p);
r32=-sin(o)*cos(p);
r33=cos(o)*cos(p);

U=-c*r11*(X-X0)+r12*(Y-Y0)+r13*(Z-Z0);
W=r31*(X-X0)+r32*(Y-Y0)+r33*(Z-Z0);
fx=U/W;

fx_d_o=diff(fx,o);


end

function [ fy_d_o ] = derive_fy_d_o()
%this function crates symbolic equation for partial derivative with respect
%to omega from the upper collinearity equation fy
syms o p k X0 Y0 Z0 c X Y Z;
syms r11 r12 r13 r21 r22 r23 r31 r32 r33;

r11=cos(p)*cos(k);
r12=cos(o)*sin(k)+sin(o)*sin(p)*cos(k);
r13=sin(o)*sin(k)-cos(o)*sin(p)*cos(k);
r21=-cos(p)*sin(k);
r22=cos(o)*cos(k)-sin(o)*sin(p)*sin(k);
r23=sin(o)*cos(k)+cos(o)*sin(p)*sin(k);
r31=sin(p);
r32=-sin(o)*cos(p);
r33=cos(o)*cos(p);

V=-c*r21*(X-X0)+r22*(Y-Y0)+r23*(Z-Z0);
W=r31*(X-X0)+r32*(Y-Y0)+r33*(Z-Z0);
fy=V/W;

fy_d_o=diff(fy,o);


end

function [ fx_d_p ] = derive_fx_d_p()
%this function crates symbolic equation for partial derivative with respect
%to phi from the upper collinearity equation fx

syms o p k X0 Y0 Z0 c X Y Z;
syms r11 r12 r13 r21 r22 r23 r31 r32 r33;

r11=cos(p)*cos(k);
r12=cos(o)*sin(k)+sin(o)*sin(p)*cos(k);
r13=sin(o)*sin(k)-cos(o)*sin(p)*cos(k);
r21=-cos(p)*sin(k);
r22=cos(o)*cos(k)-sin(o)*sin(p)*sin(k);
r23=sin(o)*cos(k)+cos(o)*sin(p)*sin(k);
r31=sin(p);
r32=-sin(o)*cos(p);
r33=cos(o)*cos(p);

U=-c*r11*(X-X0)+r12*(Y-Y0)+r13*(Z-Z0);
W=r31*(X-X0)+r32*(Y-Y0)+r33*(Z-Z0);
fx=U/W;

fx_d_p=diff(fx,p)
end

function [ fy_d_p ] = derive_fy_d_p()
%this function crates symbolic equation for partial derivative with respect
%to phi from the upper collinearity equation fy

syms o p k X0 Y0 Z0 c X Y Z;
syms r11 r12 r13 r21 r22 r23 r31 r32 r33;

r11=cos(p)*cos(k);
r12=cos(o)*sin(k)+sin(o)*sin(p)*cos(k);
r13=sin(o)*sin(k)-cos(o)*sin(p)*cos(k);
r21=-cos(p)*sin(k);
r22=cos(o)*cos(k)-sin(o)*sin(p)*sin(k);
r23=sin(o)*cos(k)+cos(o)*sin(p)*sin(k);
r31=sin(p);
r32=-sin(o)*cos(p);
r33=cos(o)*cos(p);

V=-c*r21*(X-X0)+r22*(Y-Y0)+r23*(Z-Z0);
W=r31*(X-X0)+r32*(Y-Y0)+r33*(Z-Z0);
fy=V/W;

fy_d_p=diff(fy,p)
end

function [ fx_d_k ] = derive_fx_d_k()
%this function crates symbolic equation for partial derivative with respect
%to kappa from the upper collinearity equation fx

syms o p k X0 Y0 Z0 c X Y Z;
syms r11 r12 r13 r21 r22 r23 r31 r32 r33;

r11=cos(p)*cos(k);
r12=cos(o)*sin(k)+sin(o)*sin(p)*cos(k);
r13=sin(o)*sin(k)-cos(o)*sin(p)*cos(k);
r21=-cos(p)*sin(k);
r22=cos(o)*cos(k)-sin(o)*sin(p)*sin(k);
r23=sin(o)*cos(k)+cos(o)*sin(p)*sin(k);
r31=sin(p);
r32=-sin(o)*cos(p);
r33=cos(o)*cos(p);

U=-c*r11*(X-X0)+r12*(Y-Y0)+r13*(Z-Z0);
W=r31*(X-X0)+r32*(Y-Y0)+r33*(Z-Z0);
fx=U/W;

fx_d_k=diff(fx,k)
end

function [ fy_d_k ] = derive_fy_d_k()
%this function crates symbolic equation for partial derivative with respect
%to kappa from the upper collinearity equation fy

syms o p k X0 Y0 Z0 c X Y Z;
syms r11 r12 r13 r21 r22 r23 r31 r32 r33;

r11=cos(p)*cos(k);
r12=cos(o)*sin(k)+sin(o)*sin(p)*cos(k);
r13=sin(o)*sin(k)-cos(o)*sin(p)*cos(k);
r21=-cos(p)*sin(k);
r22=cos(o)*cos(k)-sin(o)*sin(p)*sin(k);
r23=sin(o)*cos(k)+cos(o)*sin(p)*sin(k);
r31=sin(p);
r32=-sin(o)*cos(p);
r33=cos(o)*cos(p);

V=-c*r21*(X-X0)+r22*(Y-Y0)+r23*(Z-Z0);
W=r31*(X-X0)+r32*(Y-Y0)+r33*(Z-Z0);
fy=V/W;

fy_d_k=diff(fy,k);
end

function [ fx_d_X0 ] = derive_fx_d_X0()
%this function crates symbolic equation for partial derivative with respect
%to X0 from the upper collinearity equation fx

syms o p k X0 Y0 Z0 c X Y Z;
syms r11 r12 r13 r21 r22 r23 r31 r32 r33;

r11=cos(p)*cos(k);
r12=cos(o)*sin(k)+sin(o)*sin(p)*cos(k);
r13=sin(o)*sin(k)-cos(o)*sin(p)*cos(k);
r21=-cos(p)*sin(k);
r22=cos(o)*cos(k)-sin(o)*sin(p)*sin(k);
r23=sin(o)*cos(k)+cos(o)*sin(p)*sin(k);
r31=sin(p);
r32=-sin(o)*cos(p);
r33=cos(o)*cos(p);

U=-c*r11*(X-X0)+r12*(Y-Y0)+r13*(Z-Z0);
W=r31*(X-X0)+r32*(Y-Y0)+r33*(Z-Z0);
fx=U/W;

fx_d_X0=diff(fx,X0)
end

function [ fy_d_X0 ] = derive_fy_d_X0()
%this function crates symbolic equation for partial derivative with respect
%to X0 from the upper collinearity equation fy

syms o p k X0 Y0 Z0 c X Y Z;
syms r11 r12 r13 r21 r22 r23 r31 r32 r33;

r11=cos(p)*cos(k);
r12=cos(o)*sin(k)+sin(o)*sin(p)*cos(k);
r13=sin(o)*sin(k)-cos(o)*sin(p)*cos(k);
r21=-cos(p)*sin(k);
r22=cos(o)*cos(k)-sin(o)*sin(p)*sin(k);
r23=sin(o)*cos(k)+cos(o)*sin(p)*sin(k);
r31=sin(p);
r32=-sin(o)*cos(p);
r33=cos(o)*cos(p);

V=-c*r21*(X-X0)+r22*(Y-Y0)+r23*(Z-Z0);
W=r31*(X-X0)+r32*(Y-Y0)+r33*(Z-Z0);
fy=V/W;

fy_d_X0=diff(fy,X0);
end

function [ fx_d_Y0 ] = derive_fx_d_Y0()
%this function crates symbolic equation for partial derivative with respect
%to Y0 from the upper collinearity equation fx


syms o p k X0 Y0 Z0 c X Y Z;
syms r11 r12 r13 r21 r22 r23 r31 r32 r33;

r11=cos(p)*cos(k);
r12=cos(o)*sin(k)+sin(o)*sin(p)*cos(k);
r13=sin(o)*sin(k)-cos(o)*sin(p)*cos(k);
r21=-cos(p)*sin(k);
r22=cos(o)*cos(k)-sin(o)*sin(p)*sin(k);
r23=sin(o)*cos(k)+cos(o)*sin(p)*sin(k);
r31=sin(p);
r32=-sin(o)*cos(p);
r33=cos(o)*cos(p);

U=-c*r11*(X-X0)+r12*(Y-Y0)+r13*(Z-Z0);
W=r31*(X-X0)+r32*(Y-Y0)+r33*(Z-Z0);
fx=U/W;

fx_d_Y0=diff(fx,Y0)
end

function [ fy_d_Y0 ] = derive_fy_d_Y0()
%this function crates symbolic equation for partial derivative with respect
%to Y0 from the upper collinearity equation fy

syms o p k X0 Y0 Z0 c X Y Z;
syms r11 r12 r13 r21 r22 r23 r31 r32 r33;

r11=cos(p)*cos(k);
r12=cos(o)*sin(k)+sin(o)*sin(p)*cos(k);
r13=sin(o)*sin(k)-cos(o)*sin(p)*cos(k);
r21=-cos(p)*sin(k);
r22=cos(o)*cos(k)-sin(o)*sin(p)*sin(k);
r23=sin(o)*cos(k)+cos(o)*sin(p)*sin(k);
r31=sin(p);
r32=-sin(o)*cos(p);
r33=cos(o)*cos(p);

V=-c*r21*(X-X0)+r22*(Y-Y0)+r23*(Z-Z0);
W=r31*(X-X0)+r32*(Y-Y0)+r33*(Z-Z0);
fy=V/W;

fy_d_Y0=diff(fy,Y0);
end

function [ fx_d_Z0 ] = derive_fx_d_Z0()
%this function crates symbolic equation for partial derivative with respect
%to Z0 from the upper collinearity equation fx

syms o p k X0 Y0 Z0 c X Y Z;
syms r11 r12 r13 r21 r22 r23 r31 r32 r33;

r11=cos(p)*cos(k);
r12=cos(o)*sin(k)+sin(o)*sin(p)*cos(k);
r13=sin(o)*sin(k)-cos(o)*sin(p)*cos(k);
r21=-cos(p)*sin(k);
r22=cos(o)*cos(k)-sin(o)*sin(p)*sin(k);
r23=sin(o)*cos(k)+cos(o)*sin(p)*sin(k);
r31=sin(p);
r32=-sin(o)*cos(p);
r33=cos(o)*cos(p);

U=-c*r11*(X-X0)+r12*(Y-Y0)+r13*(Z-Z0);
W=r31*(X-X0)+r32*(Y-Y0)+r33*(Z-Z0);
fx=U/W;

fx_d_Z0=diff(fx,Z0);
end

function [ fy_d_Z0 ] = derive_fy_d_Z0()
%this function crates symbolic equation for partial derivative with respect
%to Z0 from the upper collinearity equation fy

syms o p k X0 Y0 Z0 c X Y Z;
syms r11 r12 r13 r21 r22 r23 r31 r32 r33;

r11=cos(p)*cos(k);
r12=cos(o)*sin(k)+sin(o)*sin(p)*cos(k);
r13=sin(o)*sin(k)-cos(o)*sin(p)*cos(k);
r21=-cos(p)*sin(k);
r22=cos(o)*cos(k)-sin(o)*sin(p)*sin(k);
r23=sin(o)*cos(k)+cos(o)*sin(p)*sin(k);
r31=sin(p);
r32=-sin(o)*cos(p);
r33=cos(o)*cos(p);

V=-c*r21*(X-X0)+r22*(Y-Y0)+r23*(Z-Z0);
W=r31*(X-X0)+r32*(Y-Y0)+r33*(Z-Z0);
fy=V/W;

fy_d_Z0=diff(fy,Z0);
end
