解决在使用mathdotnet线性方程组的系统?

编程入门 行业动态 更新时间:2024-10-26 04:21:27
本文介绍了解决在使用mathdotnet线性方程组的系统?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我要解决像,

(4-X)* 2 =(Y-1)* 10 + 2 结果 X = Y * 2 + 1

该方程以字符串形式提供。 是否有表达mathdotnet一个方程的方法吗?我只能想办法写表达式。

The equations are available in string form. Is there a way to express a equation in mathdotnet? I can only find ways to write expressions.

推荐答案

的 Math.NET Numerics的可以数值求解任何线性系统,但我想这不是你要找的内容。

Math.NET Numerics can solve any linear system numerically, but I suppose that's not what you're looking for.

数学.NET对符号可以处理符号表达式,虽然这个项目处于早期阶段,还没有理解方程的概念。但是,我们仍然可以用它来解决一些简单的系统,如这些,有一些工作 - 做什么我们会做手工,以及

Math.NET Symbolics can deal with symbolic expressions, although this project is in an early stage and does not yet understand the concept of equations. However, we can still use it to solve simple systems like these, with a bit of work - by doing what we would do by hand as well.

首先,让我们定义一个小功能,解决了令一个线性方程高达1:

First, let's define a small function to solve a single linear equation of order up to 1:

using Expr = MathNet.Symbolics.Expression; Expr SolveSimpleRoot(Expr variable, Expr expr) { // try to bring expression into polynomial form Expr simple = Algebraic.Expand(Rational.Numerator(Rational.Simplify(variable,expr))); // extract coefficients, solve known forms of order up to 1 Expr[] coeff = Polynomial.Coefficients(variable,simple); switch(coeff.Length) { case 1: return Expr.Zero.Equals(coeff[0]) ? variable : Expr.Undefined; case 2: return Rational.Simplify(variable,Algebraic.Expand(-coeff[0]/coeff[1])); default: return Expr.Undefined; } }

然后,我们可以用这个如下解决系统

Then we can use this to solve the system as follows:

// declare variables var x = Expr.Symbol("x"); var y = Expr.Symbol("y"); // Parse left and right side of both equations Expr aleft = Infix.ParseOrThrow("(4-x)*2"); Expr aright = Infix.ParseOrThrow("(y-1)*10+2"); Expr bleft = Infix.ParseOrThrow("x"); Expr bright = Infix.ParseOrThrow("y*2+1"); // Solve both equations to x Expr ax = SolveSimpleRoot(x,aleft-aright); // "8 - 5*y" Expr bx = SolveSimpleRoot(x,bleft-bright); // "1 + 2*y" // Equate both terms of x, solve to y Expr cy = SolveSimpleRoot(y,ax-bx); // "1" // Substitute term of y into one of the terms of x Expr cx = Algebraic.Expand(Structure.Substitute(y,cy,ax)); // "3" // Print expression in Infix notation Console.WriteLine(Infix.Print(cx)); // x=3 Console.WriteLine(Infix.Print(cy)); // y=1

更多推荐

解决在使用mathdotnet线性方程组的系统?

本文发布于:2023-11-30 14:50:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1650398.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:系统   线性方程组   mathdotnet

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!