

function [Em_plus, Em_minus] = compute_Em(Omega0, QE, SDS, D)
% compute_Em
% Computes amplified seismic load effects per ASCE 7:
% Em = Omega0 * QE ± 0.2 * SDS * D
%
% Inputs:
%   Omega0 : Overstrength factor
%   QE     : Seismic force from analysis (scalar or vector)
%   SDS    : Design spectral acceleration (scalar)
%   D      : Dead load (same size as QE or scalar)
%
% Outputs:
%   Em_plus  : Em with +0.2*SDS*D
%   Em_minus : Em with -0.2*SDS*D
%
% Notes:
% - Supports vectorized inputs for QE and D
% - Automatically expands scalars where appropriate

    % --- Input validation ---
    if nargin < 4
        error('compute_Em requires 4 inputs: Omega0, QE, SDS, D');
    end

    % Ensure inputs are numeric
    if ~isnumeric(Omega0) || ~isnumeric(QE) || ~isnumeric(SDS) || ~isnumeric(D)
        error('All inputs must be numeric.');
    end

    % --- Core calculation ---
    Em_base = Omega0 .* QE;
    vertical_term = 0.2 .* SDS .* D;

    Em_plus  = Em_base + vertical_term;
    Em_minus = Em_base - vertical_term;

end