C ++数值分析 [英] C++ numerical analysis

查看:58
本文介绍了C ++数值分析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,任何人都可以帮助我开始使用此软件:
我需要的是:读取包含此类方程式的文本文件

2x-5y + 3z = 10
5x + y-2z = 4
-4x + 3y -z = 6

然后对它们做雅各比.您能告诉我如何从文件中读取这些等式吗?我计划在A [] []矩阵中将"="之前的字符和在B []矩阵中在"="之后的数字.

Hello there, Can anyone help me get started on this:
What i need is: to read a text file containing equations like these

2x - 5y + 3z = 10
5x + y - 2z = 4
-4x +3y -z = 6

and then do jacobi on them. Can you tell me how I can read those equations from file. I am planning to have those before the "=" sign in an A[][] matrix and the numbers after "=" in B[] matrix.

推荐答案

请查看以下消息中的答案:
运行时数学形式 [如何使用数学字符集? [ ^ ]
使用c#简化方程式 [
Please have a look to the answers in these messages:
Runtime mathematical Formulla[^]
How Can I use the Math char set?[^]
Reduce equation with c#[^]

there are plenty of usefull answers and links that can be helpful for you


您需要创建一个众所周知的数据结构,称为"表达式树".树的节点应表示一个表达式,并且它应具有0、1或2个子节点表示子表达式.节点应该是从通用抽象类派生的几种不同类之一,我们称这个类为表达".代表节点的每个终端派生类都应代表一个具体的数学运算符,例如-或+.您需要根据要定义的代数定义一些虚拟函数,这些虚拟函数用于转换每个节点下的子树(子表达式).这些函数应在每个派生类中重写.这样,您将能够基于子树上定义的操作来递归地对树进行操作.

换句话说,您应该在由我上面提到的节点(表达式)类构成的C ++树结构上定义代数,并在计算中需要覆盖该代数与某些传统数学代数之间的映射.当然,这两个代数应该是同构的,并且映射应该是一对一的对应.

之后,您应该开发一种方法来以文本形式输出"表达式,非常类似于您所显示的那样.对于大多数高级选项或您自己的某种表示法,您还可以考虑支持HTML,XML,尤其是MathML.我不确定您是否需要它,但是您最好了解以下几点:
http://en.wikipedia.org/wiki/MathML [ http://en.wikipedia.org/wiki/Parsing_expression_grammar [ http://en.wikipedia.org/wiki/Expression_tree [ http://en.wikipedia.org/wiki/Compiler [ http://en.wikipedia.org/wiki/Computer_algebra_system [使用c#简化方程式 [
You need to create a well-known data structure called "expression tree". A node of a tree should represent an expression and it should have 0, 1 or 2 child nodes representing sub-expressions. The node should be of one of few different classes derived from the common abstract class, let''s call this class "Expression". Each terminal derived class representing a node should represent a concrete mathematical operator, like − or +. You need to define some virtual functions used to transform the sub-trees (sub-expressions) under each node, according to the algebra you are going to define. These function should be overridden in each derived class. This way, you will be able to do the operations on the tree based on defined operations on the sub-trees, recursively.

In other words, you should define the algebra over the C++ tree structure made of the node (expression) classes I mentioned above and the mapping between this algebra and some traditional mathematical algebra you need to cover in your calculations. Naturally, these two algebras should be isomorphic, and the mapping should be the on-to-one correspondence.

After that, you should develop the method to "output" the expression in the form of text, pretty much like the one you''ve shown. You can also consider support of HTML, XML, and, in particular, MathML, for most advanced option, or some notation of your own. I''m not sure you need it, but this is something you better be aware of:
http://en.wikipedia.org/wiki/MathML[^].

And finally, the procedure if population of the expression tree will need to be developed as some kind of parsing. You may need to learn some theory of parsers or… not, as you can do it all by yourself. Anyway, if you feel a need to learn this area, this is a good place to start:
http://en.wikipedia.org/wiki/Parsing_expression_grammar[^].

To learn more of expression trees, please see:
http://en.wikipedia.org/wiki/Expression_tree[^].

They are widely used at least in two areas: in compilers from a computer languages and, more closely to our topic, in computer algebra systems:
http://en.wikipedia.org/wiki/Compiler[^],
http://en.wikipedia.org/wiki/Computer_algebra_system[^].

Please also see my answer and other answers to this question:
Reduce equation with c#[^].

The computer algebra systems is something you need to learn, but, in my opinion, general mathematical and programming culture and a reasonably good brain in one''s head would be enough to develop such system on your own, especially in case when it does not have to be most comprehensive in the world. As you can see, most of the knowledge you would need is a commonplace pretty well covered by Wikipedia.

Wish you the best of luck,
—SA


我认为问题是如何从文本文件中读取字符串.
因此,这取决于Sam将使用哪种平台.他已将问题标记为C ++,因此,最好的猜测是他将使用stl.因此,要读取文件,他将需要带有getline()的sdt :: istream.他将需要使用std :: string的方法find(),rfind()等方法来解析每一行.

如果他选择的库是MFC,那么它将是具有其ReadString方法的CStdioFile.然后,他将需要使用Find,Tokenize方法处理CString. ATL具有类似的类

如果是C#,那么那里也有类似的类.
I think the question was how to read the strings from the text file.
So, it depends on what platform Sam is going to use. He has tagged the question as C++, so, the best guess is that he is going to use an stl. So, for reading from files he will need sdt::istream with getline(). The he will need to parse each line using std::string''s methods find(), rfind(), etc. methods.

If his library of choice is MFC then it will be CStdioFile with its ReadString method. Then he will need to process CStrings using Find, Tokenize methods. ATL has similar classes

If it is C#, then there are similar classes there as well.


这篇关于C ++数值分析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆