Numerical Calculus: Newton–Raphson App & Validation
MATLAB App Designer Newton–Raphson project with safeguarded root finding, numerical validation, convergence analysis, initial-guess sensitivity, and explicit failure-mode diagnostics.
This project modernizes an archived MATLAB App Designer Newton–Raphson root-finding application. The original app is preserved as historical material, while a separate reproducible MATLAB runner audits the numerical behavior, validates the method against independent reference roots, and makes several failure modes explicit rather than hiding them behind a graphical interface.
The complete implementation, original App Designer files, and generated results are available here: GitHub repository
The packaged App Designer source implements first-order Newton–Raphson. An embedded historical screenshot contains additional tabs labelled “Newton-Raphson 2” and “Fulse-Position,” but those methods are not present in the packaged source code, so this public project does not claim them as implemented algorithms.
Original App Designer behavior
The recovered application accepts an equation entered as text, an initial guess, a repeat count, and an approximate-error threshold. It converts the equation to a symbolic expression, differentiates it, applies Newton updates, and displays the estimated root together with the function value.
| Source-derived UI setting | Default |
|---|---|
Initial guess, x0 | 1 |
| Repeat count | 3 |
| Error threshold | 0.05% |
| Displayed error metric | Ea = 100(xr − x0)/xr |
Safeguarded Newton implementation
The archived callback has no hard iteration cap, derivative-near-zero safeguard, finite-value test, real-domain check, or robust stopping rule for roots near zero. The public validation runner adds a maximum iteration count, derivative thresholding, residual-decreasing backtracking, domain checks, residual tolerance, and step-size tolerance while retaining the standard Newton update x(k+1) = x(k) − f(x(k))/f′(x(k)).
Validation functions
| Equation | Initial guess | Newton root | Final residual | Iterations |
|---|---|---|---|---|
x³ − x − 2 | 1.5 | 1.521379706805 | 4.530 × 10⁻¹⁴ | 3 |
cos(x) − x | 1.0 | 0.739085133215 | 0 | 4 |
exp(−x) − x | 0.5 | 0.567143290410 | 4.552 × 10⁻¹⁵ | 3 |
The resulting roots agree with independent MATLAB fzero reference solutions to approximately machine precision. None of these three well-conditioned validation cases requires backtracking.
Residual convergence
Root-estimate error
Tangent-line interpretation
Sensitivity to the initial guess
Archived app example and a real-domain failure
The equation displayed in the original app interface is f(x) = x³ + √x − sin(x²). Its real-domain root is x = 0. Starting from the archived default x0 = 1, plain undamped Newton produces 1 → 0.521149 → −0.661385. The negative iterate leaves the intended real domain of the square-root term. The cleaned solver uses backtracking to remain in x ≥ 0 and converge to the root instead.
| Archived-example metric | Result |
|---|---|
| Real root | 0 |
| Safeguarded final root | 0 |
| Final residual | 0 |
| Safeguarded Newton iterations | 38 |
| Total backtracking steps | 73 |
Why the original percentage error fails at a zero root
The historical app computes approximate percentage error by dividing the latest change by the new iterate. This is poorly conditioned when the true root is near zero and becomes undefined when the new iterate is exactly zero. In the archived example, the solver reaches zero residual while the app-style error becomes infinite.
Source audit and project scope
The public repository preserves the original Calculus.mlapp and Numerical_Calculus.prj files as historical material, together with a text source audit describing the recovered callback behavior. The standalone runner is the reproducible entry point used for the quantitative results on this page.
This project focuses on first-order Newton–Raphson. It does not claim that the additional historical UI tabs were completed, and it does not claim global convergence for arbitrary nonlinear equations. Backtracking improves robustness but is not a substitute for a bracketing method when guaranteed root isolation is required.
Reproducibility
The cleaned validation runner requires no external MATLAB toolboxes and automatically exports the validation metrics, histories, and numerical results used here. The seven website figures are stored directly in the portfolio repository as self-contained vector assets generated from the validated output data. The reported calculations were validated in MATLAB R2022b.