C#新手 - 学习如何使用矩阵 [英] C# Newbie - Learning How to Use Matrices

查看:148
本文介绍了C#新手 - 学习如何使用矩阵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在C#中定义矩阵的元素?



我找到了矩阵类,但我需要学习如何使用它。



微软在该领域似乎有点模糊。



我以为我会试试以下,但它不起作用。



myMatrix = {1,2,3; 4,5,6; 7,8,9};



我需要能够使矩阵等于特定值。我还需要单独分配它们,如:



myMatrix(1,2)= 3;







myMatrix(3,3)= 6.



(我意识到这段代码是可能不完美。)



如果我通过定义如何进行数学运算来创建处理复数的头文件,这会有效吗?



我将不得不用复杂的数字来完成这项工作。我可以写一个复数头文件,定义数学,并期望它工作吗?



更新



是否有一个网站,人们了解矩阵是什么,并可以在C#访问中实现它?鉴于该数学领域固有的数学运算,矩阵类是必要的。该类包含矩阵运算,包括反转矩阵。



有人可以告诉我如何在C#窗体中包含C ++中的矩阵类项目的方式是让C#程序识别矩阵?有人会建议我如何让这个矩阵识别复数(也许还可以通过集成C ++ math.h)?我明白我需要一个包装。我还需要编译器设置。



我不想要模糊的建议,或者建议去其他地方尝试完全不同的东西。如果您没有这方面的专业知识,那么请不要发表评论。

How does one define the elements of a matrix in C#?

I found the matrix class, but I need to learn how to use it.

Microsoft seems to be a little vague in that area.

I thought I'd try the following, but it doesn't work.

myMatrix={ 1,2,3; 4,5,6; 7,8,9};

I need to be able to make the matrix equal to specific values. I also need to assign them individually, as in:

myMatrix(1,2) = 3;

or

myMatrix(3,3) = 6.

(I realize this code is probably imperfect.)

Will this work if I create a header file that deals with complex numbers by defining how to do the math?

I'm going to have to make this work with complex numbers. Can I write a "complex number" header file, defining the math, and expect it to work?

Update

Is there a web site at which people who understand what a matrix is and can implement it in C# visit? A matrix class is necessary given the mathematical operations that are intrinsic to that area of mathematics. The class houses the matrix operations, including inverting the matrix.

Can someone please show me either how to include the matrix class that is part of C++ in a C# windows forms project in a manner that will get the C# program to recognize the matrix? Would someone then suggest how I might get this matrix to recognize complex numbers (perhaps also by integrating C++ math.h)? I understand that I need a "wrapper". I also need the compiler settings.

I don't want vague advice, or a suggestion to go elsewhere and try something completely different. If you don't have the expertise to do this, then please don't comment.

推荐答案

如果您找到了这个Matrix类:https://msdn.microsoft.com/en-us/library/system。 drawing.drawing2d.matrix(v = vs.110).aspx [ ^ ]我不确定这正是你的标准。它用于图形变换,而不是通用矩阵操作 - 它甚至只有3 x 3!



听起来你正在寻找的是一个多维数组:

If you found this Matrix class: https://msdn.microsoft.com/en-us/library/system.drawing.drawing2d.matrix(v=vs.110).aspx[^] I'm not sure it's exactly what you are lookign for. It's intended for graphics transforms, not general purpose matrix operations - it's even only ever a 3 x 3!

It sounds like what you are looking for is a multidimensional array:
int[,] myMatrix = new int[4, 4];
myMatrix[0, 0] = -7;
myMatrix[1, 2] = 3;
myMatrix[3, 3] = 6;

或许你想看看其中的一些: Matrix class c#CodeProject [ ^ ],其中将包含更多基于矩阵的操作。

Or perhaps you want to have a look at some of these: Matrix class c# CodeProject[^] which will include more matrix based operations.


在语言中没有预定义的东西,并且,想一想,不应该有这样的东西。 Matrix只是一个带操作的数据结构。

它可以是专门的类 System.Drawing.Drawing2D.Matrix 用于图形(转换):< a href =https://msdn.microsoft.com/en-us/library/system.drawing.graphics.transform%28v=vs.110%29.aspx> https://msdn.microsoft.com/en -us / library / system.drawing.graphics.transform%28v = vs.110%29.aspx [ ^ ],它可能是某个等级的数组,也可能是数据具有全面矩阵运算的类型。除了分割或矩阵求逆运算符之外,自己编写并不困难。所以,你可能需要一些线性代数库。



参见Math.NET: http://numerics.mathdotnet.com [ ^ ]。



另请参阅此比较图表: https://en.wikipedia.org/wiki/Comparison_of_linear_algebra_libraries [< a href =https://en.wikipedia.org/wiki/Comparison_of_linear_algebra_libraries\"target =_ blanktitle =New Window> ^ ]。



-SA
There is no such thing predefined in language, and, come to think about, there should not be such thing. Matrix is just a data structure with operations.
It can be specialized class System.Drawing.Drawing2D.Matrix used in graphics (transform): https://msdn.microsoft.com/en-us/library/system.drawing.graphics.transform%28v=vs.110%29.aspx[^], it could be the array of some rank, and it could be a data type with comprehensive matrix operations. It's not so hard to write by yourself, except the division or matrix inversion operators. So, you may need some linear algebra library.

See, for example, Math.NET: http://numerics.mathdotnet.com[^].

See also this comparison chart: https://en.wikipedia.org/wiki/Comparison_of_linear_algebra_libraries[^].

—SA


您的解决方案:

- 阅读文档

- 关注教程



使用Google在互联网上查找它们。



PS:如果您想要更好的答案,请告诉我们你至少完成了基础研究以及你的发现有什么问题。
Your solution:
- Read documentation
- follow tutorials

Use Google to find them on internet.

PS: If you want better answers, let us know that you have done at least basic research and what is wrong in your findings.


这篇关于C#新手 - 学习如何使用矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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