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-23:08 #2154659
egyebkent valoban, elegge kezdo vagyok, ilyeneket kb. most csinalok eloszor, de sokat tanulok belole es ha segitenek annal hasznosabb a dolog… 🙂
2008-02-21-23:08 #2154660egyebkent valoban, elegge kezdo vagyok, ilyeneket kb. most csinalok eloszor, de sokat tanulok belole es ha segitenek annal hasznosabb a dolog… 🙂
2008-02-21-23:27 #2154661segitenel meg egy kicsit a vege fele?
Code:// for functions rand and srand
#include
//
#include
// input/output stream
#include
// for function time, and for data type time_t
#include
//
#includeusing 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];public:
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;
}Matrix3x3 &operator +=(Matrix3x3 b){
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){
int x,y;
for(x=0; x<3; x++)
for(y=0; y<3; y++)
tomb[x][y] /= c;
return *this;
}};
/* ——————————————————————– */
int main() {
vektor tar[10];
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;
tar[i].x = x;
tar[i].y = y;
tar[i].z = z;}
/* ——————————————————————– */
Matrix tar[10];for(i=0; i<10; i++)
tar[i].init(tar[i]);Matrix osszeg = tar[0];
for(i=1; i<10; i++)
osszeg += tar[i];/* ——————————————————————– */
return 0;
}konnyebb lenne megertenem, ha jo lenne… de ezzel szenvedek, Te pedig tok jol vagod…
2008-02-21-23:27 #2154662segitenel meg egy kicsit a vege fele?
Code:// for functions rand and srand
#include
//
#include
// input/output stream
#include
// for function time, and for data type time_t
#include
//
#includeusing 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];public:
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;
}Matrix3x3 &operator +=(Matrix3x3 b){
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){
int x,y;
for(x=0; x<3; x++)
for(y=0; y<3; y++)
tomb[x][y] /= c;
return *this;
}};
/* ——————————————————————– */
int main() {
vektor tar[10];
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;
tar[i].x = x;
tar[i].y = y;
tar[i].z = z;}
/* ——————————————————————– */
Matrix tar[10];for(i=0; i<10; i++)
tar[i].init(tar[i]);Matrix osszeg = tar[0];
for(i=1; i<10; i++)
osszeg += tar[i];/* ——————————————————————– */
return 0;
}konnyebb lenne megertenem, ha jo lenne… de ezzel szenvedek, Te pedig tok jol vagod…
2008-02-22-07:50 #2154663Jó dolog, ha a házi feladatot a szomszéd csinálja meg.
Ha meg távoli, akkor sört se tud kérni érte.2008-02-22-07:50 #2154664Jó dolog, ha a házi feladatot a szomszéd csinálja meg.
Ha meg távoli, akkor sört se tud kérni érte.2008-02-22-20:44 #2154665jules wrote:egyebkent valoban, elegge kezdo vagyok, ilyeneket kb. most csinalok eloszor, de sokat tanulok belole es ha segitenek annal hasznosabb a dolog… 🙂Egyszerubb dolgokkal kellene kezdjed, aztan mind bonyolultabbakkal. Es fontos, hogy te irjad a programot…
A vegerol: egy matrixot ugy lehet kiirni, hogy kiirod minden elemet, megfelelo sorrenben, tobb sorban. Javaslom, hogy ezt ird meg egy kolon kis programocskaban. Tobbet tanulsz belole, mint egy bonyolult programbol.
2008-02-22-20:44 #2154666jules wrote:egyebkent valoban, elegge kezdo vagyok, ilyeneket kb. most csinalok eloszor, de sokat tanulok belole es ha segitenek annal hasznosabb a dolog… 🙂Egyszerubb dolgokkal kellene kezdjed, aztan mind bonyolultabbakkal. Es fontos, hogy te irjad a programot…
A vegerol: egy matrixot ugy lehet kiirni, hogy kiirod minden elemet, megfelelo sorrenben, tobb sorban. Javaslom, hogy ezt ird meg egy kolon kis programocskaban. Tobbet tanulsz belole, mint egy bonyolult programbol.
2008-02-22-20:48 #2154667renben. a teljesseg kedveert, ha mar ennyit segitettel (es ezert tokre halas vagyok), nem irnad ide a kiiratas reszt. mar ugye minden mas megvan hozza es innen tudnek fejlodni, mert biztos tudnam hogy nem hulyeseg.
es akkor offolhatjuk ezt a temat es megegyszer nagyon koszonom…2008-02-22-20:48 #2154668renben. a teljesseg kedveert, ha mar ennyit segitettel (es ezert tokre halas vagyok), nem irnad ide a kiiratas reszt. mar ugye minden mas megvan hozza es innen tudnek fejlodni, mert biztos tudnam hogy nem hulyeseg.
es akkor offolhatjuk ezt a temat es megegyszer nagyon koszonom… -
SzerzőBejegyzés
- Be kell jelentkezni a hozzászóláshoz.
legutóbbi hsz