Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 516
Jay Avatar asked Sep 30 '11 13:09

Jay


2 Answers

IMHO Microsoft Solver Foundation is the way to go for this. The Express Version is free AFAIK and powerful enough for most smaller applications.

As I see now the Express Version is only indented for exploration - but there is (now?) a Standard-Lib for MSDN subscribers so I don't remove this post yet, as you might have a MSDN subscribtion.

like image 79
Random Dev Avatar answered Sep 30 '22 03:09

Random Dev


ALGLIB is great for these tasks. Check out their page on constrained optimization.

EDIT: It has both a free license (GPL) and a commercial license starting from $370.

like image 24
Andreas Avatar answered Sep 30 '22 05:09

Andreas