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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
#include<iostream>
#include<cmath>
using namespace std ;
const int row=4, column=4;
void DiagonalMatrix(double Array[row][column],double arr[row][column]);
void PrintArray (double arr[row][column]);
void SubstractArray(double Array[row][column],double arr[row][column],double R[row][column]);
void PrintR (double R[row][column]);
void MatrixToVector(double matrix[row][column],double I[row],double B[row]);
void PrintVector (double B[row]);
void SubstractVector(double B[row],double b[row],double C[row]);
void DiagonalMatrixInverse(double diagonal[row][column],double Inverse[row][column] );
void Jacobi(double Xnew[row]);
int main()
{
 
    double R[row][column];
    double arr[row][column];
    double matrix[row][column]={{-1,1,0,0},
        {7,2,4,-6},
        {0,-2,-4,8},
        {0,1,-1,6}};
    double I[row]={1,1,1,1};
    double B[row];
    double b[row]={5,20,-10,0};
    double C[row];
    double Inverse[row][column];
 
 
    double Xnew[row];
 
 
 
 
    DiagonalMatrix(matrix,arr);
    PrintArray(arr);
 
    SubstractArray(matrix,arr,R);
    PrintR(R);
    MatrixToVector(R,I,B);
    PrintVector(B);
    SubstractVector(B, b,C);
    DiagonalMatrixInverse(arr,Inverse );
 
 
 
 
 
    Jacobi(Xnew);
 
 
 
 
    return 0;
}
void PrintArray (double arr[row][column])
{
    for(int i=0; i<row;i++)
    {cout<<endl;
        {
            for(int j=0;j<column;j++)
                cout<<"     "<<arr[i][j];
 
        }
    }
 
    cout<<endl;
}
void DiagonalMatrix(double Array[row][column],double arr[row][column])
{
 
 
 
    for(int i=0;i<row;i++)
    {cout<<endl;
        {
            for(int j=0;j<column;j++)
            {
                if(i==j)
 
                    arr[i][j]=Array[i][j];
                else
                    arr[i][j]=0;
            }
        }
    }
}
void SubstractArray(double Array[row][column],double arr[row][column],double R[row][column])
{
    for(int i=0;i<row;i++)
    {
        {
            for(int j=0;j<column;j++)
 
                R[i][j]=(Array[i][j]-arr[i][j]);
 
 
 
        }
    }
}
void PrintR (double R[row][column])
{
    for(int i=0;i<row;i++)
    {
 
        cout<<endl;
        {for(int j=0;j<column; j++)
            cout<<"     "<<R[i][j];
        }
    }
 
    cout<<endl;
}
void MatrixToVector(double matrix[row][column],double I[row],double B[row])
{
    double sum=0;
    for(int i =0;i<row;i++)
    {for(int j=0;j<column;j++)
 
    {
 
        sum+=matrix[i][j]*I[j];
        B[i]=sum;
        if(j==column-1)
            sum=0;
    }
    }
 
 
 
}
void PrintVector (double B[row])
{
 
    for(int i=0; i<row;i++)
    {    cout<<endl;
 
        cout<<B[i];}
    cout<<endl;
 
 
}
void SubstractVector(double B[row],double b[row],double C[row])
{
 
    for(int i =0;i<row;i++)
    C[i] =b[i]-B[i];
    for(int j=0;j<row;j++)
        cout<<C[j]<<endl;
 
 
}
void DiagonalMatrixInverse(double diagonal[row][column],double Inverse[row][column] )
{
    for(int i=0;i<row;i++)
    {cout<<endl;
        for(int j=0;j<column;j++)
        {if(i==j)
 
                Inverse[i][j]=1.0/diagonal[i][j];
        else
            Inverse[i][j]=0;
        cout<<"   "<<Inverse[i][j];
        }
 
 
 
}
}
void Jacobi(double Xnew[row])
{
 
    double Array[row][column]={{-1,1,0,0},
                             {7,2,4,-6},
        {0,-2,-4,8},
        {0,1,-1,6}};
 
    int counter=0;
     double Diagonal[row][column];
 
    double R[row][column];
    double Xold[row]={0,0,0,0};
    double B[row];
    double b[row]={5,20,-10,0};
    double C[row];
     double Inverse[row][column];
 
    DiagonalMatrix(Array,Diagonal);
    SubstractArray(Array,Diagonal,R);
    DiagonalMatrixInverse(Diagonal,Inverse);
 
 
 
  while (counter<2)
  { MatrixToVector(R,Xold,B);
    SubstractVector(B,b,C);
    MatrixToVector(Inverse,C,Xnew);
    PrintVector (Xnew);
    for(int i=0;i<row;i++)
      Xold[i]=Xnew[i];
       counter++;}
 
 
}
bool Error(double Xold[row],double Xnew[row])
{bool check=false;
    double sum=0;
    for(int i=0;i<row;i++)
    {sum+=( abs(Xold[i]-Xnew[i]));
        if( sum<=pow(10,-6))
               check=true;
    }
 
    return check;
 
}
je veux utiliser la fonction booléenne à l'intérieur de la boucle (while)
je veux boucle jusqu'à ce qu'il soit fausse
est ce que quelqu'un peux m'aider??