Currently, this goal seek uses Steffensen's Method to find the root of the error.
goal-seek-big-number is an npm package, so installation is as easy as:
$ npm install --save goal-seek-big-number
The package exports two error types, the function parameter type and one function,
goalSeek as a default export:
goalSeek function takes one object argument with the following keys:
fn- the function, "f(x)" that is being evaluated.
fnParams- an array of parameters that are to be used as inputs to
percentTolerance- the acceptable error range to the stated goal. For example, if
percentTolerance: 1, then any values in the range [99, 101] will be accepted as correct (± 1% of 100).
maxIterations- the maximum number of attempts to make.
maxStep- the maximum magnitude step size to move the independent variable
xfor the next guess.
goal- the desired output of the
independentVariableIdx- the index position of the independent variable
To use the function, for example, with a simple linear equeation:
let x = 10;const fn = x: BigNumber: x;const fnParams = x;tryconst result =// result => 98catche
This library will throw one of two errors:
IsNanError is thrown whenever the result of
fn returns a value that is not a BigNumber. For example, if
Math.log, and the value
-1 is input
goalSeek with throw
FailedToConvergeError is thrown when no acceptable independent variable can be found. For example, if
x * x and goal is
-1 the library will fail to converge and throw
;const fn = x * y * z;const fnParams = 456;tryconst result =;console;catch econsole;// result: 7
This work is licensed under MIT.
The MIT License (MIT) Copyright (c) 2020 Chaitanya Potti Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
This package is derivative of the amazing work done by Adam Hanna and his original package