function plot_pke_results(t, X, U, plant, Q_sg, plot_title) % PLOT_PKE_RESULTS Standard 4-panel plot of PKE + T/H simulation results. % % Inputs: % t - time vector from ODE solver % X - state matrix (M x 10): [n, C1..C6, T_f, T_c, T_cold] % U - control input trajectory (M x 1): scalar u at each time % plant - parameter struct from pke_params() % Q_sg - function handle Q_sg(t) used in the simulation % plot_title - (optional) string used in the figure name and first subplot if nargin < 6 || isempty(plot_title) plot_title = 'PKE + T/H closed-loop'; end % --- Extract states --- n = X(:, 1); T_f = X(:, 8); T_c = X(:, 9); T_cold = X(:, 10); T_hot = 2 * T_c - T_cold; % --- Convert temperatures to Fahrenheit for display --- CtoF = @(T) T * 9/5 + 32; T_f_F = CtoF(T_f); T_c_F = CtoF(T_c); T_cold_F = CtoF(T_cold); T_hot_F = CtoF(T_hot); % --- Derived quantities --- power_MW = n * plant.P0 / 1e6; Q_sg_MW = arrayfun(Q_sg, t) / 1e6; rho_fb = plant.alpha_f * (T_f - plant.T_f0) + plant.alpha_c * (T_c - plant.T_c0); rho_tot = U + rho_fb; % --- Plot --- figure('Position', [100 50 1000 950], 'Name', plot_title); % Power & SG demand subplot(4, 1, 1); plot(t, power_MW, 'b-', 'LineWidth', 1.5); hold on; plot(t, Q_sg_MW, 'r--', 'LineWidth', 1.2); xlabel('Time [s]'); ylabel('Power [MW_{th}]'); legend('Reactor Power', 'Q_{sg}', 'Location', 'east'); title(sprintf('%s — Power and SG Heat Demand', plot_title)); grid on; % Reactivity: controller u, feedback, total subplot(4, 1, 2); plot(t, U / plant.beta, 'k-', 'LineWidth', 1.5); hold on; plot(t, rho_fb / plant.beta, 'b-.', 'LineWidth', 1.2); plot(t, rho_tot / plant.beta, 'm:', 'LineWidth', 1.5); xlabel('Time [s]'); ylabel('\rho [$]'); legend('u (controller)', 'Feedback', 'Total', 'Location', 'east'); title('Reactivity'); grid on; % Coolant temperatures subplot(4, 1, 3); plot(t, T_hot_F, 'r-', 'LineWidth', 1.5); hold on; plot(t, T_c_F, 'm--', 'LineWidth', 1.2); plot(t, T_cold_F, 'b-', 'LineWidth', 1.5); xlabel('Time [s]'); ylabel('Temperature [F]'); legend('T_{hot}', 'T_{avg}', 'T_{cold}', 'Location', 'east'); title('Coolant Temperatures'); grid on; % Fuel temperature subplot(4, 1, 4); plot(t, T_f_F, 'Color', [0.85 0.33 0.1], 'LineWidth', 1.5); xlabel('Time [s]'); ylabel('Temperature [F]'); title('Fuel Temperature'); grid on; end