简体   繁体   English

如何在 Visual Studios 中使用 math.Net 数字

[英]How to use math.Net numerics in Visual Studios

I am just testing to see if I can utilize math.Net Numerics for upcoming Linear Algebra classes and I am having trouble.我只是在测试我是否可以将 math.Net Numerics 用于即将到来的线性代数课程,但我遇到了麻烦。 I normally use R and Python but I felt like testing this out.我通常使用 R 和 Python,但我想测试一下。 I literally am brand new to Visual Studio.我真的是 Visual Studio 的新手。 For some reason I get like 26 errors when trying to just test how to script for instance the first example in this website below.出于某种原因,我在尝试测试如何编写脚本时遇到了 26 个错误,例如下面本网站中的第一个示例。 I added the math.Net Numerics 3.20.0 in the NuGet Package Manager.我在 NuGet 包管理器中添加了 math.Net Numerics 3.20.0。 I also have attached what my UI looks like.我还附上了我的用户界面的样子。 Anybody know how I need to start the script.任何人都知道我需要如何启动脚本。 Do I need to open with a class and method?我需要用类和方法打开吗? 在此处输入图片说明

https://numerics.mathdotnet.com/#Using-Math-NET-Numerics-with-C https://numerics.mathdotnet.com/#Using-Math-NET-Numerics-with-C

Here is the code:这是代码:

using MathNet.Numerics.LinearAlgebra;
using MathNet.Numerics.LinearAlgebra.Double;

Matrix<double> A = DenseMatrix.OfArray(new double[,] {
        {1,1,1,1},
        {1,2,3,4},
        {4,3,2,1}});
Vector<double>[] nullspace = A.Kernel();

// verify: the following should be approximately (0,0,0)
(A* (2* nullspace[0] - 3* nullspace[1]))

Here are the errors when I copy and paste code into a new project in VS.以下是我将代码复制并粘贴到 VS 中的新项目时出现的错误。

Error CS8124 Tuple must contain at least two elements.错误 CS8124 元组必须至少包含两个元素。 Error CS1026 ) expected Error CS1031 Type expected错误 CS1026 ) 预期错误 CS1031 类型预期
Error CS8124 Tuple must contain at least two elements.错误 CS8124 元组必须至少包含两个元素。
Error CS1026 ) expected错误 CS1026) 预期
Error CS1022 Type or namespace definition, or end-of-file expected错误 CS1022 类型或命名空间定义,或预期的文件结尾
Error CS1031 Type expected错误 CS1031 类型预期
Error CS0650 Bad array declarator: To declare a managed array the rank specifier precedes the variable's identifier.错误 CS0650 错误的数组声明符:要声明托管数组,秩说明符位于变量的标识符之前。 To declare a fixed size buffer field, use the fixed keyword before the field type.要声明固定大小的缓冲区字段,请在字段类型之前使用 fixed 关键字。 Error CS0270 Array size cannot be specified in a variable declaration (try initializing with a 'new' expression) Error CS1002 ;错误 CS0270 无法在变量声明中指定数组大小(尝试使用“新”表达式进行初始化)错误 CS1002; expected Error CS1022 Type or namespace definition, or end-of-file expected预期的错误 CS1022 类型或命名空间定义,或预期的文件结尾
Error CS1031 Type expected错误 CS1031 类型预期
Error CS0650 Bad array declarator: To declare a managed array the rank specifier precedes the variable's identifier.错误 CS0650 错误的数组声明符:要声明托管数组,秩说明符位于变量的标识符之前。 To declare a fixed size buffer field, use the fixed keyword before the field type.要声明固定大小的缓冲区字段,请在字段类型之前使用 fixed 关键字。
Error CS0270 Array size cannot be specified in a variable declaration (try initializing with a 'new' expression) Error CS1002 ;错误 CS0270 无法在变量声明中指定数组大小(尝试使用“新”表达式进行初始化)错误 CS1002; expected预期的
Error CS1022 Type or namespace definition, or end-of-file expected错误 CS1022 类型或命名空间定义,或预期的文件结尾
Error CS0116 A namespace cannot directly contain members such as fields or methods错误 CS0116 命名空间不能直接包含成员,如字段或方法
Error CS0116 A namespace cannot directly contain members such as fields or methods Error CS0214 Pointers and fixed size buffers may only be used in an unsafe context错误 CS0116 命名空间不能直接包含成员,如字段或方法错误 CS0214 指针和固定大小的缓冲区只能在不安全的上下文中使用
Error CS0208 Cannot take the address of, get the size of, or declare a pointer to a managed type ('?')错误 CS0208 无法获取托管类型 ('?') 的地址、获取其大小或声明指向托管类型的指针
Error CS0102 The type '' already contains a definition Error CS0214 Pointers and fixed size buffers may only be used in an unsafe Error CS0208 Cannot take the address of, get the size of, or declare a pointer to a managed type ('?') Error CS0102 The type '' already contains a definition错误 CS0102 类型 '' 已经包含定义错误 CS0214 指针和固定大小的缓冲区只能用于不安全的错误 CS0208 无法获取托管类型的地址、获取其大小或声明指向托管类型的指针 ('?')错误 CS0102 类型 '' 已经包含一个定义
Error CS0103 The name 'A' does not exist in the current context错误 CS0103 当前上下文中不存在名称“A”
Error CS0103 The name 'A' does not exist in the current context.错误 CS0103 当前上下文中不存在名称“A”。

NVM figured it out. NVM 想通了。

using System;
using MathNet.Numerics.LinearAlgebra;
using MathNet.Numerics.LinearAlgebra.Double;


namespace check1
{
    class Program
    {
        static void Main(string[] args)
        {
            Matrix<double> A = DenseMatrix.OfArray(new double[,] {
        {1,1,1,1},
        {1,2,3,4},
        {4,3,2,1}});
            Vector<double>[] nullspace = A.Kernel();

            // verify: the following should be approximately (0,0,0)
            Console.Write(A * (2 * nullspace[0] - 3 * nullspace[1]));
            Console.Read();
        }
    }
}

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

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