Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Describe your change:
I noticed the Newton Raphson method could be improved, so I made an altered script for it.
There are currently 2 scripts for newton raphson method in
Python/arithmetic_analysis/
:newton_method.py
newton_raphson.py
There are a few issues with them,
newton_method.py
: requires user to pass both the mathematical function and its derivative into the functionnewton_raphson.py
: uses the wrong precision check; it compares the value of the f(x) with the precision required, rather than the difference in the consecutive x's. This resulted in its values to be wrong as in their test cases they showed pi =3.1415926536808043
while correct precision check would give a value of3.141592653589793
which is way closer to actual value of pi.newton_raphson.py
: also extensively useseval()
statements, which are necessary for finding derivatives, but the implementation limits them from only taking the x as variable, and it was also used in every loop making the computation slower.newton_raphson.py
: it doesn't check for the division by 0, which is the biggest limitation to using newton method, since the root can't be found for those cases.I have taken goods from both the files and added more improvements and created a third file for the time being.
Checklist:
Fixes: #{$ISSUE_NO}
.