Перегрузка оператора умножения: нужно матрицу умножить на вектор, в результате нули - C#
Формулировка задачи:
Проблема в перегрузке умножения, нужно матрицу умножить на вектор, но получаю нули в результате. Смотрел как в отладчике наращиваются переменные и элементы вектора всегда нули. Наследование может так сказывается, не знаю.
Благодарю за любую помощь))
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace попытка1
{
class Matrix
{
public int _size;
public int[,] mas;
public Matrix(int _size)
{
this._size = _size;
this.mas = new int[this._size, this._size];
}
public void read()
{
Console.WriteLine("Введите " + Math.Pow(_size, 2) + " элементa(элементы матрицы)");
for (int i = 0; i < _size; i++)
{
for (int j = 0; j < _size; j++)
{
mas[i, j] = int.Parse(Console.ReadLine());
}
}
}
public virtual void show()
{
for (int i = 0; i < _size; i++)
{
Console.WriteLine();
for (int j = 0; j < _size; j++)
{
Console.Write(mas[i, j] + "\t");
}
}
}
public void trans()
{
int tmp;
for (int i = 0; i < _size; i++)
{
for (int j = 0; j < i; j++)
{
tmp = mas[i, j];
mas[i, j] = mas[j, i];
mas[j, i] = tmp;
}
}
}
public static extraMatrix operator *(Matrix matr1, extraMatrix matr2)
{
extraMatrix result = new extraMatrix(matr2._Column);
if (matr1._size != matr2._Column)
throw new ArgumentException("Размерность матрицы и длина вектора должны строго совпадать");
else
{
int k = 0;
int g = 0;
for (int i = 0; i < 1; i++)
{
for (int j = 0; j < matr2._Column; j++)
{
k += matr1.mas[g, j];
}
result.mas[i, g] = matr2.mas[i, g];
g++;
}
return result;
}
}
}
public interface IVector
{
void CreateVector();
}
class extraMatrix : Matrix, IVector
{
public int _Column;
public int[,] extraMas;
public extraMatrix(int _Column)
: base(_Column)
{
this._Column = _Column;
this.extraMas = new int[1, _Column];
}
public void CreateVector()
{
Console.WriteLine("\n\nВведите " + _Column + " элементa(элементы вектора)");
for (int i = 0; i < 1; i++)
{
for (int j = 0; j < _Column; j++)
{
extraMas[i, j] = int.Parse(Console.ReadLine());
}
}
}
public override void show()
{
Console.WriteLine("\n\n");
for (int i = 0; i < 1; i++)
{
for (int j = 0; j < _Column; j++)
{
Console.Write(extraMas[i, j] + "\t");
}
}
}
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Введите размерность матрицы");
int _size = int.Parse(Console.ReadLine());
Console.WriteLine("Введите длину вектора");
int _sizeRow = int.Parse(Console.ReadLine());
Matrix one = new Matrix(_size);
one.read();
one.show();
extraMatrix two = new extraMatrix(_sizeRow);
two.CreateVector();
two.show();
extraMatrix three = new extraMatrix(_sizeRow);
three = one * two;
three.show();
Console.ReadKey();
}
}
}
}Решение задачи: «Перегрузка оператора умножения: нужно матрицу умножить на вектор, в результате нули»
textual
Листинг программы
int k = 0;
int g = 0;
for (int i = 0; i < 1; i++)
{
for (int j = 0; j < matr2._Column; j++)
{
k += matr1.mas[g, j];
}
result.mas[i, g] = k * matr2.mas[i, g];
g++;
}