function [f_EKF,JacFx,h_EKF,JacHx,JacAx,JacBu,JacJx,JacJu] = prepareAEKF(diff,x_var,d_var,u_var,y_var,par,L)

import casadi.*

nx = numel(x_var);
nd = numel(d_var);

diff_EKF= [];

    for i = 1:nx
        diff_EKF = [diff_EKF; x_var(i) + par.Ts*diff(i)];
    end
   for i = 1:nd
        diff_EKF = [diff_EKF; d_var(i)];
    end
    
    x_EKF = vertcat(x_var,d_var);
    
    f_EKF = Function('f_EKF',{x_EKF,u_var},{diff_EKF},{'x','p'},{'xdot'});
    JacFx = Function('JacFx',{x_EKF,u_var},{jacobian(diff_EKF,x_EKF)});
    
    h_EKF = Function('h_EKF',{x_EKF,u_var},{y_var});
    JacHx = Function('JacHx',{x_EKF,u_var},{jacobian(y_var,x_EKF)});
    
    p_var = vertcat(u_var,d_var);
    JacAx = Function('JacAx',{x_var,p_var},{jacobian(diff,x_var)});
    JacBu = Function('JacBu',{x_var,p_var},{jacobian(diff,u_var)});
    JacJx = Function('JacJx',{x_var,p_var},{jacobian(L,x_var)});
    JacJu = Function('JacJu',{x_var,p_var},{jacobian(L,u_var)});
    


