Comments (7)
How about: Math\NumericalAnalysis ?
from math-php.
Sounds good to me.
from math-php.
This file in also in the Pull Request
from math-php.
Can you provide a simple example of how to use the NewtonsMethod function? Some simple input with expected output. It will help me better understand the function to be able to write unit tests for it and possibly refactor with improvements.
Thanks.
from math-php.
Newton's Method is a numerical method to solve the inverse of a function. Say, for example, you want to find the roots of the polynomial, f(x) = x^4+8x³ -13x² -92x+96. You can use newton's method. You find the x that will make f(x) = 0;
In our method:
$function is a callback to a f(x). In this case it will be: function($x){return $x ** 4 + 8 * $x ** 3 - 13 * $x ** 2 - 92 * $x + 96;}
$args is an array of arguments that have to be passed to the function. In or case it is ['x'], because $function only needs one parameter, the one we are solving for. If the function were f(x,y) = x³y + y²x and we wanted f(x|y=2) = 0, we would provide $args = ['x', 2].
$target is the value of f(x) we a trying to solve for. in our case we want to find the x that gives us f(x) = 0.
$guess is the starting point. For our polynomial above this is very important because there are 4 solutions. the starting point will determine which solution we will receive.
$tol is the tolerance...How close to the actual solution we would like.
Putting it all together, here is a console php statement to run the method. This polynomial has 4 roots, 3,1,-8 and -4.
php -r "include 'src/NumericalAnalysis/NewtonsMethod.php';use Math\NumericalAnalysisewtonsMethod; print NewtonsMethod::solve(function(\$x){return \$x ** 4 + 8 * \$x ** 3 - 13 * \$x ** 2 - 92 * \$x + 96;}, ['x'], 0, -4.1, .00001);"
Running this gives -3.9999999999999
An alternative implementation might be to make $args a list of parameter initial values, and replace '$guess' with '$position', where $position indicates which element in the $args array needs to be changed, keeping the rest constant. I think this is a better idea.
from math-php.
If I move to the alternate implementation would you prefer zero index or one index on the position?
from math-php.
Thanks for the great explanation. I've added unit tests based on it.
If you decide to refactor, please update the unit tests as well. For index positions, I've been using zero indexing for everything.
from math-php.
Related Issues (20)
- What is the point of the complex polar form? HOT 7
- Division by zero in Probability\Distribution\Continuous\Continuous HOT 21
- Dealing with NANs HOT 3
- Integer Modulo n HOT 3
- Add vector, matrix and quaternion operations for 3d geometry HOT 1
- Could math-php support KPHP? HOT 1
- Truncated Mean Percentage HOT 5
- Incompatibility with Iterator and ArrayAccess interfaces HOT 1
- Quartiles calculation in Stats Descriptive HOT 1
- MiddlePayment For Loan HOT 2
- `number` is not a valid PHP type HOT 5
- Kernel Density Estimation: Improved Sheather-Jones algorithm HOT 4
- Bug for the t-test? HOT 5
- Add row/column algebra methods to Matrix for Vector HOT 3
- Document additional Matrix Row Operations and add their Columnar counterparts HOT 5
- Implicit Behavior of ImmutableSet
- Add Moore-Penrose Inverse HOT 12
- Psalm does not understand `number` pseudo-type HOT 3
- Add a factor method for Polynomials HOT 4
- Repeated measures ANOVA HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from math-php.