Dateien nach „BSP_1_G“ hochladen

This commit is contained in:
Georg Thomas Mandl 2025-10-23 00:49:40 +02:00
commit a77a9f9fca
4 changed files with 102 additions and 0 deletions

48
BSP_1_G/matrixprod.cpp Normal file
View file

@ -0,0 +1,48 @@
#include "matrixprod.h"
#include "sigmoid.h"
MatrixProd::MatrixProd()
{
//ctor
}
MatrixProd::MatrixProd(vector<double> uc, vector<double> vc)
{
nrow = uc.size();
mcol = vc.size();
u = uc;
v = vc;
}
vector<double> MatrixProd::Mult(const vector<double> &x) const
{
vector<double> y(nrow,0);
for(int n=0; n<nrow; ++n)
{
for(int m=0; m<mcol; ++m)
{
y[n] += v[m]*x[m];
}
y[n] *= u[n];
}
return y;
}
vector<double> MatrixProd::MultT(const vector<double> &x) const
{
vector<double> y(mcol,0);
for(int m=0; m<mcol; ++m) // over columns
{
for(int n=0; n<nrow; ++n) // over rows
{
y[m] += u[n]*x[n];
}
y[m] *= v[m];
}
return y;
}
MatrixProd::~MatrixProd()
{
//dtor
}

33
BSP_1_G/matrixprod.h Normal file
View file

@ -0,0 +1,33 @@
#ifndef MATRIXPROD_H
#define MATRIXPROD_H
#include <vector>
using namespace std;
class MatrixProd
{
public:
/** Default constructor */
MatrixProd();
/** Constructor */
MatrixProd(vector<double> uc, vector<double> vc);
vector<double> Mult(const vector<double> &x) const;
vector<double> MultT(const vector<double> &x) const;
/** Default destructor */
virtual ~MatrixProd();
protected:
private:
vector<double> u; //!< Member variable "u"
vector<double> v; //!< Member variable "v"
int nrow; //!< Member variable "nrow"
int mcol; //!< Member variable "mcol"
};
#endif // MATRIXPROD_H

11
BSP_1_G/sigmoid.cpp Normal file
View file

@ -0,0 +1,11 @@
#include "sigmoid.h"
double sigmoid(const double &x)
{
return 1.0/(1+exp(-x));
}
double xk(const int & k, const int & nm)
{
return 10*k/(nm-1) - 5;
}

10
BSP_1_G/sigmoid.h Normal file
View file

@ -0,0 +1,10 @@
#ifndef SIGMOID_H_INCLUDED
#define SIGMOID_H_INCLUDED
#include "cmath"
double sigmoid(const double &x);
double xk(const int & k, const int & nm);
#endif // SIGMOID_H_INCLUDED