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: ValueFnIter_Case1_FHorz_GulPesendorfer_nod_noz_raw.m
    path of file: ./repos/VFIToolkit-matlab/ValueFnIter/FHorz/ExoticPrefs/GulPesendorfer
    
    the code of the file until where you have to start completion: function [V, Policy]=ValueFnIter_Case1_FHorz_GulPesendorfer_nod_noz_raw(n_a,N_j, a_grid, ReturnFn, TemptationFn, Parameters, DiscountFactorParamNames, ReturnFnParamNames, TemptationFnParamNames, vfoptions)

N_a=prod(n_a);

V=zeros(N_a,N_j,'gpuArray');
Policy=zeros(N_a,N_j,'gpuArray'); %first dim indexes the optimal choice for aprime rest of dimensions a,z

%%
a_grid=gpuArray(a_grid);

if vfoptions.lowmemory==1
    special_n_a=ones(1,length(n_a));
    a_gridvals=CreateGridvals(n_a,a_grid,1); % The 1 at end indicates want output in form of matrix.
end

%% j=N_j

% Create a vector containing all the return function parameters (in order)
ReturnFnParamsVec=CreateVectorFromParams(Parameters, ReturnFnParamNames, N_j);
TemptationFnParamsVec=CreateVectorFromParams(Parameters, TemptationFnParamNames, N_j);

if ~isfield(vfoptions,'V_Jplus1')
    if vfoptions.lowmemory==0

        ReturnMatrix=CreateReturnFnMatrix_Case1_Disc_noz_Par2(ReturnFn, 0, n_a, 0, a_grid, ReturnFnParamsVec,0);

        TemptationMatrix=CreateReturnFnMatrix_Case1_Disc_noz_Par2(TemptationFn, 0, n_a, 0, a_grid, TemptationFnParamsVec,0);
        MostTempting=max(TemptationMatrix,[],1);
        entireRHS=ReturnMatrix+TemptationMatrix-ones(N_a,1).*MostTempting;

        %Calc the max and it's index
     
    
function parameters (in order)
    ReturnFnParamsVec=CreateVectorFromParams(Parameters, ReturnFnParamNames,jj);
    TemptationFnParamsVec=CreateVectorFromParams(Parameters, TemptationFnParamNames,jj);
    DiscountFactorParamsVec=CreateVectorFromParams(Parameters, DiscountFactorParamNames,jj);
    DiscountFactorParamsVec=prod(DiscountFactorParamsVec);

    
    VKronNext_j=V(:,jj+1);
    
    if vfoptions.lowmemory==0
        %if vfoptions.returnmatrix==2 % GPU
        ReturnMatrix=CreateReturnFnMatrix_Case1_Disc_noz_Par2(ReturnFn, 0, n_a, 0, a_grid, ReturnFnParamsVec,0);

        TemptationMatrix=CreateReturnFnMatrix_Case1_Disc_noz_Par2(TemptationFn, 0, n_a, 0, a_grid, TemptationFnParamsVec,0);
        MostTempting=max(TemptationMatrix,[],1);
        entireRHS=ReturnMatrix+TemptationMatrix-ones(N_a,1).*MostTempting+DiscountFactorParamsVec*VKronNext_j; %.*ones(1,N_a);
        
        %Calc the max and it's index
        [Vtemp,maxindex]=max(entireRHS,[],1);

        V(:,jj)=shiftdim(Vtemp,1);
        Policy(:,jj)=shiftdim(maxindex,1);
        
    elseif vfoptions.lowmemory==1
        for a_c=1:N_a
            a_val=a_gridvals(a_c,:);
            ReturnMatrix_a=CreateReturnFnMatrix_Case1_Disc_noz_Par2(ReturnFn, 0, special_n_a, 0, a_val, ReturnFnParamsVec,0);

            TemptationMatrix_a=CreateReturnFnMatrix_Case1_Disc_noz_Par2(TemptationFn, 0, special_n_a, 0, a_val, TemptationFnParamsVec,0);
            MostTempting_a=max(TemptationMatrix_a,[],1);
            entireRHS_a=ReturnMatrix_a+TemptationMatrix_a-ones(N_a,1).*MostTempting_a+DiscountFactorParamsVec*VKronNext_j;

            %Calc the max and it's index
            [Vtemp,maxindex]=max(entireRHS_a);
            V(a_c,jj)=Vtemp;
            Policy(a_c,jj)=maxindex;
        end