Files
equation-solver/Makefile
T
Andre Neto d547f2fc28 Make the solvers run and be tested under Octave
The project is MATLAB coursework and had never been run outside MATLAB. Two
things stop it in Octave, both found by running it rather than reading it:

  * newtonr.m called sym/matlabFunction unconditionally. Octave has no
    matlabFunction, so the file died before the first iteration with
    "'sym' undefined near line 12, column 5". The derivative is now taken
    from the Symbolic Math Toolbox when it is there and from a central
    difference otherwise. The method and its results are unchanged: on the
    test functions the numeric derivative agrees with the analytic one to
    2.3e-16 or better.
  * secant.m and newtonr.m built plot labels with "a" + i + "b". A
    double-quoted literal is a char array in Octave, not a string, so the
    addition became numeric and secant.m stopped at line 58 with
    "operator +: nonconformant arguments (op1 is 1x10, op2 is 1x2)". The
    labels are now built by concatenation and the text is identical.

No mathematics was changed. The defects that were found are left in place and
documented instead: tab = (max) is not a preallocation, newtonr returns
without assigning x1 when f'(x0) == 0, secant rejects an interval without a
sign change, and none of the three reports exhaustion of the iteration cap.

Added so the behaviour can be checked instead of asserted:

  * tests/run_tests.m - 13 checks against roots known analytically, solvers
    called at tol=1e-10, assertion tolerance 1e-6, exit 1 on any failure
  * a Makefile with test, demo, run and clean, and tests/demo.m
  * README.md in the house format; README.txt is kept as the original note
  * .gitignore for MATLAB autosave files and the captured plot output

Verified on the raspberry pi with Octave 9.4.0: make test reports 13 checks,
0 failures and exits 0, and a deliberately wrong expected root gives exit 1.
projetodlg.m was not made to run under Octave: it is built from MathWorks
dialogs and needs a display.
2026-10-08 14:54:36 +01:00

39 lines
1.2 KiB
Makefile

# equation-solver - run the solvers and the test suite.
#
# make test run tests/run_tests.m under Octave (exit 0 = pass, 1 = fail)
# make demo solve x^3-1 = 0 with the three methods, prints the numbers
# make run start the dialog interface projetodlg (needs a display)
# make clean delete the captured plot output
#
# The solvers plot the function while they iterate, so Octave needs a graphics
# toolkit. On a machine with no display, install gnuplot-nox and
# fonts-freefont-otf; the scripts then create the figure invisible and the
# Makefile captures what gnuplot renders in tests/.last-run.log.
SHELL := /bin/bash
OCTAVE ?= octave-cli
LOG := tests/.last-run.log
.PHONY: help test demo run clean
help:
@echo "make test run the Octave test suite (tests/run_tests.m)"
@echo "make demo solve x^3-1 = 0 with the three methods, no window needed"
@echo "make run start the dialog interface projetodlg (needs a display)"
@echo "make clean delete tests/.last-run.log"
test:
@$(OCTAVE) --no-gui tests/run_tests.m 1>$(LOG); \
rc=$$?; \
if [ $$rc -ne 0 ]; then echo "(plot output kept in $(LOG))" >&2; fi; \
exit $$rc
demo:
@$(OCTAVE) --no-gui tests/demo.m 1>$(LOG)
run:
@$(OCTAVE) --no-gui projetodlg.m
clean:
rm -f $(LOG)