WUT_Computer_Science/NotProgramming/ENUME/projectC/sections/11-task2-m.tex
Krzysztof kuhy Rudnicki ffa5dad02a Split 19 over-cap LaTeX reports, proving each PDF is unchanged
The 250-line cap applies to prose too, and the reports were the worst
offenders -- ENUME's projectA.tex alone was 1,876 lines. Each is now a
preamble plus one \input{} per section, which is how a long LaTeX document is
normally organised; not one byte of prose was rewritten.

"The PDF is unchanged" is checked by a script rather than by eye, because
hashing the PDF cannot work: pdflatex stamps a /CreationDate and an /ID into
every build, so two runs of the SAME source already differ. tex_fingerprint.sh
compares what a reader sees instead -- page count plus a hash of the extracted
text -- and it is stable across rebuilds of untouched sources, which is the
property that makes it usable as a gate.

It earned its keep immediately. Both ECOTE reports quote an example LaTeX
document inside an lstlisting block, so \end{document} appears in the middle
of the file; splitting on the FIRST one stranded everything after it. Same
page count, different text, caught automatically. EOPSY lab3 exposed a second
bug: a \section{} title that runs onto the next line.

Result: 19 .tex over the cap -> 1. The survivor,
ELAC/.../03-building-nfa-...tex, is 418 lines of consecutive tikz figures
with no subsection to split on and needs a hand-placed boundary.

Verified: 29 splits across two passes (section, then subsection for the
pieces still over), every one reporting `unchanged` from
scripts/tex_fingerprint.sh --check.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0172dj34FDpao6wsix8ZuCzE
2026-08-28 19:47:12 +02:00

178 lines
5.4 KiB
TeX

\section{task2.m}
\subsection{task2}
\begin{simplechar}
\begin{lstlisting}
function task2()
[ordinaryDifferentialEquations, initialValues, interval, algorithms] = initialize();
solveAndPrintODEs(algorithms, ordinaryDifferentialEquations, initialValues, interval);
[result, sizes, errors] = solveAndPlotODEAutomatic(ordinaryDifferentialEquations, initialValues, interval);
plotStatistics(result, sizes, errors);
plotComparisonToMatlabFunction(ordinaryDifferentialEquations, interval, initialValues);
end
\end{lstlisting}
\end{simplechar}
\subsection{initialize}
\begin{simplechar}
\begin{lstlisting}
function [ordinaryDifferentialEquations, initialValues, interval, algorithms] = initialize()
ordinaryDifferentialEquations = {
@(x) x(2) + x(1) * (0.5 - x(1)^2 - x(2)^2);
@(x) -x(1) + x(2) * (0.5 - x(1)^2 - x(2)^2)
};
initialValues = [8; 9];
interval = [0; 15];
algorithms = {
'RK4 algorithm', @RK4, [0.01, 0.011];
'Adams PC algorithm', @AdamsPCMethod, [0.002, 0.013]
};
end
\end{lstlisting}
\end{simplechar}
\subsection{solveAndPrintODEs}
\begin{simplechar}
\begin{lstlisting}
function solveAndPrintODEs(algorithms, ordinaryDifferentialEquations, initialValues, interval)
for algorithm = 1 : 2
[algorithmName, algorithmFunction, stepSizes] = algorithms{algorithm, :};
stepResults = solveForEachStep(stepSizes, ordinaryDifferentialEquations, initialValues, interval, algorithmFunction);
plotAgainstTime(ordinaryDifferentialEquations, algorithmName, stepResults);
plotAgainst(algorithmName, stepResults);
end
end
\end{lstlisting}
\end{simplechar}
\subsection{solveForEachStep}
\begin{simplechar}
\begin{lstlisting}
function stepResults = solveForEachStep(stepSizes, ordinaryDifferentialEquations, initialValues, interval, algorithmFunction)
stepResults = cell(size(stepSizes, 2), 3);
stepNames = {'Optimal Step Size', 'Slightly Larger Step Size'};
for stepNumber = 1:size(stepSizes, 2)
result = algorithmFunction(ordinaryDifferentialEquations, initialValues, interval, stepSizes(stepNumber));
stepResults(stepNumber, :) = {stepSizes(stepNumber), stepNames{stepNumber}, result};
end
end
\end{lstlisting}
\end{simplechar}
\subsection{beginPlot}
\begin{simplechar}
\begin{lstlisting}
function beginPlot()
figure;
grid on;
hold on;
end
\end{lstlisting}
\end{simplechar}
\subsection{plotAgainstTime}
\begin{simplechar}
\begin{lstlisting}
function plotAgainstTime(ordinaryDifferentialEquations, algorithmName, stepResults)
for equationNumber = 1:size(ordinaryDifferentialEquations, 1)
beginPlot();
title([algorithmName, ', x_', num2str(equationNumber), ' ODE']);
for stepresult = stepResults'
plot(stepresult{3}(1, :), stepresult{3}(equationNumber + 1, :));
end
hold off;
legend(stepResults{:, 2});
end
end
\end{lstlisting}
\end{simplechar}
\subsection{plotAgainst}
\begin{simplechar}
\begin{lstlisting}
function plotAgainst(algorithmName, stepResults)
beginPlot();
title([algorithmName, ' trajectory plot (x_2 compared to x_1)']);
for stepresult = stepResults'
plot(stepresult{3}(2, :), stepresult{3}(3, :));
end
hold off;
legend(stepResults{:, 2});
% %print(['report/', func2str(algfunc), 'traj'], '-dpdf');
end
\end{lstlisting}
\end{simplechar}
\subsection{solveAndPlotODEAutomatic}
\begin{simplechar}
\begin{lstlisting}
function [result, sizes, errors] = solveAndPlotODEAutomatic(ordinaryDifferentialEquations, initialValues, interval)
[result, sizes, errors] = solveRKAutomatic(ordinaryDifferentialEquations, initialValues, interval);
plotTrajectory(result);
end
\end{lstlisting}
\end{simplechar}
\subsection{solveRKAutomatic}
\begin{simplechar}
\begin{lstlisting}
function [result, sizes, errors] = solveRKAutomatic(ordinaryDifferentialEquations, initialValues, interval)
initialStepSize = 1e-5;
relativeEpsilon = 1e-9;
absoluteEpsilon = 1e-9;
[result, sizes, errors] = RK4Automatic(ordinaryDifferentialEquations, initialValues, interval, initialStepSize, relativeEpsilon, absoluteEpsilon);
end
\end{lstlisting}
\end{simplechar}
\subsection{plotTrajectory}
\begin{simplechar}
\begin{lstlisting}
function plotTrajectory(result)
figure;
plot(result(2, :), result(3, :));
grid on;
title('RK4 with auto step trajectory plot (x_2 against x_1)');
end
\end{lstlisting}
\end{simplechar}
\subsection{plotStatistics}
\begin{simplechar}
\begin{lstlisting}
function plotStatistics(result, sizes, errors)
stats = {
"RK4 with auto step step size", "rk4sizes", sizes;
"RK4 with auto step approximation error", "rk4errors", errors
};
for stat = stats'
figure;
plot(result(1, 2:(end - 1)), stat{3});
grid on;
title(stat{1});
end
end
\end{lstlisting}
\end{simplechar}
\subsection{plotComparisonToMatlabFunction}
\begin{simplechar}
\begin{lstlisting}
function plotComparisonToMatlabFunction(ordinaryDifferentialEquations, interval, initialValues)
% compare results with ODE45
odefun = @(t, x) [ ordinaryDifferentialEquations{1}(x); ordinaryDifferentialEquations{2}(x) ];
odeoptions = odeset('RelTol', 10e-10, 'AbsTol', 10e-10);
[~, x] = ode45(odefun, interval, initialValues, odeoptions);
figure;
plot(x(:, 1), x(:, 2));
grid on;
title('ODE45 trajectory plot (x_2 against x_1)');
end
\end{lstlisting}
\end{simplechar}