简体   繁体   English

如何在C#中表示数学变量?

[英]How can I represent math variables in c#?

I need to represent these mathematical equations in code and to solve them: 我需要在代码中表示这些数学方程式并加以解决:

2x = 3y
3y = 4z
2x + 3y + 4z = 1

Please advise. 请指教。

(I suspect this is homework, so I will give you some clues as to how to proceed...) (我怀疑这是家庭作业,所以我会给您一些有关如何进行操作的线索...)

Think about how you would solve these equations on paper. 考虑一下您将如何在纸上求解这些方程式。

The same steps can be written into your software. 可以将相同的步骤写入您的软件。 Each equation has a variable and a coefficient , so you will most likely want to represent the coefficient with a variable in your program, and "solve" the equations using the same techniques you would by hand. 每个方程式都有一个变量和一个系数 ,因此您很可能希望在程序中用一个变量表示该系数,并使用与手工相同的技术来“求解”方程式。

也许这样的答案就是你在追求什么?

Here is a complete, documented/tutorial C# program to solve sets of linear equations: http://www.codeproject.com/KB/cs/LinearEquationsSystemSoln.aspx 这是一个完整的有文档的C#程序,用于解决线性方程组: http : //www.codeproject.com/KB/cs/LinearEquationsSystemSoln.aspx

By the way, C# isn't really the language for this. 顺便说一句,C#并不是真正的语言。 MATLAB or Python/scipy would have built-in solvers. MATLAB或Python / scipy将具有内置的求解器。 See things like this: http://docs.scipy.org/doc/numpy/reference/generated/numpy.linalg.solve.html 看到这样的事情: http : //docs.scipy.org/doc/numpy/reference/generated/numpy.linalg.solve.html

This sound like a simple case a linear algebra. 这听起来像线性代数的简单情况。 Throw the equations into an M x N matrix where M is the number of coefficients + 1 and N is the number of equations. 将方程式放入M x N矩阵,其中M为系数数+ 1,N为方程式数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM