
function [alpha,u_num] = stoch_SL_scheme(f_fct,g_fct,sig_fct,b_fct,A_M,x_vec,t_vec)

% Explanations:

% I just look at x in R^N with N = 1.

% Functions:
% f_fct depends on t, alpha(t) and x
% g_fct depends on x
% sig_fct depends on t, alpha(t) and x
% b_fct depends on t, alpha(t) 

% Other inputs:
% A_M is a t_length times M matrix, which approximates A where the
% alpha function come from 
% x_vec: this is x_1,x_2,... the approximation of the x-domain
% T: t is in [0,T]
% t_vec: will approximate [0,T] with length t_length

alpha = 0; % change that
P = 1;
M = size(A_M,2);
x_length = length(x_vec);
t_length = length(t_vec);
T = t_vec(t_length);

   
u_tilde = zeros(1,length(x_vec));
u_new = u_tilde;
min = 0;
u_value = 0;
L_appr = 0;

for i = 1:x_length
    u_tilde(i) = g_fct(x_vec(i));
end

for m = 1:t_length-1
    u_new = zeros(1,x_length);
    for i = 1:x_length
        
        for k = 1:M
            
            
            L_appr = (1/((t_vec(m+1)-t_vec(m))*(P+1)))*...
                (interpol_operator(u_tilde,x_vec,x_vec(i) + (t_vec(m+1)-t_vec(m))*(P+1)*b_fct(t_vec(m),A_M(m,k))) - interpol_operator(u_tilde,x_vec,x_vec(i)));
            for j = 1:P % just one step, because to make it simple we assumed x in R
               L_appr = L_appr + (1/(2*(t_vec(m+1)-t_vec(m))*(P+1)))*...
                (interpol_operator(u_tilde,x_vec,x_vec(i) + sqrt((t_vec(m+1)-t_vec(m))*(P+1))*sig_fct(t_vec(m),A_M(m,k),x_vec(i))) - 2*interpol_operator(u_tilde,x_vec,x_vec(i)) + interpol_operator(u_tilde,x_vec,x_vec(i) + sqrt((t_vec(m+1)-t_vec(m))*(P+1))*sig_fct(t_vec(m),A_M(m,k),x_vec(i)))); 
            end
            
            u_value = u_tilde(i) +  f_fct(t_vec(m), A_M(m,k), x_vec(i))*(t_vec(m+1) - t_vec(m)) + ... 
             (t_vec(m+1)-t_vec(m))*(L_appr);
         
         if k == 1
             min = u_value;
         end
            
            if u_value < min
                min = u_value;
            end
            
            
        end
      u_new(i)=u_value;
        
        
    end
   
 u_tilde = u_new;
 
end

u_num = u_tilde;
end