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-27-19:34 #2154769
Nagyon koszi.
Meg valami:
Amit most kiir nekem az a „sum”, azaz a matrixok osszege?
Es ennek az atlagat hogyan irathatom ki? Azaz, a pl. ” sum /=5; „-ot.2008-02-27-19:34 #2154770Nagyon koszi.
Meg valami:
Amit most kiir nekem az a „sum”, azaz a matrixok osszege?
Es ennek az atlagat hogyan irathatom ki? Azaz, a pl. ” sum /=5; „-ot.2008-02-27-19:37 #2154771Attol tartok, utana kellene nezzel, hogy mi a kulonbseg a „/” es a „/=” operatorok kozott…
2008-02-27-19:37 #2154772Attol tartok, utana kellene nezzel, hogy mi a kulonbseg a „/” es a „/=” operatorok kozott…
2008-02-27-19:42 #2154773Gondoltam adok egy peldat arra is, hogy hogyan ne programozzunk (hacsak nem akarjuk oruletbe kergetni azt, aki a programot olvassa):
Code:#includeclass Valami {
private:
float tomb[3][3];
public:
Valami & operator ++(int unused);
};// ennek a fuggvenynek is ismerjuk a parametereit
Valami & Valami::operator ++(int unused){
int i,j;
for( i=0; i<3; i++){
for(j=0; j<3; j++)
std::cout << tomb[I][j] << " ";
std::cout << std::endl;
}
return *this;
}int main(void){
Valami objektum;
// ….
// es ez ki fogja irni az objektumot!!!
objektum++;
}2008-02-27-19:42 #2154774Gondoltam adok egy peldat arra is, hogy hogyan ne programozzunk (hacsak nem akarjuk oruletbe kergetni azt, aki a programot olvassa):
Code:#includeclass Valami {
private:
float tomb[3][3];
public:
Valami & operator ++(int unused);
};// ennek a fuggvenynek is ismerjuk a parametereit
Valami & Valami::operator ++(int unused){
int i,j;
for( i=0; i<3; i++){
for(j=0; j<3; j++)
std::cout << tomb[I][j] << " ";
std::cout << std::endl;
}
return *this;
}int main(void){
Valami objektum;
// ….
// es ez ki fogja irni az objektumot!!!
objektum++;
}2008-02-27-20:08 #2154775Ez így miért nem jo?
Code:#include
#include
#include
#include
#include#define N 5
using namespace std;
const float M_2PIf = 6.283185307179586476925286766559f;
const float M_PIf = 3.141592653589793238462643383279f;/* —————–RANDOM_GENERATOR——————————- */
float rand(float min, float max)
{
return min + (max – min) * rand() / (float)RAND_MAX;
}
/*——————————————————————*/struct vektor {
float x,y,z;
};/* ——————MATRIX_CLASS———————————–*/
class Matrix {private:
float tomb[3][3];
public:
void init(vektor &a){tomb[0][0] = a.x * a.x;
tomb[0][1] = a.x * a.y;
tomb[0][2] = a.x * a.z;
tomb[1][0] = a.y * a.x;
tomb[1][1] = a.y * a.y;
tomb[1][2] = a.y * a.z;
tomb[2][0] = a.z * a.x;
tomb[2][1] = a.z * a.y;
tomb[2][2] = a.z * a.z;
}Matrix &operator +=(Matrix b){
int k,l;
for(k=0; k<3; k++)
for(l=0; l<3; l++)
tomb[k][l] += b.tomb[k][l];
return *this;
}Matrix &operator/=(float c){
int k,l;
for(k=0; k<3; k++)
for(l=0; l<3; l++)
tomb[k][l] /= c;
return *this;
}Matrix &operator /=(int unused);
};
Matrix & Matrix::operator /=(int unused){
int i,j;
for( i=0; i<3; i++){
for(j=0; j<3; j++)
std::cout << tomb[i][j] << " ";
std::cout << std::endl;
}
return *this;
}/* ——————————————————————– */
int main(void) {
int i,j;
vektor tar[5];
for (i = 0;i<5;i++) {
float phi = rand(0.0f, M_2PIf);
float costheta = rand(-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;tar[i].x = x;
tar[i].y = y;
tar[i].z = z;}
Matrix m[5];
for (i=0;i<5;i++) {
m[i].init(tar[i]);
}
Matrix sum = m[0];for (i=0;i<5;i++) {
sum += m[i];
}Matrix sum /= 5;
sum/=;
return 0;
}2008-02-27-20:08 #2154776Ez így miért nem jo?
Code:#include
#include
#include
#include
#include#define N 5
using namespace std;
const float M_2PIf = 6.283185307179586476925286766559f;
const float M_PIf = 3.141592653589793238462643383279f;/* —————–RANDOM_GENERATOR——————————- */
float rand(float min, float max)
{
return min + (max – min) * rand() / (float)RAND_MAX;
}
/*——————————————————————*/struct vektor {
float x,y,z;
};/* ——————MATRIX_CLASS———————————–*/
class Matrix {private:
float tomb[3][3];
public:
void init(vektor &a){tomb[0][0] = a.x * a.x;
tomb[0][1] = a.x * a.y;
tomb[0][2] = a.x * a.z;
tomb[1][0] = a.y * a.x;
tomb[1][1] = a.y * a.y;
tomb[1][2] = a.y * a.z;
tomb[2][0] = a.z * a.x;
tomb[2][1] = a.z * a.y;
tomb[2][2] = a.z * a.z;
}Matrix &operator +=(Matrix b){
int k,l;
for(k=0; k<3; k++)
for(l=0; l<3; l++)
tomb[k][l] += b.tomb[k][l];
return *this;
}Matrix &operator/=(float c){
int k,l;
for(k=0; k<3; k++)
for(l=0; l<3; l++)
tomb[k][l] /= c;
return *this;
}Matrix &operator /=(int unused);
};
Matrix & Matrix::operator /=(int unused){
int i,j;
for( i=0; i<3; i++){
for(j=0; j<3; j++)
std::cout << tomb[i][j] << " ";
std::cout << std::endl;
}
return *this;
}/* ——————————————————————– */
int main(void) {
int i,j;
vektor tar[5];
for (i = 0;i<5;i++) {
float phi = rand(0.0f, M_2PIf);
float costheta = rand(-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;tar[i].x = x;
tar[i].y = y;
tar[i].z = z;}
Matrix m[5];
for (i=0;i<5;i++) {
m[i].init(tar[i]);
}
Matrix sum = m[0];for (i=0;i<5;i++) {
sum += m[i];
}Matrix sum /= 5;
sum/=;
return 0;
}2008-02-27-20:34 #2154777Mert csak azt tudod felulertelmezni, hogy mi tortenjen egy operator alkalmazasa eseten, a parametereinek a szamat nem.
2008-02-27-20:34 #2154778Mert csak azt tudod felulertelmezni, hogy mi tortenjen egy operator alkalmazasa eseten, a parametereinek a szamat nem.
-
SzerzőBejegyzés
- Be kell jelentkezni a hozzászóláshoz.
legutóbbi hsz