Kezdőlap › Fórumok › Programozás › matrix osztaly osszeadasra
- This topic has 178 hozzászólás, 8 résztvevő, and was last updated 17 years, 4 months telt el by
uzsolt.
-
SzerzőBejegyzés
-
2008-02-21-22:01 #2154649
A logikaja es az elmelet vilagos. Nekem csak a kod irassal vannak gondjaim
2008-02-21-22:01 #2154650A logikaja es az elmelet vilagos. Nekem csak a kod irassal vannak gondjaim
2008-02-21-22:14 #21546513×3-as matrixhoz mukodik a „paraszt” modszer is:
Code: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;
}Es ezzel meg is van.
*mindenfele elgepeles es hibas indexeles joga fenntartva 😀
2008-02-21-22:14 #21546523×3-as matrixhoz mukodik a „paraszt” modszer is:
Code: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;
}Es ezzel meg is van.
*mindenfele elgepeles es hibas indexeles joga fenntartva 😀
2008-02-21-22:20 #2154653Okes. 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]
2008-02-21-22:20 #2154654Okes. 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]
2008-02-21-22:34 #2154655Szerintem nem fog lefordulni a program. Nekem ugy tunik, neked a c es c++ alapok ujboli attekintese nem artana.
peldaul: // ez itt egy megjegyes
Az en (nevetseges) megjegyzeseimet egy az egyben beomlesztetted a programba.A Matrix::init ketszer van ertelmezve, mas parameterekkel, raadasul egyszer a main fuggveny kozepen.
Egyszer egy ‘tar’ nevu tombod van (vektor tar[10]), maskor ‘m’ a tomb neve. Annak ugyanaz kellene legyen a neve.
A tobbi hibarol majd szol a fordito 🙂
A kiiratast pedig egy uj metodussal a legegyszerubb elintezni a Matrix osztalyban.
2008-02-21-22:34 #2154656Szerintem nem fog lefordulni a program. Nekem ugy tunik, neked a c es c++ alapok ujboli attekintese nem artana.
peldaul: // ez itt egy megjegyes
Az en (nevetseges) megjegyzeseimet egy az egyben beomlesztetted a programba.A Matrix::init ketszer van ertelmezve, mas parameterekkel, raadasul egyszer a main fuggveny kozepen.
Egyszer egy ‘tar’ nevu tombod van (vektor tar[10]), maskor ‘m’ a tomb neve. Annak ugyanaz kellene legyen a neve.
A tobbi hibarol majd szol a fordito 🙂
A kiiratast pedig egy uj metodussal a legegyszerubb elintezni a Matrix osztalyban.
2008-02-21-22:55 #2154657bocs, csak beomlesztettem a javaslataidat. nem gondoltam ezt tenyleges .cpp-nek. csak tajekozodni szerettem volna, hogy nem hagytam-e ki semmit…
2008-02-21-22:55 #2154658bocs, csak beomlesztettem a javaslataidat. nem gondoltam ezt tenyleges .cpp-nek. csak tajekozodni szerettem volna, hogy nem hagytam-e ki semmit…
-
SzerzőBejegyzés
- Be kell jelentkezni a hozzászóláshoz.
legutóbbi hsz