sympy
sympy copied to clipboard
Fixed Problem Caused By Rounding Errors in Beam Module
References to other Issues or PRs
Fixes #22443 Fixes #21162
Brief description of what is fixed or changed
The rounding errors of floats can cause problems in linsolve(), leading to inconsistent results.
To address this issue, nsimplify() is used instead of sympify() to convert input values in appropriate sympy types. nsimplify() also converts Float values to Rational values, which helps in removing rounding errors resulting in more accurate solutions from linsolve().
Other comments
Release Notes
NO ENTRY
:white_check_mark:
Hi, I am the SymPy bot. I'm here to help you write a release notes entry. Please read the guide on how to write release notes.
- No release notes entry will be added for this pull request.
Click here to see the pull request description that was parsed.
<!-- Your title above should be a short description of what
was changed. Do not include the issue number in the title. -->
#### References to other Issues or PRs
<!-- If this pull request fixes an issue, write "Fixes #NNNN" in that exact
format, e.g. "Fixes #1234" (see
https://tinyurl.com/auto-closing for more information). Also, please
write a comment on that issue linking back to this pull request once it is
open. -->
Fixes #22443
Fixes #21162
#### Brief description of what is fixed or changed
The rounding errors of floats can cause problems in `linsolve()`, leading to inconsistent results.
To address this issue, `nsimplify()` is used instead of `sympify()` to convert input values in appropriate sympy types. `nsimplify()` also converts `Float` values to `Rational` values, which helps in removing rounding errors resulting in more accurate solutions from `linsolve()`.
#### Other comments
#### Release Notes
<!-- Write the release notes for this release below between the BEGIN and END
statements. The basic format is a bulleted list with the name of the subpackage
and the release note for this PR. For example:
* solvers
* Added a new solver for logarithmic equations.
* functions
* Fixed a bug with log of integers. Formerly, `log(-x)` incorrectly gave `-log(x)`.
* physics.units
* Corrected a semantical error in the conversion between volt and statvolt which
reported the volt as being larger than the statvolt.
or if no release note(s) should be included use:
NO ENTRY
See https://github.com/sympy/sympy/wiki/Writing-Release-Notes for more
information on how to write release notes. The bot will check your release
notes automatically to see if they are formatted correctly. -->
<!-- BEGIN RELEASE NOTES -->
NO ENTRY
<!-- END RELEASE NOTES -->
The rounding errors of floats can cause problems in
linsolve()
I think this is the classic complaint for which we must "refuse the temptation to guess". nsimplify is an approximation and will work like magic until you give it numbers that get incorrectly simplified. The user should be educated to use the type needed for the problem or a keyword like "prec" could be used to indicate the precision of the float that will be converted to Rational. But an unqualified use of nsimplify should not be done.