Let us assume that I have defined a function named computeValue (double x)
:
Also, we have the above mentioned array that
My aim is to invoke a root-finding algorithm (such as Newton-Raphson, Secant Method, etc) that will aim to minimize the following expression:
f = CONSTANT - computeValue(array[4])
As you may have already observed, the problem is that every time my root-finding routine modifies the 4th element of my array to obtain a new solution, the positions 2 and 3 of my array should be modified accordingly given that they are the result of a interpolation (as mentioned in point 4 above), thus changing the result of computeValue
.
What is a possible way of making the values of the array change dynamically as the root finding algorithm works its way towards the root? Maybe something to do with an array storing lambda expressions defining the interpolation?
It cannot be done with a classic array, but you can implement your own type that solves the problem. This type internally uses an array of length four and offers access by
public int this[int index]
{
// get and set accessors
}
Here, you can write your own getters and setters, so that you can recalculate values as soon as the others were changed.