Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excel GoalSeek algorithm

Does anyone have the code for this algorithm ? Any C-based programming language would be OK but I prefer C#.

I could try to implement it but I'm sure I'm not the first one...

edit: It's not homework, it's a "gimme teh codez" question :D I just don't want to reinvent the wheel

like image 320
Catalin DICU Avatar asked Nov 26 '10 10:11

Catalin DICU


People also ask

What algorithm does Excel Goal Seek use?

Goal seek uses a numerical algorithm called Newton's method or the Newton Raphson method. It is a numerical algorithm for solving equation that is especially useful for equations that cannot be solved algebraically.

How does the Goal Seek function work in Excel?

The Goal Seek function in Excel allows you to adjust an input value in a formula to determine a desired outcome. This What-If Analysis tool is ideal for situations where you know the outcome you want, but aren't sure of the values needed to reach that outcome.

What is the difference between Goal Seek and Solver in Excel?

Goal Seek: Determines the value that you need to enter in a single input cell to produce a result that you want in a dependent (formula) cell. Solver: Determines the values that you need to enter in multiple input cells to produce a result that you want.


3 Answers

GoalSeek most likely uses the Bisection method

The bisection method in mathematics is a root-finding method that repeatedly bisects an interval and then selects a subinterval in which a root must lie for further processing. It is a very simple and robust method, but it is also relatively slow. Because of this, it is often used to obtain a rough approximation to a solution which is then used as a starting point for more rapidly converging methods.1 The method is also called the interval halving method,2 the binary search method,[3] or the dichotomy method.[4]

I found a C# implementation here : Bisection-based XIRR implementation in C#

like image 177
Catalin DICU Avatar answered Oct 18 '22 14:10

Catalin DICU


Have a look at:

https://www.nuget.org/packages/TridentGoalSeek/

Your algorithm needs to implement the IGoalSeekAlgorithm interface. Then usage is as follows:

var myAlgorithm = new MyAlgorithm(90463.45M, 200);
var goalSeeker = new GoalSeek(myAlgorithm);
var seekResult = goalSeeker.SeekResult(96178.21M);
like image 43
Latus Art Avatar answered Oct 18 '22 14:10

Latus Art


Try https://www.nuget.org/packages/Budoom.GoalSeek/

Sample usage:

var sc = new SomeCalculation(); //implements interface Budoom.IGoalSeek

var goalSeek = new Budoom.GoalSeek(sc);
var goalSeekResult = goalSeek.TrySeek();

or use the static method and pass the calculation function to it, like this:

var goalSeekResult = Budoom.GoalSeek.TrySeek(Calculate);
like image 26
Ahmed Avatar answered Oct 18 '22 16:10

Ahmed