Search code examples
c#.netmathconditional-statementsmathematical-optimization

Solving equations in .NET


I'm trying to solve some simple equations in .NET. I came across Math.NET and evaluate it. The Solver() methods seemed to be what I need but I can't figure out how to use side conditions with this method.

To illustrate my problem I will give you a sample:

Given:  
0 <= a_i <= 100  
0 <= b <= 100
0 <= c
a_i, b and c are given

x_1, ..., x_n should be optimized

f(x) = x_1*a_1 + x_2*a_2 + ... + x_n*a_n = b

Side conditions:  
g(x) = x_1 + x_2 + ... + x_n = c  
0 <= x_i

Is it possible to solve such a problem using the solve method or any other component of Math.NET or do you know any (free for commercial use) .NET library that can be used for solving this? I wouldn't like to write an algorithm for such a common problem by myself.

Best regards & thanks in advance


Solution

  • You need an optimizer with constraints like simplex method or Marquardt non-linear optimization.