Skip to content

fix: select the largest absolute pivot in Gaussian elimination - #150

Open
kusicheng wants to merge 1 commit into
king04aman:mainfrom
kusicheng:fix/gauss-partial-pivot-selection
Open

kusicheng wants to merge 1 commit into
king04aman:mainfrom
kusicheng:fix/gauss-partial-pivot-selection

Conversation

@kusicheng

Copy link
Copy Markdown

Developer Checklist

  • Followed the README and contributing guidelines.
  • Kept changes in the existing project directory.
  • The project already includes a README.

Summary

gauss_partial compares candidates against the original signed diagonal value instead of the best candidate found so far. This can select a smaller pivot or replace a negative nonzero pivot with zero.

For example, the nonsingular system -x + y = 0, y = 1 raises ZeroDivisionError.

Compare absolute values against the current best row so partial pivoting selects the largest remaining magnitude. The example now correctly returns x_0 = 1.0 and x_1 = 1.0.

Testing

Run:
python -B -m unittest discover -s "Gauss Elimination with Partial Pivoting" -p "test_*.py" -v

All six tests pass, covering:

  • Smaller candidates following the maximum.
  • Negative pivots and candidates.
  • Equal pivot magnitudes.
  • Later pivot columns.
  • The previously crashing system.

Before the fix, four tests failed and one raised ZeroDivisionError.

Also verified the example through the interactive CLI and ran git diff --check.

@github-actions

Copy link
Copy Markdown
Contributor

👋 @kusicheng 👋

We're delighted to have your pull request! Please take a moment to check our contributing guidelines and ensure you've filled out the PR template for a smooth process. We will review it soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant