Upload files to "ex1G_dense_matrices_access"
This commit is contained in:
parent
bdf01bd761
commit
394e1be746
4 changed files with 228 additions and 0 deletions
52
ex1G_dense_matrices_access/ProductMatrix.h
Normal file
52
ex1G_dense_matrices_access/ProductMatrix.h
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
#pragma once
|
||||
#include <cmath>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
using namespace std;
|
||||
|
||||
class ProductMatrix
|
||||
{
|
||||
private:
|
||||
vector<double> u;
|
||||
vector<double> v;
|
||||
size_t n;
|
||||
size_t m;
|
||||
|
||||
public:
|
||||
vector<double> Mult(const vector<double> &x) const
|
||||
{
|
||||
vector<double> y(n,0);
|
||||
for(int i = 0; i < n; ++i)
|
||||
{
|
||||
for(int j = 0; j < m; ++j)
|
||||
{
|
||||
y[i] += v[j]*x[j];
|
||||
}
|
||||
y[i] *= u[i];
|
||||
}
|
||||
return y;
|
||||
}
|
||||
|
||||
vector<double> MultT(const vector<double> &y) const
|
||||
{
|
||||
vector<double> x(m,0);
|
||||
for(int j = 0; j < m; ++j)
|
||||
{
|
||||
for(int i = 0; i < n; ++i)
|
||||
{
|
||||
x[j] += y[i]*u[i];
|
||||
}
|
||||
x[j] *= v[j];
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
ProductMatrix(const vector<double> &u, const vector<double> &v)
|
||||
{
|
||||
n = u.size();
|
||||
m = v.size();
|
||||
this->u = u;
|
||||
this->v = v;
|
||||
|
||||
}
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue