Non-linear systems - how to keep track of unknowns from delegates?

This may sound like math questions, but it's more of a programming question.

Imagine that I have already implemented a multidimensional root solver in C # to find the unknowns of the following system, made from equations that I pass as delegates:

delegate 1) x4 + f (x4, x2, x3) -2 = 0

delegate 2) g (x1, x2) - 0.5 = 0

delegate 3) h (x1, x2) + x1 * x3 - 5 = 0

delegate 4) x3 * x4 - 2 = 0

Here fg and h are some functions that return float. The way the solver works is to try different combinations of the input vector [a, b, c, d] corresponding to the union of all unknowns provided by the delegates, after some algorithm, until all the roots are found by iteration.

My problem is that each delegate of the above system is provided by a different class. This is actually a problem because delegate number 1, which is a function defined in another class elsewhere, must now have its parameters x2, x3, x4 match the values ​​b, c, d from the input vector ... but it doesn't know what if there isn't any mapping defined somewhere (?).

It would seem that there is an addiction between the solver and the delegates provided by each class. Is there a way that I can design my system so that each function knows where to get the corresponding x values ​​so that the solver can do its job? I've thought about implementing hash tables and creating IDs for each parameter, but it all seems completely awkward to me.

In practice, I will work with a system with over 1000 equations and 1000 unknowns with the problems described above.

Is there a data structure or pattern that can help me?

+3


source to share


1 answer


Having a bit of trouble understanding the problem, but I suspect it will be solved by redefining your equations with some 0 coefficients, for example.

delegate 1) x1 * 0 + x4 + f (x4, x2, x3) - 2 = 0

delegate 2) x2 * 0 + x3 * 0 + g (x1, x2) - 0.5 = 0



delegate 3) x4 * 0 + h (x1, x2) + x1 * x3 - 5 = 0

delegate 4) x1 * 0 + x2 * 0 + x3 * x4 - 2 = 0

The above will give exactly the same results without the ambiguity of how to read the vector. This wraps around the problem because all delegates will have the same arguments.

0


source







All Articles