WUT_Computer_Science/NotProgramming/ENUME/projectC/sections/10-task1-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

134 lines
3.7 KiB
TeX

\section{task1.m}
\subsection{task1}
\begin{simplechar}
\begin{lstlisting}
function task1(polynomialDegree)
for currentPolynomialDegree = 0 : polynomialDegree
dataPoints = functionDataPoints();
% obtain LSPSolutions of approximating polynomial
[LSPSolutions, error, conditionNumber] = approximate(dataPoints, currentPolynomialDegree);
displayInfo(currentPolynomialDegree, error, conditionNumber);
plotGraph(currentPolynomialDegree, dataPoints, LSPSolutions)
end
end
\end{lstlisting}
\end{simplechar}
\subsection{displayInfo}
\begin{simplechar}
\begin{lstlisting}
function displayInfo(currentPolynomialDegree, error, conditionNumber)
disp("Current Polynomial Degree:");
disp(currentPolynomialDegree);
disp("Error: ");
disp(error);
disp("Condition number of Gram's Matrix: ");
disp(conditionNumber);
end
\end{lstlisting}
\end{simplechar}
\subsection{plotGraph}
\begin{simplechar}
\begin{lstlisting}
function plotGraph(currentPolynomialDegree, dataPoints, LSPSolutions)
figure;
grid on;
hold on;
plotDataPoints(currentPolynomialDegree, dataPoints);
plotApproximation(dataPoints, LSPSolutions);
hold off;
end
\end{lstlisting}
\end{simplechar}
\subsection{plotDataPoints}
\begin{simplechar}
\begin{lstlisting}
function plotDataPoints(currentPolynomialDegree, dataPoints)
title(['Polynomial approximation of the funtion using: ', num2str(currentPolynomialDegree), ' degree']);
scatter(dataPoints(:, 1), dataPoints(:, 2), 72, 'x');
end
\end{lstlisting}
\end{simplechar}
\subsection{plotApproximation}
\begin{simplechar}
\begin{lstlisting}
function plotApproximation(dataPoints, LSPSolutions)
x = dataPoints(1):0.05:dataPoints(end, 1);
y = valueApproximationAtx(LSPSolutions, x);
plot(x, y);
end
\end{lstlisting}
\end{simplechar}
\subsection{approximate}
\begin{simplechar}
\begin{lstlisting}
% find the approximating polynomial of the given degree
function [LSPSolutions, error, conditionNumber] = approximate(dataPoints, polydeg)
% initialize A matrix
A = zeros(size(dataPoints, 1), polydeg + 1);
A = calculateACells(dataPoints, A);
LSPSolutions = solveLSP(A, dataPoints);
% Calculate error of solution
error = norm(dataPoints(:, 2) - A * LSPSolutions);
% Calculate condition number of Gram's matrix
GramsMatrix = A' * A;
conditionNumber = cond(GramsMatrix);
end
\end{lstlisting}
\end{simplechar}
\subsection{calculateACells}
\begin{simplechar}
\begin{lstlisting}
function Matrix = calculateACells(dataPoints, Matrix)
for row = 1 : size(Matrix, 1)
for column = 1 : size(Matrix, 2)
Matrix(row, column) = dataPoints(row, 1) ^ (column - 1);
end
end
end
\end{lstlisting}
\end{simplechar}
\subsection{solveLSP}
\begin{simplechar}
\begin{lstlisting}
function solutions = solveLSP(Matrix, dataPoints)
[Q, eqsys, invqtq] = QRDecomposition(Matrix);
eqsys(:, end + 1) = invqtq * Q' * dataPoints(:, 2);
solutions = backSubstitution(eqsys);
end
\end{lstlisting}
\end{simplechar}
\subsection{valueApproximationAtx}
\begin{simplechar}
\begin{lstlisting}
function arrayOfValues = valueApproximationAtx(LSPSolutions, arrayOfArguments)
arrayOfValues = zeros(1, size(arrayOfArguments, 2));
arrayOfValues = calculateArrayofValues(arrayOfArguments, arrayOfValues, LSPSolutions);
end
\end{lstlisting}
\end{simplechar}
\subsection{calculateArrayofValues}
\begin{simplechar}
\begin{lstlisting}
function arrayOfValues = calculateArrayofValues(arrayOfArguments, arrayOfValues, LSPSolutions)
for x = 1 : size(arrayOfArguments, 2)
for i = 1 : size(LSPSolutions, 1)
arrayOfValues(x) = arrayOfValues(x) + LSPSolutions(i) * arrayOfArguments(x) ^ (i - 1);
end
end
end
\end{lstlisting}
\end{simplechar}