Hozzászólások
-
SzerzőBejegyzés
-
egyebkent valoban, elegge kezdo vagyok, ilyeneket kb. most csinalok eloszor, de sokat tanulok belole es ha segitenek annal hasznosabb a dolog… 🙂
bocs, csak beomlesztettem a javaslataidat. nem gondoltam ezt tenyleges .cpp-nek. csak tajekozodni szerettem volna, hogy nem hagytam-e ki semmit…
bocs, csak beomlesztettem a javaslataidat. nem gondoltam ezt tenyleges .cpp-nek. csak tajekozodni szerettem volna, hogy nem hagytam-e ki semmit…
Okes. Szerinted jo lesz igy? + hogyan tudnam kiiratni a végeredményt, ez ugye 1db. mátrix lesz. (jelen esetben a tíz matrix összege osztva 10-zel)
Code:// for functions rand and srand
#include
//
#include
// input/output stream
#include
// for function time, and for data type time_t
#include
//
#include#include „matrix.h”
using namespace std;
const float M_2PIf = 6.283185307179586476925286766559f;
const float M_PIf = 3.141592653589793238462643383279f;/* ——————————————————————– */
bool init_rnd()
{
time_t TIME;
ctime(&TIME);
srand48((unsigned int)(TIME));
return true;
}// Random szamokat general egyenletes eloszlassal (az [a,b[ intervallumon):
double uniform(double a, double b)
{
return a+(b-a)*drand48();
}/* ——————————————————————– */
struct vektor {
float x,y,z;
};class Matrix3x3 {
private:
float tomb[3][3]; // minek vacakolni?public:
void init(vektor a, vektor b){
// itt feltoltod a ‘tomb’-ot
}
Matrix3x3 &operator +=(Matrix3x3 b){ // osszeadas
int x,y;
for(x=0; x<3; x++)
for(y=0; y<3; y++)
tomb[x][y] += b.tomb[x][y];
return *this;
}
Matrix3x3 &operator/=(float c){ // osztas skalarral
int x,y;
for(x=0; x<3; x++)
for(y=0; y<3; y++)
tomb[x][y] /= c;
return *this;
}
};/* ——————————————————————– */
int main(void) {
vektor tar[10]; // itt vannak a vektoraink feltoltve; 10 db.
int i;
for (i=0;i<10;i++) {
float phi = uniform(0.0f, M_2PIf);
float costheta = uniform(-1.0f, 1.0f);
float x = 1.0f * sqrtf(1-costheta*costheta) * cosf(phi);
float y = 1.0f * sqrtf(1-costheta*costheta) * sinf(phi);
float z = 1.0f * costheta;//cout << x << " " << y << " " << z << endl;
// taroljuk el
tar[I].x = x;
tar[I].y = y;
tar[I].z = z;}
/* ——————————————————————– */
void Matrix::init(vektor &a, vektor &b){
tomb[0][0] = a.x*b.x;
tomb[1][0] = a.x*b.y;
tomb[2][0] = a.x*b.z;
tomb[0][1] = a.y*b.x;
tomb[1][1] = a.y*b.y;
tomb[2][1] = a.y*b.z;
tomb[0][2] = a.z*b.x;
tomb[1][2] = a.z*b.y;
tomb[2][2] = a.z*b.z;
}/* ——————————————————————– */
/* ——————————————————————– */
Matrix m[10]; // matrixokfor(i=0; i<n; i++)
m[I].init(tar[I]; // minden vektor atalakitvaMatrix osszeg = m[0];
for(i=1; i<n; i++)
osszeg += m[I];m /= 10;
// most m-ben megvan ami kell neked
/* ——————————————————————– */return 0;
}[/I][/I][/I][/I][/I][/I]
Okes. Szerinted jo lesz igy? + hogyan tudnam kiiratni a végeredményt, ez ugye 1db. mátrix lesz. (jelen esetben a tíz matrix összege osztva 10-zel)
Code:// for functions rand and srand
#include
//
#include
// input/output stream
#include
// for function time, and for data type time_t
#include
//
#include#include „matrix.h”
using namespace std;
const float M_2PIf = 6.283185307179586476925286766559f;
const float M_PIf = 3.141592653589793238462643383279f;/* ——————————————————————– */
bool init_rnd()
{
time_t TIME;
ctime(&TIME);
srand48((unsigned int)(TIME));
return true;
}// Random szamokat general egyenletes eloszlassal (az [a,b[ intervallumon):
double uniform(double a, double b)
{
return a+(b-a)*drand48();
}/* ——————————————————————– */
struct vektor {
float x,y,z;
};class Matrix3x3 {
private:
float tomb[3][3]; // minek vacakolni?public:
void init(vektor a, vektor b){
// itt feltoltod a ‘tomb’-ot
}
Matrix3x3 &operator +=(Matrix3x3 b){ // osszeadas
int x,y;
for(x=0; x<3; x++)
for(y=0; y<3; y++)
tomb[x][y] += b.tomb[x][y];
return *this;
}
Matrix3x3 &operator/=(float c){ // osztas skalarral
int x,y;
for(x=0; x<3; x++)
for(y=0; y<3; y++)
tomb[x][y] /= c;
return *this;
}
};/* ——————————————————————– */
int main(void) {
vektor tar[10]; // itt vannak a vektoraink feltoltve; 10 db.
int i;
for (i=0;i<10;i++) {
float phi = uniform(0.0f, M_2PIf);
float costheta = uniform(-1.0f, 1.0f);
float x = 1.0f * sqrtf(1-costheta*costheta) * cosf(phi);
float y = 1.0f * sqrtf(1-costheta*costheta) * sinf(phi);
float z = 1.0f * costheta;//cout << x << " " << y << " " << z << endl;
// taroljuk el
tar[I].x = x;
tar[I].y = y;
tar[I].z = z;}
/* ——————————————————————– */
void Matrix::init(vektor &a, vektor &b){
tomb[0][0] = a.x*b.x;
tomb[1][0] = a.x*b.y;
tomb[2][0] = a.x*b.z;
tomb[0][1] = a.y*b.x;
tomb[1][1] = a.y*b.y;
tomb[2][1] = a.y*b.z;
tomb[0][2] = a.z*b.x;
tomb[1][2] = a.z*b.y;
tomb[2][2] = a.z*b.z;
}/* ——————————————————————– */
/* ——————————————————————– */
Matrix m[10]; // matrixokfor(i=0; i<n; i++)
m[I].init(tar[I]; // minden vektor atalakitvaMatrix osszeg = m[0];
for(i=1; i<n; i++)
osszeg += m[I];m /= 10;
// most m-ben megvan ami kell neked
/* ——————————————————————– */return 0;
}[/I][/I][/I][/I][/I][/I]
A logikaja es az elmelet vilagos. Nekem csak a kod irassal vannak gondjaim
A logikaja es az elmelet vilagos. Nekem csak a kod irassal vannak gondjaim
Persze. A generalt random vektort osszeszorzom onmagaval tenzorialisan… Csak ezt kellene beletenni az altalad vazolt kodba…valahogy
Persze. A generalt random vektort osszeszorzom onmagaval tenzorialisan… Csak ezt kellene beletenni az altalad vazolt kodba…valahogy
Bocsi a szőrözésért, csak talaltam valahol egy ilyet:
Code:template
Matrix TensorProduct(Matrix& A,Matrix& B) {if (A.M == 1 && A.N == 1) {
return B;
}if (B.M == 1 && B.N == 1)
return A;int rows = A.M*B.M;
int cols = A.N*B.N;Matrix M(rows,cols);
for (int i=0;i<rows;i++)
for (int j=0;j<cols;j++)
M(i,j) = A(i/B.M,j/B.N) * B(i%B.M,j%B.N);return M;
}ami egy vektorbol csinal nekem 3×3-as matrixot. Most ezt vagy ehhez hasonlot kellene ide atultetnem, de ez NEKEM nem tunik egyszerunek…
-
SzerzőBejegyzés
legutóbbi hsz