Умножение матрицы на вектор, исправить код - C#
Формулировка задачи:
При выводе координат вектора(выделено красным) мне всегда выдает 0000. какие бы числа не заводила. я уже просто тупо не могу найти ошибку. помогите, я совсем тяжко начинающая.программа не дописана- не хочу продолжать дальше,не избавившись от ошибки
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication11 { class Program { double[,] massiv=new double[4,4]; double[] vektor= new double[4]; double[] result = new double[4]; public void Programm() { int m, n; for (m = 0; m < 4; m++) { for (n = 0; n < 4; n++) { Console.WriteLine("Введите эламент матрицы № {0},{1}", m, n); massiv[m, n] = System.Convert.ToDouble(Console.ReadLine()); } } } public void Programm2() { int x; double[] vektor = new double[4]; for (x = 0; x < 4; x++) { Console.WriteLine("Введите координату вектора №" + x); vektor[x] = System.Convert.ToDouble(Console.ReadLine()); } }
public void Prosmotr() { Console.WriteLine("Вектор"); for (int x = 0; x < vektor.Length; ++x) Console.Write(+vektor[x]); Console.WriteLine();
} static void Main(string[] args) { Program matriza = new Program(); Program vetorstroka = new Program(); Program vid1 = new Program(); matriza.Programm(); vetorstroka.Programm2(); vid1.Prosmotr(); Console.WriteLine("Нажмите Enter для выхода из программы"); Console.Read(); } } }
Решение задачи: «Умножение матрицы на вектор, исправить код»
textual
Листинг программы
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication11 { public class Matrix { double[,] matrix; public int Row { get; protected set; } public int Column { get; protected set; } public Matrix(int row, int column) { Row = row; Column = column; matrix = new double[row, column]; } public Matrix Multiple(Matrix value) { Matrix result = new Matrix(Row, value.Column); for (int i = 0; i < Row; i++) for (int j = 0; j < value.Column; j++) for (int k = 0; k < value.Row; k++) result.matrix[i, j] += matrix[i, k] * value.matrix[k, j]; return result; } public void Read() { for (int i = 0; i < Row;i++ ) for (int j = 0; j < Column; j++) { Console.Write("Введите элемент [{0},{1}]: ", i+1, j+1); matrix[i, j] = System.Convert.ToDouble(Console.ReadLine()); } } public void Print() { for (int i=0; i<Row; i++) { for (int j = 0; j < Column; j++) Console.Write("{0:f2} ", matrix[i, j]); Console.WriteLine(); } } } class Program { static void Main(string[] args) { Matrix vector = new Matrix(1, 4); Matrix matrix = new Matrix(4, 4); Console.Clear(); Console.WriteLine("Ввод вектора"); vector.Read(); Console.WriteLine("\nВвод матрицы"); matrix.Read(); Console.Clear(); Matrix result = vector.Multiple(matrix); Console.WriteLine("Вектор"); vector.Print(); Console.WriteLine("\nМатрица"); matrix.Print(); Console.WriteLine("\nРезультат умножения матрицы на вектор"); result.Print(); Console.WriteLine("\nНажмите любую клавишу для выхода из программы"); Console.ReadKey(true); } } }
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д