This repository contains a full-stack, interactive exploration of Nonlinear Eigenvalue Problems with eigenvector dependency (NEPv).
In a standard linear eigenvalue problem, a fixed matrix equation is solved to find the natural resonant states of a static system:
In an NEPv, the matrix (or operator) depends on the eigenvector itself. The geometry of the space actively warps based on the vector's position:
The Intuition: This creates a massive feedback loop. The direction of
The visualizer is designed to move beyond a generic scatter of random numbers and instead focus on three core geometric phenomena:
-
The "Moving Target" Chase (Dependence of Operator on Vector): The right panel shows the current iterate (solid blue/green arrow) and a local target direction (dashed orange/light-green arrow). When stepping through the standard Self-Consistent Field (SCF) iteration, the user visually sees the target jump away. This visceral "chase" proves the core concept of NEPv.
-
Symmetry Breaking (Degeneracy): Because the underlying
$2 \times 2$ toy matrix uses the squares of the vector components, the system is symmetric across all four quadrants. Starting the vector in different quadrants leads to distinct, degenerate solutions, mimicking physical symmetry breaking. -
The Pitchfork Bifurcation: By adjusting the non-linearity parameter (
alpha), the user can discover a bifurcation phase-transition. At low non-linearity, only a single stable 45° solution exists. Whenalphacrosses a critical threshold, the space fractures into two distinct stable solutions. -
Convergence Dual-Signal Chart: Residual alone can be misleading in simple toy systems, so the chart tracks both residual error and angular distance to the local target direction, clearly showing when algorithms either converge or fall into infinite oscillation.
Why user control matters: One of the biggest pitfalls of NEPv (and non-linear math in general) is that the final answer you get—or whether you get an answer at all—depends heavily on where you start. This creates Basins of Attraction.
- The Safe Zone: If you start your vector within ~20 degrees of the true answer, the SCF method usually converges quickly and smoothly.
- The Far-Away Zone: Even if you start much farther away, this demo still often converges, but it may take more iterations and follow a very different path.
Instead of pure randomness, the app provides a 0°–360° angle slider. This lets you:
- Explore how far away you can start before the algorithm breaks (engaging educational discovery).
- Test multiple quadrants systematically to observe symmetry breaking.
- Reproduce exact initial conditions for reproducible teaching moments.
The slider guarantees a unit-normalized vector
When the angular gap between current and target vectors drops to ≤ 0.5°, both vectors (and the trail) automatically turn green. This provides instant visual feedback that the algorithm has converged, replacing the need to squint at decimal digits.
The application follows a decoupled architecture, separating the "Physics Engine" from the "Display Terminal":
- Framework: Sinatra (lightweight, fast HTTP endpoints).
- Core Logic: Plain Old Ruby Objects (POROs) handling the mathematical state, implementing both first-order SCF iterations and second-order Inexact Matrix-Newton step solvers.
- Middleware:
rack-corsto allow cross-origin requests from the React dev server.
- Bundler: Vite (React + JavaScript).
- Visualization: HTML5
<svg>for the 2D vector space rendering. - Charting:
rechartsfor rendering the algorithmic convergence rate. - Styling: Tailwind CSS for rapid, clean control panel UI.
Install the following before running the project locally:
- Ruby 3.3.8 or later
- Bundler
- Node.js 18 or later
- npm
- rbenv (if you want to switch Ruby versions easily)
If you use rbenv, switch to the Ruby version that already has Bundler available:
rbenv shell 3.3.8git clone https://github.com/Guilty233/NEPv.git
cd NEPvInstall the Ruby backend gems:
cd backend
rbenv shell 3.3.8
bundle installInstall the frontend dependencies in a second terminal or after returning to the repository root:
cd frontend
npm installFrom the backend directory:
bundle exec ruby app.rb -p 4567The API will be available at http://localhost:4567.
From the frontend directory:
npm run devVite will print the local development URL, usually http://localhost:5173.
Keep the backend and frontend running in separate terminals:
- Start the Ruby API in
backend/. - Start the React app in
frontend/. - Open the frontend URL in your browser.
The frontend talks to the backend through POST /api/v1/step.
The SCF method iteratively computes:
-
Current matrix: $A(v) = \begin{bmatrix} 1 + \alpha x^2 & 1 \ 1 & 1 + \alpha y^2 \end{bmatrix}$ from current vector
$v = [x, y]$ . -
Principal eigenvector: Solve
$A(v) w = \lambda w$ ; extract principal eigenvector as target. -
Relaxation step: Compute
$v_{\text{next}} = (1 - \text{relaxation}) \cdot v + \text{relaxation} \cdot \text{target}$ . -
Loop: Set
$v := v_{\text{next}}$ and repeat.
When current and target nearly overlap (distance
The Newton solver computes:
-
Jacobian: Finite-difference approximation of
$\frac{\partial F}{\partial v}$ where$F(v) = A(v)v - \lambda(v) v$ . -
Newton step: Solve
$J \Delta v = -F$ using Cramer's rule (2×2 direct solve). -
Target: Normalize
$v + \Delta v$ as the Newton-corrected target direction. - Relaxation: Same interpolation as SCF for user control over convergence speed.
Newton typically converges faster (fewer iterations) but is more sensitive to initial conditions.
-
Solver scope. Current SCF/Newton are educational stubs and not production-grade NEPv solvers for large systems.
-
Small 2D setting. The visual model is intentionally 2D for intuition; it does not capture many high-dimensional effects seen in practical NEPv applications.
-
Simplified target direction. The displayed target is a teaching reference direction computed from the current iterate, not a rigorous proof of global convergence.
The backend exposes a single stateless endpoint that takes a vector state, applies one mathematical iteration based on the chosen algorithm, and returns the new state.
Route: POST /api/v1/step
Headers: Content-Type: application/json
Request Body:
{
"current_vector": [0.894, 0.447],
"method": "scf",
"alpha": 2.5,
"relaxation": 0.35
}Response Body:
{
"current_vector": [0.894, 0.447],
"next_vector": [0.895, 0.446],
"target_vector": [0.894, 0.448],
"residual_error": 0.00123,
"matrix": [
[3.000, 1.0],
[1.0, 1.499]
],
"method": "scf",
"alpha": 2.5,
"relaxation": 0.35
}Field Descriptions:
-
next_vector: The updated vector after relaxation (becomes the newcurrent_vectorin the next iteration). -
target_vector: The principal eigenvector or Newton-corrected target (purely for visualization). -
residual_error: Distance betweencurrent_vectorandtarget_vector. -
matrix: Snapshot of$A(v)$ evaluated at the inputcurrent_vector.
Both solvers strictly follow the algorithm outlined in the reference paper:
- SCF: Principal eigenvalue computation via closed-form 2×2 solution, with relaxation interpolation.
- Newton: Finite-difference Jacobian with direct 2×2 linear solve, matching the paper's inexact Newton approach.
This project was built to make the NEPv idea visible: the current vector generates a new matrix, that matrix produces a local target vector, and the algorithm relaxes toward that target step by step. The goal is to turn an abstract mathematical feedback loop into something users can watch and explore in the browser.
The SCF and Newton methods implemented in this project were adapted from:
- Linear Algebra and Its Applications (2024): https://www.sciencedirect.com/science/article/pii/S0024379524004166
AI helped with wording, structure, and code review. I verified the solver behavior by hand and with code through API responses, browser interaction, and convergence tests for both SCF and Newton.