function sol = NewtonMethod(f_n1_trial,chi_n,delta_t,C)

% This function solves the nonlinear scalar equation of the plastic
% multiplier (gamma) at time n+1 by means of the Newton-Raphson method, 
% setting the initial value of gamma at zero, and making use of a given
% tolerance

E = C(1) ;
K = C(3) ;
H = C(4) ;
my = C(11) ;
eta = C(6) ;
sigma_y = C(5) ;
sigma_inf = C(7) ;
delta = C(8) ;

% Inputs a maximum number of iterations to avoid overflow
N = 10 ;
% Inputs a tolerance value to check the residual at every iteration step
tol = 1e-5 ;
% Initializes iteration counter and plastic multiplier
counter = 0 ;
gamma_n1 = 0 ;
g = f_n1_trial - gamma_n1 * delta_t * (2*my + 2/3*H + eta/delta_t) - sqrt(2/3)*(diff_potential(chi_n + gamma_n1*delta_t*sqrt(2/3),sigma_inf,sigma_y,delta,K) - diff_potential(chi_n,sigma_inf,sigma_y,delta,K)) ;

% Initializes iteration process
while abs(g) >= tol && counter < N
    delta_g = - (2*my + 2/3*diff2_potential(chi_n + gamma_n1*delta_t*sqrt(2/3),sigma_inf,sigma_y,delta,K) + 2/3*H + eta/delta_t) * delta_t ;
    gamma_n1 = gamma_n1 - g/delta_g ;
    g = f_n1_trial - gamma_n1 * delta_t * (2*my + 2/3*H + eta/delta_t) - sqrt(2/3)*(diff_potential(chi_n + gamma_n1*delta_t*sqrt(2/3),sigma_inf,sigma_y,delta,K) - diff_potential(chi_n,sigma_inf,sigma_y,delta,K)) ;
    counter = counter + 1 ;   %Refreshes iteration counter
end

sol = gamma_n1 ;