I had just started to learn about Math.NET Numerics and find this useful and powerful for Matrix Multiplication purpose. It's quite challenging for me now as I had just started to learn C#, I hope I could find some solutions here to assist me throughout the journey. Thank you in advance!
Objectives:
Extract data from Excel file which is filled in the first & second column and put them in a nx2 Matrix (where n can be any number of rows, here I set 3000, so it's 3000x2 Matrix)
Extract data from the first column of the Matrix to multiply by 5 and store in a vector 1 (VColumn). Similarly, extract data from the second column of the Matrix to multiply by 2 and store in a vector 2 (VRow). With this method I'm able to multiply each column with different values. (Is there any other more direct methods to multiply each column value individually in Matrix form using .Multiply keywords?) From what I see from the output, it is display in a line instead of one column.
- To place vector 1 and vector 2 into Matrix form (3000x2 Matrix format). But the output I'm getting is 0. Not sure this is the correct way though... how do I code for this part or any other alternatives?
I'm not sure if this is the right way to code for Matrix Multiplications. If there are alternative ways, please do share as I'm still learning. Many thanks!
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MathNet.Numerics;
using MathNet.Numerics.LinearAlgebra;
using MathNet.Numerics.Data.Text;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Matrix<Double> fileMatrix = DelimitedReader.Read<Double>
(@"C:\Users\Student\Downloads\MatricesData.xls", false, "\t", true); //Objective 1
textBox1.AppendText(fileMatrix.ToString());
Vector<Double> x = Vector<Double>.Build.Dense(3000, 1); //Objective 2
Vector<Double> y = Vector<Double>.Build.Dense(3000, 1);
Vector<Double> VColumn = fileMatrix.Column(0);
Vector<Double> VRow = fileMatrix.Column(1);
VColumn.Multiply(5.0, x);
VRow.Multiply(1.0, y);
textBox1.AppendText(x.ToString());
textBox1.AppendText(y.ToString());
Matrix<Double> z = Matrix<Double>.Build.Dense(3000, 2); //Objective 3: Need help
z.InsertColumn(0, VColumn);
z.InsertColumn(1, VRow);
textBox1.AppendText(z.ToString());
}
}
}