WUT_Computer_Science/NotProgramming/ENUME/projectC/sections/15-rk4automatic-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

160 lines
5.6 KiB
TeX

\section{RK4Automatic.m}
\subsection{RK4Automatic}
\begin{simplechar}
\begin{lstlisting}
function [x, sizes, errors] = RK4Automatic(equations, initialValues, interval, initialStepSize, relativeEpsilon, absoluteEpsilon)
[functionArguments, x, sizes, errors, stepSize, step, flag] = Initialize(interval, initialValues, initialStepSize);
[functionArguments, x, sizes, errors] = RK4AutomaticLoop(functionArguments, x, sizes, errors, stepSize, step, equations, relativeEpsilon, absoluteEpsilon, interval, flag);
x = [functionArguments; x];
end
\end{lstlisting}
\end{simplechar}
\subsection{Initialize}
\begin{simplechar}
\begin{lstlisting}
function [functionArguments, x, sizes, errors, stepSize, step, flag] = Initialize(interval, initialValues, initialStepSize)
functionArguments = interval(1);
x = initialValues;
sizes = double.empty();
errors = double.empty();
stepSize = initialStepSize;
step = 0;
flag = 1;
end
\end{lstlisting}
\end{simplechar}
\subsection{RK4AutomaticLoop}
\begin{simplechar}
\begin{lstlisting}
function [functionArguments, x, sizes, errors] = RK4AutomaticLoop(functionArguments, x, sizes, errors, stepSize, step, equations, relativeEpsilon, absoluteEpsilon, interval, flag)
while flag
[functionArguments, x, sizes, errors, stepSize, step, interval, flag] = insideWhileLoop(functionArguments, x, sizes, errors, stepSize, step, equations, relativeEpsilon, absoluteEpsilon, interval, flag);
end
end
\end{lstlisting}
\end{simplechar}
\subsection{insideWhileLoop}
\begin{simplechar}
\begin{lstlisting}
function [functionArguments, x, sizes, errors, stepSize, step, interval, flag] = insideWhileLoop(functionArguments, x, sizes, errors, stepSize, step, equations, relativeEpsilon, absoluteEpsilon, interval, flag)
[step, stepValue, x, functionArguments, flag] = calculateXandFunctionArguments(step, x, equations, stepSize, functionArguments, interval);
if ~flag
return;
end
[stepSize, errors] = calculateStepAndErrors(equations, stepValue, stepSize, x, step, relativeEpsilon, absoluteEpsilon, errors);
sizes(step) = stepSize;
end
\end{lstlisting}
\end{simplechar}
\subsection{calculateXandFunctionArguments}
\begin{simplechar}
\begin{lstlisting}
function [step, stepValue, x, functionArguments, flag] = calculateXandFunctionArguments(step, x, equations, stepSize, functionArguments, interval)
[step, stepValue] = initializeSteps(step, x);
x = equationsLoop(x, equations, stepValue, stepSize, step);
[flag, functionArguments] = stopAlgorithm(functionArguments, stepSize, step, interval);
end
\end{lstlisting}
\end{simplechar}
\subsection{calculateStepAndErrors}
\begin{simplechar}
\begin{lstlisting}
function [stepSize, errors] = calculateStepAndErrors(equations, stepValue, stepSize, x, step, relativeEpsilon, absoluteEpsilon, errors)
stepValue = calculateNextStep(equations, stepValue, stepSize);
[stepCorrectionFactor, errors] = calculateStepCorrection(stepValue, x, step, relativeEpsilon, absoluteEpsilon, errors);
stepSize = 0.9 * stepCorrectionFactor * stepSize;
end
\end{lstlisting}
\end{simplechar}
\subsection{initializeSteps}
\begin{simplechar}
\begin{lstlisting}
function [step, stepValue] = initializeSteps(step, x)
step = step + 1;
stepValue = x(:, step);
end
\end{lstlisting}
\end{simplechar}
\subsection{equationsLoop}
\begin{simplechar}
\begin{lstlisting}
function x = equationsLoop(x, equations, stepValue, stepSize, step)
for equationNumber = 1 : 2
Phi = RK4Phi(equations{equationNumber}, stepValue, stepSize);
x(equationNumber, step + 1) = x(equationNumber, step) + stepSize * Phi;
end
end
\end{lstlisting}
\end{simplechar}
\subsection{stopAlgorithm}
\begin{simplechar}
\begin{lstlisting}
function [flag, functionArguments] = stopAlgorithm(functionArguments, stepSize, step, interval)
functionArguments(step + 1) = functionArguments(step) + stepSize;
if functionArguments(end) >= interval(2)
flag = 0;
else
flag = 1;
end
end
\end{lstlisting}
\end{simplechar}
\subsection{calculateNextStep}
\begin{simplechar}
\begin{lstlisting}
function stepValue = calculateNextStep(equations, stepValue, stepSize)
for halfStep = 1 : 2
for equationsNumber = 1:size(equations, 1)
Phi = RK4Phi(equations{equationsNumber}, stepValue, stepSize / 2);
stepValue(equationsNumber) = stepValue(equationsNumber) + (stepSize / 2) * Phi;
end
end
end
\end{lstlisting}
\end{simplechar}
\subsection{calculateStepCorrection}
\begin{simplechar}
\begin{lstlisting}
function [stepCorrectionFactor, errors] = calculateStepCorrection(stepValue, x, step, relativeEpsilon, absoluteEpsilon, errors)
stepCorrectionFactor = Inf; % Initialize stepCorrectionFactor
[stepCorrectionFactor, errors] = calculateStepCorrectionLoop(stepValue, x, step, relativeEpsilon, absoluteEpsilon, errors, stepCorrectionFactor);
stepCorrectionFactor = stepCorrectionFactor ^ (1/5);
end
\end{lstlisting}
\end{simplechar}
\subsection{calculateStepCorrectionLoop}
\begin{simplechar}
\begin{lstlisting}
function [stepCorrectionFactor, errors] = calculateStepCorrectionLoop(stepValue, x, step, relativeEpsilon, absoluteEpsilon, errors, stepCorrectionFactor)
for equationsNumber = 1 : 2
approximationError = abs(stepValue(equationsNumber) - x(equationsNumber, step + 1)) / 15;
errors(step) = approximationError;
epsilon = abs(stepValue(equationsNumber)) * relativeEpsilon + absoluteEpsilon;
equationAlpha = epsilon / approximationError;
if equationAlpha < stepCorrectionFactor
stepCorrectionFactor = equationAlpha;
end
end
end
\end{lstlisting}
\end{simplechar}