You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to solve a system of equations for a straight line and a tangent to an ellipse.
A straight line: y - y1 = (y2 - y1) / (x2 - x1) * (x - x1)
A tangent to an ellipse: x * x3 / a ^ 2 + y * y3 / b ^ 2 = 1
So I ran the following test code and it didn't finish.
Apparently the Rational.Simplify method is taking a long time.
My operating environment is as follows.
Windows 11
Visual Studio 2019
C# NUnit Test project
AMD Ryzen 9 5950X
32GB RAM
The dependent libraries are:
FParsec 1.0.3
FSharp.Core 4.6.0
MathNet.Numerics 4.15.0
MathNet.Numerics.FSharp 4.15.0
MathNet.Symbolics 0.24.0
NUnit 3.13.2
NUnit.ConsoleRunner 3.12.0
etc...
Is there any good solution to reduce the processing time?
Thank you.
usingMathNet.Symbolics;usingNUnit.Framework;usingSystem;usingSystem.Collections.Generic;usingSystem.Threading.Tasks;namespaceboilersGraphics.Test{usingExpr=MathNet.Symbolics.Expression;[TestFixture]publicclassMathNetTest{[Test]publicvoidBasic(){varx=Expr.Symbol("x");vary=Expr.Symbol("y");varx1=Expr.Symbol("x1");vary1=Expr.Symbol("y1");varx2=Expr.Symbol("x2");vary2=Expr.Symbol("y2");varx3=Expr.Symbol("x3");vary3=Expr.Symbol("y3");vara=Expr.Symbol("a");varb=Expr.Symbol("b");Exprleft_line=y-y1;Exprright_line=(y2-y1)/(x2-x1)*(x-x1);Exprleft_tangent=x*x3/Expr.Pow(a,2)+y*y3/Expr.Pow(b,2);Exprright_tangent=1;Exprline_x=null;Exprtangent_x=null;Parallel.Invoke(()=>{line_x=SolveSimpleRoot(x,left_line-right_line);},()=>{tangent_x=SolveSimpleRoot(x,left_tangent-right_tangent);});Exprcy=SolveSimpleRoot(y,line_x-tangent_x);Exprcx=Algebraic.Expand(Structure.Substitute(y,cy,line_x));Console.WriteLine(Infix.Format(cx));Console.WriteLine(Infix.Format(cy));}// Quote from https://stackoverflow.com/questions/31223380/solving-system-of-linear-equations-using-mathdotnetExprSolveSimpleRoot(Exprvariable,Exprexpr){// try to bring expression into polynomial formExprsimple=Algebraic.Expand(Rational.Numerator(Rational.Simplify(variable,expr)));// extract coefficients, solve known forms of order up to 1Expr[]coeff=MathNet.Symbolics.Polynomial.Coefficients(variable,simple);switch(coeff.Length){case1:returnExpr.Zero.Equals(coeff[0])?variable:Expr.Undefined;case2:returnRational.Simplify(variable,Algebraic.Expand(-coeff[0]/coeff[1]));//heavy codedefault:returnExpr.Undefined;}}}}
The text was updated successfully, but these errors were encountered:
Hello.
I want to solve a system of equations for a straight line and a tangent to an ellipse.
A straight line: y - y1 = (y2 - y1) / (x2 - x1) * (x - x1)
A tangent to an ellipse: x * x3 / a ^ 2 + y * y3 / b ^ 2 = 1
So I ran the following test code and it didn't finish.
Apparently the Rational.Simplify method is taking a long time.
My operating environment is as follows.
The dependent libraries are:
Is there any good solution to reduce the processing time?
Thank you.
The text was updated successfully, but these errors were encountered: