%
%  enforced_motion_modal_transient_engine_fea_beam_alt_np.m  ver 1.3  by Tom Irvine
%

function[na,nx]=enforced_motion_modal_transient_engine_fea_beam_alt_np(FP,a1,a2,df1,df2,df3,af1,af2,af3,nt,num_modes)
%
% Preallocate outputs
nx = zeros(nt, num_modes);
na = zeros(nt, num_modes);

% Reusable coefficient arrays (avoid realloc each loop)
den = zeros(1,3);
num_d = zeros(1,3);
num_a = zeros(1,3);

for j = 1:num_modes

    % Access WITHOUT transposing FP
    amodal = FP(j, :).';   % small temporary (cheap vs full FP transpose)

    % Reuse arrays instead of reallocating
    den(1) = 1;
    den(2) = -a1(j);
    den(3) = -a2(j);

    num_d(1) = df1(j);
    num_d(2) = df2(j);
    num_d(3) = df3(j);

    num_a(1) = af1(j);
    num_a(2) = af2(j);
    num_a(3) = af3(j);

    % Filter directly into output
    nx(:, j) = filter(num_d, den, amodal);
    na(:, j) = filter(num_a, den, amodal);
end