You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: postprocess_part3.m
    path of file: ./repos/Isogeometric-Analysis/projects/phase_field/1d_brittle_fracture_alternating_alternative
    
    the code of the file until where you have to start completion: %--------------------------------------------------------------------------
%  Author: Isaac J. Lee (ijlee2@ices.utexas.edu)
%  
%  
%  Summary:
%  
%  This routine computes (1) the L2 errors between the analytical and FE
%  solutions of the displacement and phase fields, and (2) the strain,
%  surface, and potential energies at the last alternation step.
%  
%  
%  Instructions:
%  
%  Use the terminal to run the driver file with this command:
%  
%      ./matbg.sh driver_postprocess_part3.m output
%  
%  Note that,
%  
%      order is the order of the phase field theory (2, 4, 6, 8)
%      path_to_assembly_directory is the path to the assembly directory
%      path_to_results_directory is the path to the results directory
%      path_to_outputs_directory is the path to the plots directory
%  
%  
%  Output:
%  
%  1. Errors in the displacement and phase fields (.mat files)
%--------------------------------------------------------------------------
function postprocess_part3(order, path_to_assembly_directory, path_to_results_directory, path_to_outputs_directory)
    %----------------------------------------------------------------------
    %  Initialize the arrays
    %----------------------------------------------------------------------
    % Set the refinement levels
    numRefinements = [0; 1;
    
function = u2_der0^2;
                
                strain_energy_e = strain_energy_e + (w(q_e) * Jacobian * (degradation_function * 0.5 * constant_stiffness * u1_der1^2));
                
                
                %----------------------------------------------------------
                %  Evaluate the surface energy
                %----------------------------------------------------------
                switch order
                    case 2
                        crack_density = (1 - u2_der0)^2 + 4     * constant_ell_0_sq * u2_der1^2;
                        
                    case 4
                        crack_density = (1 - u2_der0)^2 + 2     * constant_ell_0_sq * u2_der1^2 +             constant_ell_0_sq^2 * u2_der2^2;
                        
                    case 6
                        crack_density = (1 - u2_der0)^2 + 27/16 * constant_ell_0_sq * u2_der1^2 + 243/256   * constant_ell_0_sq^2 * u2_der2^2 + 729/4096    * constant_ell_0_sq^3 * u2_der3^2;
                        
                    case 8
                        crack_density = (1 - u2_der0)^2 + 25/16 * constant_ell_0_sq * u2_der1^2 + 1875/2048 * constant_ell_0_sq^2 * u2_der2^2 + 15625/65536 * constant_ell_0_sq^3 * u2_der3^2 + 390625/16777216 * constant_ell_0_sq^4 * u2_der4^2;
                        
                end
                
                surface_energy_e = surface_energy_e + (w(q_e) * Jacobian * (constant_G_c * crack_density));
                
                
                %----------------------------------------------------------
                %  Evaluate the potential energy
                %----------------------------------------------------------
                potential_energy_e = strain_energy_e + surface_energy_e;
                
            end
            
            
            %--------------------------------------------------------------
            % -------------------------------------------------------------
            %   End: Loop over quadrature points
            % -------------------------------------------------------------
            %--------------------------------------------------------------
            
            
            %--------------------------------------------------------------
            %  Add the element contribution
            %--------------------------------------------------------------
            L2_error_u(i)       = L2_error_u(i)       + L2_error_u_e      ;
            L2_error_c(i)       = L2_error_c(i)       + L2_error_c_e      ;
            strain_energy(i)    = strain_energy(i)    + strain_energy_e   ;
            surface_energy(i)   = surface_energy(i)   + surface_energy_e  ;
            potential_energy(i) = potential_energy(i) + potential_energy_e;
        end