如何将方程转换为各个变量的公式?

发布于 2024-07-17 10:10:28 字数 553 浏览 6 评论 0原文

如何将方程转换为各个变量的公式? 我正在考虑一个数学方程,例如:

c^2 = a^2 + b^2

我想要一个可以处理任何公式的函数,并给出各个变量的公式。 上面的等式将产生以下结果:

a = (c^2 - b^2)^0.5
b = (c^2 - a^2)^0.5
c = (a^2 + b^2)^0.5

我还想从以下内容开始:

a = (c^2 - b^2)^0.5

和输出:

b = (c^2 - a^2)^0.5
c = (a^2 + b^2)^0.5

我已经查看了表达式树,但我无法想象它是如何工作的。 我想要一个 .NET(C#、VB.NET 或 F#)解决方案。 有任何想法吗?

比如:

public string[] GetFormulas(string equation)
{
   ...
}

谢谢。

How to convert an equation into formulas for individual variables? I am thinking about a math equations like:

c^2 = a^2 + b^2

I would like to have a function that could process any formula, and give me the individual variable formulas. The above equation would produce the following:

a = (c^2 - b^2)^0.5
b = (c^2 - a^2)^0.5
c = (a^2 + b^2)^0.5

I would also like to start with:

a = (c^2 - b^2)^0.5

and output:

b = (c^2 - a^2)^0.5
c = (a^2 + b^2)^0.5

I have looked at expression trees, but I am having trouble visualizing how this will work. I would like a .NET (C#, VB.NET, or F#) solution. Any ideas?

Something like:

public string[] GetFormulas(string equation)
{
   ...
}

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

疑心病 2024-07-24 10:10:28

符号方程求解是一个复杂的问题,许多方程没有闭合解。 编写自己的计算机代数系统并非易事,但您也许可以编写一个简单的程序方程。

您必须构建输入字符串的表达式树并定义用于操作表达式树的转换规则。 为了求解变量,您可以在表达式树的空间上执行搜索(通过良好的启发式引导以保持运行时可接受),该表达式树可以通过多次应用从原始树派生
变换规则。

Symbolic equation solving is a complex problem and there is no closed solution for many equations. Writing your own Computer Algebra System is none trivial, but you may be able to write a program for simple equation.

You will have to build a expression tree of the input string and define transformation rules for manipulating the expression tree. To solve for a variable you might then perform a search (guided by good heuristics to keep the runtime acceptable) on the space of expression tree that can be derived from the orginal tree by multiple aplications of
transformation rules.

全部不再 2024-07-24 10:10:28

这是您想要解决的一个不平凡的问题...我认为您自己尝试解决它不会有太多运气。 最好找到某种可以做到这一点的第三方应用程序或库。 有许多程序可以完成您所讨论的操作,例如 Matlab 和 Maple。 另外,TI-89 图形计算器也可以做到这一点。 您也许可以从 Octave 获得所需的算法,它本质上是一个开放的Matlab源码实现。

This is a non-trivial problem you're trying to solve... I don't think you'll have much luck trying to solve it on your own. Better to find some kind of third-party app or library that does it. There are a number of programs that can do the operation you're talking about, such as Matlab and Maple. Also, a TI-89 graphing calculator can do it. You may be able to get the algorithms you need from Octave, which is essentially an open-source implementation of Matlab.

层林尽染 2024-07-24 10:10:28

您可能需要使用数学库来解决这个问题。 对于.NET, Math.NET 似乎是最完整的选项(不确定它有多稳定,但是它当然非常完整)。 用于进行符号操作的库应该能够处理您在此处提出的特定问题。

老实说,从头开始编写这个应该不会太困难,但如果您不太熟悉表达式树并且不知道如何完成任务,我仍然建议使用现有的数学库,无论是 Math.NET 还是任何其他可以进行符号代数的不错的库。

This is something for which you'll probably want to look at using a mathematical library. For .NET, Math.NET seems to be the most complete option (not sure how stable it is, but it's certainly very complete). The library for doing symbolic manipulation should be able to handle the specific problem you have posed here.

To be honest, writing this from scratch shouldn't be too difficult, but if you're not very familiar with expression trees and wouldn't know how to approach the task, I would still recommend using an existing maths library, either Math.NET or any other decent one that does symbolic algebra.

合久必婚 2024-07-24 10:10:28

您唯一的选择是通过应用所有已知技术来暴力破解。 在像上面这样的简单代数方程中,这可能就足够了,但更复杂的问题将需要越来越复杂的解决方案。 简而言之,这并不容易。

一旦你弄清楚如何将文本解析为符号,创建一个应用程序可能很容易,它可以确定

c^2 = a^2 + b^2

可以替换为

c = (a^2 + b^2)^.5

但是,更

cos(c) = sin(a^2/b) - b^(a/sin(b))

糟糕的是,你有无法解决的集成和抽象代数......你将有在某处划定复杂性的界限,否则您最终将构建另一个 Maple

Your only choice is to brute force it by applying all known techniques. In simple algebra equations like you have above, that might be sufficient, but more complex problems will require increasingly complex solutions. In brief, it won't be easy.

Once you figure out how to parse text into symbols, it might be easy enough to create an app that can determine that

c^2 = a^2 + b^2

can be substituted as

c = (a^2 + b^2)^.5

but, what about

cos(c) = sin(a^2/b) - b^(a/sin(b))

Worse yet, you have unsolvable integrations, and abstract algebra... You'll have to draw the line of complexity somewhere, or else you'll just end up building another Maple.

爱*していゐ 2024-07-24 10:10:28

以符号和非数字的方式处理方程绝对不是一件容易的事。 我认为对你来说最简单的方法就是在幕后简单地使用 Mathematica、Maple 或类似的工具,让它们为你完成艰苦的工作。

Dealing with equations in a symbolic and non-numeric way is definitely not an easy task. I think the easiest way for you would be to simply use Mathematica, Maple or similar behind the scenes and let them do the hard work for you.

揪着可爱 2024-07-24 10:10:28

由于 c^2 = a^2 + b^2 不是 C# 中的表达式,因此您走错了路。

忘记 .NET 表达式树并创建您自己的表达式树。 您需要描述执行这些转换所需的算法以及描述方程所需的数据。 您会发现最终得到的结果与 .NET 表达式树有很大不同。

Since c^2 = a^2 + b^2 is not an expression in C#, you're off on the wrong track.

Forget about .NET expression trees and create your own. You need to describe the algorithms required to do these transformations, and the data necessary to describe an equation. You'll find that what you wind up with is quite different from a .NET expression tree.

情徒 2024-07-24 10:10:28

除了已经说过的内容之外,您还可以查看数值方法。

有一些算法可以近似方程的解。 因为其中大多数问题并不那么容易(甚至不可能)精确解决。

In addition to anything that has already been said, you can have a look at numerical methods.

There are algorithms to apriximate the solution(s) of an equation. Because most of them won't be that easy (or even imposible) to solve exactly.

染墨丶若流云 2024-07-24 10:10:28

总的来说是一个令人讨厌的问题。 对于低阶多项式表达式,这并不是太难。 对于线性问题,您只需要一个解析器和一点后处理。 但即使是一个简单的编写表达式也可能不是微不足道的。 例如,您将如何解决

x^5 + y^5 - xy + 1 = 0

x 或 y 中的一个问题,意味着您必须求解 5 阶非常数系数多项式的根。这通常是不可能做到的。

更糟糕的是,将三角函数或任何特殊函数引入其中,它会迫使您在完成之前重新编写 Mathematica。

A nasty problem in general. For low order polynomial expressions, this is not too terribly hard. For linear problems, you just need a parser and a little bit of post-processing. But even a simple to write expression might be less than trivial. For example, what will you do with

x^5 + y^5 - xy + 1 = 0

Solving for either of x or y in terms of the other means you must solve for the roots of a non-constant coefficient polynomial of order 5. This will be impossible to do in general.

Worse, introduce trig functions or any special function into the mix, and it will force you to re-write Mathematica before you are done.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文