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: spm_ness_flows.m
    path of file: ./repos/spm
    
    the code of the file until where you have to start completion: function spm_ness_flows(P,x,M)
% Nonequilibrium steady-state under a Helmholtz decomposition
% FORMAT spm_ness_flows(M,x)
%--------------------------------------------------------------------------
% M   - model specification structure
% Required fields:
%    M.X  - sample points
%    M.W  - (n x n) - precision matrix of random fluctuations
%    M.K  - order of polynomial expansion
%__________________________________________________________________________

% Karl Friston
% Copyright (C) 2008-2022 Wellcome Centre for Human Neuroimaging

                
% evaluate flows at sample points 
%--------------------------------------------------------------------------

    
function spm_ness_flows(P,x,M)
% Nonequilibrium steady-state under a Helmholtz decomposition
% FORMAT spm_ness_flows(M,x)
%--------------------------------------------------------------------------
% M   - model specification structure
% Required fields:
%    M.X  - sample points
%    M.W  - (n x n) - precision matrix of random fluctuations
%    M.K  - order of polynomial expansion
%__________________________________________________________________________

% Karl Friston
% Copyright (C) 2008-2022 Wellcome Centre for Human Neuroimaging

                
% evaluate flows at sample points 
%--------------------------------------------------------------------------
X     = spm_ndgrid(x);                   % get sample points
X     = X';
n     = numel(x);
f1    = X;
f2    = X;
f3    = X;
for i = 1:size(X,2)
    M.X     = X(:,i)';
    [F,S,Q,L,H,D] = spm_NESS_gen(P,M);
    Q       = reshape(cat(1,Q{:}),n,n);
    D       = cat(1,D{:});
    G       = diag(diag(Q));
    Q       = Q - G;
    
    f1(:,i) = G*D;
    f2(:,i) = Q*D;
    f3(:,i) = -L';
end