bonjour, j'ai une classe vecteur et matrice et je dois resoudre un systeme par la methode de gauss mais le vecteur resultat je px plus le recuperer !
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#include<iostream.h>
#include"vecteur.h"
#include"matrice.h"
#include<math.h>
#include<assert.h>

//void Produit(double A[][3],double b[], double resultat[]);
	bool testnul(double A[][3]);
	void StyleTriSup(double A[][3], double B[], double triang[]);
	void MatriceGauss(double A[][3],double A1[3][3+1][3],double B[]);
	void trans(double A[][3],double A1[3][3+1][3],double B[]);
	
	Matrice M;
    Vecteur X;


void main()
{
	double aide[3][3+1][3];
    double Ma[3][3];
	double Ve[3],produit[3],rGauss[3];
	
	M.LectMatrice(Ma);
	cout<<endl;
	M.AffichMatrice(Ma);
	cout<<endl;
	X.LectVecteur(Ve);
	cout<<endl;
	X.AffichVecteur(Ve);
    MatriceGauss(Ma,aide,Ve);
	trans(Ma,aide,Ve);
    StyleTriSup(Ma,Ve,rGauss);
	//Produit(Ma,Ve,produit);

    X.AffichVecteur(rGauss);
}

	bool testnul(double A[][3])
{
	int i=1;
	bool trouve=false;
	while((i<3)&&(!trouve))
	{
	if (A[i][i]==0) trouve=true;
	else i++;
	}

	return trouve;

}

/*void Produit(double A[][3], double b[], double resultat[])
{

	int i,j;
	for(i=0;i<3;i++)
	{
		resultat[i]=0;
		for(j=0;j<3;j++){
			resultat[i]+=A[i][j] * b[j];}
	}
       
}*/

void StyleTriSup(double A[][3], double B[], double triang[])
{
double s;
int j;
assert(!testnul(A)); 
triang[3]=B[3]/A[3][3];
for(int i=3-1;i>=1;i--)
{
	s=B[i];
    for(j=i+1;j<=3;j++) 
		s=s-(A[i][j] * triang[j]);
	triang[i]=s/A[i][i];    
 }
 cout<<endl;
 cout<<"-------------------- RESULTAT ------------------------"<<endl;
 cout<<endl;
 
}


void MatriceGauss(double A[][3],double A1[3][3+1][3],double B[])
{
for(int i=1;i<=3;i++)
for(int j=1;j<=3;j++)
{A1[i][j][1]=A[i][j];}

for(i=1;i<=3;i++)
{A1[i][3+1][1]=B[i];}


for(int k=1;k<=3-1;k++)
{
	for(i=1;i<=k;i++)
for(int j=1;j<=3+1;j++) {A1[i][j][k+1]=A1[i][j][k];}


for(i=k+1;i<=3;i++)
{
double piv= double(A1[i][k][k])/A1[k][k][k];
for(int j=k;j<=3+1;j++)
A1[i][j][k+1]=(A1[i][j][k]-(piv*A1[k][j][k]));
}
}
}

void trans(double A[][3],double A1[3][3+1][3],double B[])
{
	
int i,j;
for(i=1;i<=3;i++)
for(j=1;j<=3;j++)
{
A[i][j]=A1[i][j][3];
}
for(i=1;i<=3;i++)
B[i]=A1[i][3+1][3]; 
}