使用C#和.NET进行矩阵乘法 [英] matrix multiplication using C# and .NET

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

问题描述

用C#和.NET编写的矩阵乘法程序怎么样?

how is the program for matrix multiplication written in C# and .NET?

推荐答案

这里不能这样工作。



以下是询问者的预期:

1. 先尝试你想做什么!你可能会发现它并不那么难。

2.制定你所做的看似问题/不工作的事情。



尝试一下,告诉你是否面临问题。

各位会员非常乐意为此提供帮助。




现在,从这里开始:

MSDN:Matrix .Multiply方法 [ ^ ]

利用C#的功能来强大您的科学计算项目 [ ^ ]
It does not work like this here.

Here is what is expected of enquirers:
1. TRY first what you want to do! You may find that it's not that hard.
2. Formulate what was done by you that looks like an issue/not working.

Try them and tell if you face issues.
Members will be more than happy to help like this.


For now, start from here:
MSDN: Matrix.Multiply Method [^]
Harness the Features of C# to Power Your Scientific Computing Projects[^]


for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
        for (int k = 0; k < N; k++) {
            C[i,j] += A[i,k] * B[k,j];
        }
    }
}


使用系统;



class Program

{

static void Main(string [] args)

{

Console.WriteLine (输入行数和列数);

int r = int.Parse(Console.ReadLine());

int c = int.Parse(Console .ReadLine());

int [,] a = new int [r,c];

int [,] b = new int [r,c];

int [,] res = new int [r,c];

Console.WriteLine(输入第一个矩阵的元素);

for(int i = 0; i< r; i ++)

{

string [] s = Console.ReadLine()。Split('');

for(int j = 0; j< c; j ++)

{

a [i,j] = int.Parse(s [j]);

}

} < br $>


Console.WriteLine(第一个矩阵的元素是);

for(int i = 0;我< R等i ++)

{

for(int j = 0; j< c; j ++)

{

Console.Write(a [i,j] +);

}

}

Console.WriteLine();

Console.WriteLine(输入元素到第二个矩阵);

for(int i = 0; i< r; i ++)

{

string [] s1 = Console.ReadLine()。Split('');

for(int j = 0; j< c; j ++)

{

b [i,j] = int.Parse(s1 [j]);

}

}

Console.WriteLine(第二个矩阵的元素是);

for(int i = 0; i< r; i ++)

{

for(int j = 0; j< c; j ++)

{

Console.Wr ite(b [i,j] +);

}

}



for(int i = 0;我< R等i ++)

{



for(int j = 0; j< c; j ++)

{

res [i,j] = 0;

for(int k = 0; k< r; k ++)

{

res [i,j] + = a [i,k] * b [k,j];

}



}

}

Console.WriteLine(\\\
Matrix Multiplication is);

for(int i = 0; i< r; i ++)

{

Console.WriteLine();

for(int j = 0; j< c; j ++)

{

Console.Write(res [i,j] +);

}

}

Console.ReadLine();



}

}
using System;

class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter the number of rows and columns");
int r = int.Parse(Console.ReadLine());
int c = int.Parse(Console.ReadLine());
int[,] a = new int[r, c];
int[,] b = new int[r, c];
int[,] res = new int[r, c];
Console.WriteLine("Enter the elments to first matrix");
for (int i = 0; i < r; i++)
{
string[] s = Console.ReadLine().Split(' ');
for (int j = 0; j < c; j++)
{
a[i, j] = int.Parse(s[j]);
}
}

Console.WriteLine("the elements of first matrix are");
for (int i = 0; i < r; i++)
{
for (int j = 0; j < c; j++)
{
Console.Write(a[i, j] + " ");
}
}
Console.WriteLine("");
Console.WriteLine("Enter the elements to second matrix");
for (int i = 0; i < r; i++)
{
string[] s1 = Console.ReadLine().Split(' ');
for (int j = 0; j < c; j++)
{
b[i, j] = int.Parse(s1[j]);
}
}
Console.WriteLine("the elements of second matrix are");
for (int i = 0; i < r; i++)
{
for (int j = 0; j < c; j++)
{
Console.Write(b[i, j] + " ");
}
}

for (int i = 0; i < r; i++)
{

for (int j = 0; j < c; j++)
{
res[i, j] = 0;
for (int k = 0; k < r; k++)
{
res[i, j] += a[i, k] * b[k, j];
}

}
}
Console.WriteLine("\nThe Matrix Multiplication is");
for (int i = 0; i < r; i++)
{
Console.WriteLine("");
for (int j = 0; j < c; j++)
{
Console.Write(res[i, j]+" ");
}
}
Console.ReadLine();

}
}


这篇关于使用C#和.NET进行矩阵乘法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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