This project has moved. For the latest updates, please go here.

Can Math.NET Numerics solve equations of higher degree?

May 2, 2011 at 8:58 AM

I have a sort of codes written by MATLAB, and now I plan to transplant it to C# using Math.NET Numerics.

One part of the code in MATLAB is domenstrated below and I am not sure whether it could be transplanted smoothly since the function solve() solves a equation of 4 degree.

syms u v;

eq1=-Wbar(3,1,1,1)*u^4-3*Wbar(3,1,1,2)*u^3*v+(Wbar(1,1,1,1)-3*Wbar(3,1,1,3))*u^3-3*Wbar(3,1,2,2)*u^2*v^2+(3*Wbar(1,1,1,2)-6*Wbar(3,1,2,3))*u^2*v ...
    +(3*Wbar(1,1,1,3)-3*Wbar(3,1,3,3))*u^2-3*Wbar(3,2,2,3)*u*v^2-Wbar(3,2,2,2)*u*v^3+3*Wbar(1,1,2,2)*u*v^2+(6*Wbar(1,1,2,3)-3*Wbar(3,2,3,3))*u*v ...
    +(3*Wbar(1,1,3,3)-Wbar(3,3,3,3))*u+Wbar(1,2,2,2)*v^3+3*Wbar(1,2,2,3)*v^2+3*Wbar(1,2,3,3)*v+Wbar(1,3,3,3);

eq2=-Wbar(3,1,1,1)*u^3*v+Wbar(2,1,1,1)*u^3-3*Wbar(3,1,1,2)*u^2*v^2+(3*Wbar(2,1,1,2)-3*Wbar(3,1,1,3))*u^2*v+3*Wbar(2,1,1,3)*u^2-3*Wbar(3,1,2,2)*u*v^3 ...
    +(3*Wbar(2,1,2,2)-6*Wbar(3,1,2,3))*u*v^2+(6*Wbar(2,1,2,3)-3*Wbar(3,1,3,3))*u*v+3*Wbar(2,1,3,3)*u+3*Wbar(2,2,2,3)*v^2-Wbar(3,2,2,2)*v^4 ...
    +(Wbar(2,2,2,2)-3*Wbar(3,2,2,3))*v^3-3*Wbar(3,2,3,3)*v^2+(3*Wbar(2,2,3,3)-Wbar(3,3,3,3))*v+Wbar(2,3,3,3);

sol=solve(eq1,eq2);


Here,eq1 is a equation, so is eq2.

I run the demo and see the real value of eq1 is

 
(2468960008933709*u^4)/72057594037927936 + (2083662827593531*u^3*v)/9007199254740992 - (4914365064003583*u^3)/9007199254740992 + (3566988361907577*u^2*v^2)/9007199254740992 - (1322708076069197*u^2*v)/562949953421312 + (7629599153705847*u^2)/9007199254740992 + (2104806452828165*u*v^3)/4503599627370496 - (1362712901439835*u*v^2)/562949953421312 + (7610756345394247*u*v)/4503599627370496 - (107926417152785*u)/281474976710656 + (5321387875001673*v^3)/9007199254740992 - (3566988361907577*v^2)/9007199254740992 + (3047413826241435*v)/2251799813685248 - 5703639438037325/18014398509481984
 

and eq2 is

 
(2468960008933709*u^3*v)/72057594037927936 + (8575950380864875*u^3)/72057594037927936 + (2083662827593531*u^2*v^2)/9007199254740992 + (2672888252780483*u^2*v)/9007199254740992 - (2083662827593531*u^2)/9007199254740992 + (3566988361907577*u*v^3)/9007199254740992 - (2103786746231615*u*v^2)/2251799813685248 + (710741216620417*u*v)/4503599627370496 + (3047413826241435*u)/2251799813685248 + (2104806452828165*v^4)/4503599627370496 - (1369791312663931*v^3)/1125899906842624 + (3379999814503283*v^2)/4503599627370496 + (5255662331732181*v)/2251799813685248 - 6462946115325185/9007199254740992
 

 The result "sol" here is a combination of u and v. u is

                                          134.96538566936506062846451817258
                                        0.077734476888921664713977137238381
                                        -0.40783257609311349792436148754659
  - 30.62432718855008701730966769311*i - 0.32461249370179839195290187256571
    30.62432718855008701730966769311*i - 0.32461249370179839195290187256571
     2.007137707979380879325538940066 - 1.6563030468437904747828940939966*i
     1.6563030468437904747828940939966*i + 2.007137707979380879325538940066
 - 1.7598990115267311570738683519375*i - 0.13343915765783438019857414081916
   1.7598990115267311570738683519375*i - 0.13343915765783438019857414081916
  0.59031406688954115593224444587114 - 0.40521741368120747229263492896236*i
  - 1.8653964706817827688823654930655*i - 2.4715087831302445793376456758204
    1.8653964706817827688823654930655*i - 2.4715087831302445793376456758204
  0.40521741368120747229263492896236*i + 0.59031406688954115593224444587114

and v is

                                         -25.661681874615685504156783670207
                                         0.25036320867053087081021465476325
                                          -1.090876372536086369169811365949
    11.969731371712596244311433563368*i - 13.342060164985762973632746082818
  - 11.969731371712596244311433563368*i - 13.342060164985762973632746082818
   0.31791342592928085496400313950225*i - 0.5627748485808064690898311691957
 - 0.31791342592928085496400313950225*i - 0.5627748485808064690898311691957
   1.3839238938141614955470342016916*i + 0.15623428964104483458652190022207
   0.15623428964104483458652190022207 - 1.3839238938141614955470342016916*i
    1.6033805069833145020013384865326 - 1.2898537646170867928076088661523*i
   0.36215103134553189525806582941266*i + 1.1969372119923177170795481105926
   1.1969372119923177170795481105926 - 0.36215103134553189525806582941266*i
    1.2898537646170867928076088661523*i + 1.6033805069833145020013384865326

 

All the solver examples I have seen in the source of Beta2 are aiming at solve the equations in 1 degree. I doubt whether the library has the modules to solve higher degree equations. If not, are there any other ways to solve the problem?

Many thanks for your great work!

May 3, 2011 at 5:17 AM

I am sorry to issue such an unprofessional question. Until now do I realise that the function solving this problem needed is called "symbolic mathmatics", while Math.NET Numerics focuses on solving numeric problems. With the technology involved within numeric mathmatic, there is no way to get all the roots.

Since that, I get interested in the prospect of Math.NET Yttrium. Will another "Math.NET Symbolic" project launch up on the privious work of Yttrium after the release of Math.NET Numerics 1.0?

Thanks all the same.

Coordinator
May 6, 2011 at 8:09 AM

Hi,

I certainly plan to revive the symbolic libraries once the development of the numerics part has stabilized,
although my focus will likely be more on Math.NET LinqAlgebra (name may change) than Math.NET Yttrium.

Yttrium is more about symbolic systems (e.g. for simplifying and simulating a feedback control system),
while LinqAlgebra is about classical symbolic expression trees, in the form of LINQ expressions.

However, this is a long term project, so do not expect any releases there within a year.

Thanks,
Chris