質問編集履歴
7
題名変更
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
C言語
|
1
|
+
C言語 ガウスの消去法
|
test
CHANGED
File without changes
|
6
間違っている回答やコードの部分を削除しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -20,7 +20,7 @@
|
|
20
20
|
|
21
21
|
|
22
22
|
|
23
|
-
void PrintAb(double *A, double *b, int n){
|
23
|
+
void PrintAb(double *A, double *b, int n){
|
24
24
|
|
25
25
|
int i,j;
|
26
26
|
|
@@ -56,9 +56,9 @@
|
|
56
56
|
|
57
57
|
double r;
|
58
58
|
|
59
|
-
double *ai, *ak;
|
59
|
+
double *ai, *ak;
|
60
|
-
|
60
|
+
|
61
|
-
double *A, *b;
|
61
|
+
double *A, *b;
|
62
62
|
|
63
63
|
double mmax, temp;
|
64
64
|
|
@@ -68,8 +68,6 @@
|
|
68
68
|
|
69
69
|
|
70
70
|
|
71
|
-
/*行列Aのメモリ確保*/
|
72
|
-
|
73
71
|
A = (double *)malloc(N*N*sizeof(double));
|
74
72
|
|
75
73
|
if(A==NULL){
|
@@ -82,9 +80,7 @@
|
|
82
80
|
|
83
81
|
|
84
82
|
|
85
|
-
/*ベクトルbのメモリ確保*/
|
86
|
-
|
87
|
-
|
83
|
+
b = (double *)malloc(N*sizeof(double));
|
88
84
|
|
89
85
|
if(b==NULL){
|
90
86
|
|
@@ -96,8 +92,6 @@
|
|
96
92
|
|
97
93
|
|
98
94
|
|
99
|
-
/*行列・ベクトルの入力*/
|
100
|
-
|
101
95
|
ai = A;
|
102
96
|
|
103
97
|
ak = A;
|
@@ -134,15 +128,13 @@
|
|
134
128
|
|
135
129
|
|
136
130
|
|
137
|
-
/* 前進消去(ピボット選択)*/
|
138
|
-
|
139
|
-
for(k = 0; k < N-1; k++){
|
131
|
+
for(k = 0; k < N-1; k++){
|
140
132
|
|
141
133
|
m = k;
|
142
134
|
|
143
135
|
mmax = fabs(*(ak+k));
|
144
136
|
|
145
|
-
for(i = k+1; i < N; i++){
|
137
|
+
for(i = k+1; i < N; i++){
|
146
138
|
|
147
139
|
if(fabs(*(ai+i*N+k)) > mmax){
|
148
140
|
|
@@ -156,9 +148,9 @@
|
|
156
148
|
|
157
149
|
printf("column %d: row %d is max\n", k, m);
|
158
150
|
|
159
|
-
if(m != k){
|
151
|
+
if(m != k){
|
160
|
-
|
152
|
+
|
161
|
-
for(i = k; i < N; i++){
|
153
|
+
for(i = k; i < N; i++){
|
162
154
|
|
163
155
|
temp = *(ak+i);
|
164
156
|
|
@@ -168,8 +160,6 @@
|
|
168
160
|
|
169
161
|
}
|
170
162
|
|
171
|
-
/* 既知ベクトル */
|
172
|
-
|
173
163
|
temp = b[k];
|
174
164
|
|
175
165
|
b[k] = b[m];
|
@@ -182,8 +172,6 @@
|
|
182
172
|
|
183
173
|
ak = A;
|
184
174
|
|
185
|
-
/* 第k列消去 */
|
186
|
-
|
187
175
|
for (i = k + 1; i < N; i++){
|
188
176
|
|
189
177
|
r = *(ai+i*N+k) / *(ak+k);
|
@@ -206,8 +194,6 @@
|
|
206
194
|
|
207
195
|
|
208
196
|
|
209
|
-
/*後退代入*/
|
210
|
-
|
211
197
|
ai = ak;
|
212
198
|
|
213
199
|
for (i = N - 1; i >= 0; i--) {
|
@@ -331,89 +317,3 @@
|
|
331
317
|
0.0 -2.3 1.7 | -1.0
|
332
318
|
|
333
319
|
0.0 -0.0 2.6 | 2.0
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
=私の誤った出力=
|
340
|
-
|
341
|
-
N= 3
|
342
|
-
|
343
|
-
A[0][0] = 1
|
344
|
-
|
345
|
-
A[0][1] = 1
|
346
|
-
|
347
|
-
A[0][2] = 2
|
348
|
-
|
349
|
-
A[1][0] = 3
|
350
|
-
|
351
|
-
A[1][1] = 2
|
352
|
-
|
353
|
-
A[1][2] = -1
|
354
|
-
|
355
|
-
A[2][0] = 2
|
356
|
-
|
357
|
-
A[2][1] = -1
|
358
|
-
|
359
|
-
A[2][2] = 1
|
360
|
-
|
361
|
-
b[0] = 4
|
362
|
-
|
363
|
-
b[1] = -1
|
364
|
-
|
365
|
-
b[2] = 5
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
A, b =
|
370
|
-
|
371
|
-
1.0 1.0 2.0 | 4.0
|
372
|
-
|
373
|
-
3.0 2.0 -1.0 | -1.0
|
374
|
-
|
375
|
-
2.0 -1.0 1.0 | 5.0
|
376
|
-
|
377
|
-
column 0: row 1 is max
|
378
|
-
|
379
|
-
A, b =
|
380
|
-
|
381
|
-
3.0 2.0 -1.0 | -1.0
|
382
|
-
|
383
|
-
0.0 0.3 2.3 | 4.3
|
384
|
-
|
385
|
-
0.0 -2.3 1.7 | 5.7
|
386
|
-
|
387
|
-
column 1: row 2 is max ←ここまでは正しいです。
|
388
|
-
|
389
|
-
A, b =
|
390
|
-
|
391
|
-
3.0 2.0 -1.0 | 0.3
|
392
|
-
|
393
|
-
0.0 -1.0 4.3 | 5.7
|
394
|
-
|
395
|
-
0.0 0.0 0.5 | 8.9
|
396
|
-
|
397
|
-
A, b =
|
398
|
-
|
399
|
-
3.0 2.0 -1.0 | 0.3
|
400
|
-
|
401
|
-
0.0 -1.0 4.3 | 5.7
|
402
|
-
|
403
|
-
0.0 0.0 0.5 | 2.1
|
404
|
-
|
405
|
-
A, b =
|
406
|
-
|
407
|
-
3.0 2.0 -1.0 | 0.3
|
408
|
-
|
409
|
-
0.0 -1.0 4.3 | 3.9
|
410
|
-
|
411
|
-
0.0 0.0 0.5 | 2.1
|
412
|
-
|
413
|
-
A, b =
|
414
|
-
|
415
|
-
3.0 2.0 -1.0 | 0.0
|
416
|
-
|
417
|
-
0.0 -1.0 4.3 | 3.9
|
418
|
-
|
419
|
-
0.0 0.0 0.5 | 2.1
|
5
ソースコードの更新
test
CHANGED
File without changes
|
test
CHANGED
@@ -34,11 +34,11 @@
|
|
34
34
|
|
35
35
|
for( j = 0 ; j < n ; j++){
|
36
36
|
|
37
|
-
printf("%6.
|
37
|
+
printf("%6.1f\t", *(ai+j));
|
38
|
-
|
38
|
+
|
39
|
-
}
|
39
|
+
}
|
40
|
-
|
40
|
+
|
41
|
-
printf("|%6.
|
41
|
+
printf("|%6.1f\n",*(b+i));
|
42
42
|
|
43
43
|
ai+=n;
|
44
44
|
|
4
答えに一番近づいたソースコード
test
CHANGED
File without changes
|
test
CHANGED
@@ -6,6 +6,8 @@
|
|
6
6
|
|
7
7
|
以上のような問いに対し、以下のソースコードを書きました。
|
8
8
|
|
9
|
+
質問をしてから、何度もやり直しや修正を図り少しづつ答えには近づいてきたものの、まだ正確にはうまくいきません。よろしくお願いいたします。
|
10
|
+
|
9
11
|
|
10
12
|
|
11
13
|
```
|
@@ -32,11 +34,11 @@
|
|
32
34
|
|
33
35
|
for( j = 0 ; j < n ; j++){
|
34
36
|
|
35
|
-
printf("%6.
|
37
|
+
printf("%6.2f\t", *(ai+j));
|
36
|
-
|
38
|
+
|
37
|
-
}
|
39
|
+
}
|
38
|
-
|
40
|
+
|
39
|
-
printf("|%6.
|
41
|
+
printf("|%6.2f\n",*(b+i));
|
40
42
|
|
41
43
|
ai+=n;
|
42
44
|
|
@@ -138,11 +140,11 @@
|
|
138
140
|
|
139
141
|
m = k;
|
140
142
|
|
141
|
-
mmax = fabs(*(a
|
143
|
+
mmax = fabs(*(ak+k));
|
142
144
|
|
143
145
|
for(i = k+1; i < N; i++){ /* ピボット選択 */
|
144
146
|
|
145
|
-
if(fabs(*
|
147
|
+
if(fabs(*(ai+i*N+k)) > mmax){
|
146
148
|
|
147
149
|
m = i;
|
148
150
|
|
@@ -158,7 +160,7 @@
|
|
158
160
|
|
159
161
|
for(i = k; i < N; i++){/* 係数行列 */
|
160
162
|
|
161
|
-
temp= *(ak+i);
|
163
|
+
temp = *(ak+i);
|
162
164
|
|
163
165
|
*(ak+i) = *(ak+m*N+i);
|
164
166
|
|
@@ -182,28 +184,24 @@
|
|
182
184
|
|
183
185
|
/* 第k列消去 */
|
184
186
|
|
185
|
-
for (k = 0; k < N - 1; k++){
|
186
|
-
|
187
|
-
|
187
|
+
for (i = k + 1; i < N; i++){
|
188
|
-
|
188
|
+
|
189
|
-
|
189
|
+
r = *(ai+i*N+k) / *(ak+k);
|
190
|
-
|
190
|
+
|
191
|
-
|
191
|
+
for (j = k; j < N; j++){
|
192
|
-
|
192
|
+
|
193
|
-
|
193
|
+
*(ai+i*N+j) -= *(ak+j) * r;
|
194
|
-
|
195
|
-
}
|
196
|
-
|
197
|
-
b[i] -= b[k] * r;
|
198
194
|
|
199
195
|
}
|
200
196
|
|
201
|
-
|
197
|
+
b[i] -= b[k] * r;
|
202
198
|
|
203
199
|
}
|
204
200
|
|
205
201
|
PrintAb(A, b, N);
|
206
202
|
|
203
|
+
ak+=N;
|
204
|
+
|
207
205
|
}
|
208
206
|
|
209
207
|
|
@@ -246,7 +244,9 @@
|
|
246
244
|
|
247
245
|
|
248
246
|
|
249
|
-
しかし、私自身が書いたソースコードを実行しても
|
247
|
+
しかし、私自身が書いたソースコードを実行しても正しくいきません(エラーなどは出ていません)。
|
248
|
+
|
249
|
+
(第二回目の消去までは正しいのですが、それ以降が正しくありません。)
|
250
250
|
|
251
251
|
どなたかわかる方がいらっしゃれば教えていただけると幸いです。
|
252
252
|
|
@@ -282,55 +282,55 @@
|
|
282
282
|
|
283
283
|
A, b =
|
284
284
|
|
285
|
-
1.0
|
285
|
+
1.0 1.0 2.0 | 4.0
|
286
|
-
|
286
|
+
|
287
|
-
3.0
|
287
|
+
3.0 2.0 -1.0 | -1.0
|
288
|
-
|
288
|
+
|
289
|
-
2.0
|
289
|
+
2.0 -1.0 1.0 | 5.0
|
290
290
|
|
291
291
|
column 0: row 1 is max
|
292
292
|
|
293
293
|
A, b =
|
294
294
|
|
295
|
-
3.0
|
295
|
+
3.0 2.0 -1.0 | -1.0
|
296
|
-
|
296
|
+
|
297
|
-
0.0
|
297
|
+
0.0 0.3 2.3 | 4.3
|
298
|
-
|
298
|
+
|
299
|
-
0.0
|
299
|
+
0.0 -2.3 1.7 | 5.7
|
300
300
|
|
301
301
|
column 1: row 2 is max
|
302
302
|
|
303
303
|
A, b =
|
304
304
|
|
305
|
-
3.0
|
305
|
+
3.0 2.0 -1.0 | -1.0
|
306
|
-
|
306
|
+
|
307
|
-
0.0
|
307
|
+
0.0 -2.3 1.7 | 5.7
|
308
|
-
|
308
|
+
|
309
|
-
0.0
|
309
|
+
0.0 -0.0 2.6 | 5.1
|
310
|
-
|
310
|
+
|
311
|
-
A, b =
|
311
|
+
A, b =
|
312
|
-
|
312
|
+
|
313
|
-
3.0
|
313
|
+
3.0 2.0 -1.0 | -1.0
|
314
|
-
|
314
|
+
|
315
|
-
0.0
|
315
|
+
0.0 -2.3 1.7 | 5.7
|
316
|
-
|
316
|
+
|
317
|
-
0.0
|
317
|
+
0.0 -0.0 2.6 | 2.0
|
318
|
-
|
318
|
+
|
319
|
-
A, b =
|
319
|
+
A, b =
|
320
|
-
|
320
|
+
|
321
|
-
3.0
|
321
|
+
3.0 2.0 -1.0 | -1.0
|
322
|
-
|
322
|
+
|
323
|
-
0.0
|
323
|
+
0.0 -2.3 1.7 | -1.0
|
324
|
-
|
324
|
+
|
325
|
-
0.0
|
325
|
+
0.0 -0.0 2.6 | 2.0
|
326
|
-
|
326
|
+
|
327
|
-
A, b =
|
327
|
+
A, b =
|
328
|
-
|
328
|
+
|
329
|
-
3.0
|
329
|
+
3.0 2.0 -1.0 | 1.0
|
330
|
-
|
330
|
+
|
331
|
-
0.0
|
331
|
+
0.0 -2.3 1.7 | -1.0
|
332
|
-
|
332
|
+
|
333
|
-
0.0
|
333
|
+
0.0 -0.0 2.6 | 2.0
|
334
334
|
|
335
335
|
|
336
336
|
|
@@ -368,42 +368,52 @@
|
|
368
368
|
|
369
369
|
A, b =
|
370
370
|
|
371
|
-
1.0
|
371
|
+
1.0 1.0 2.0 | 4.0
|
372
|
-
|
372
|
+
|
373
|
-
3.0
|
373
|
+
3.0 2.0 -1.0 | -1.0
|
374
|
-
|
374
|
+
|
375
|
-
2.0
|
375
|
+
2.0 -1.0 1.0 | 5.0
|
376
376
|
|
377
377
|
column 0: row 1 is max
|
378
378
|
|
379
379
|
A, b =
|
380
380
|
|
381
|
-
3.0
|
381
|
+
3.0 2.0 -1.0 | -1.0
|
382
|
-
|
382
|
+
|
383
|
-
0.0
|
383
|
+
0.0 0.3 2.3 | 4.3
|
384
|
-
|
384
|
+
|
385
|
-
0.0
|
385
|
+
0.0 -2.3 1.7 | 5.7
|
386
|
+
|
386
|
-
|
387
|
+
column 1: row 2 is max ←ここまでは正しいです。
|
388
|
+
|
387
|
-
A, b =
|
389
|
+
A, b =
|
388
|
-
|
390
|
+
|
389
|
-
3.0
|
391
|
+
3.0 2.0 -1.0 | 0.3
|
390
|
-
|
392
|
+
|
391
|
-
0.0
|
393
|
+
0.0 -1.0 4.3 | 5.7
|
392
|
-
|
394
|
+
|
393
|
-
0.0
|
395
|
+
0.0 0.0 0.5 | 8.9
|
394
|
-
|
396
|
+
|
395
|
-
A, b =
|
397
|
+
A, b =
|
396
|
-
|
398
|
+
|
397
|
-
3.0
|
399
|
+
3.0 2.0 -1.0 | 0.3
|
398
|
-
|
400
|
+
|
399
|
-
0.0
|
401
|
+
0.0 -1.0 4.3 | 5.7
|
400
|
-
|
402
|
+
|
401
|
-
0.0
|
403
|
+
0.0 0.0 0.5 | 2.1
|
402
|
-
|
404
|
+
|
403
|
-
A, b =
|
405
|
+
A, b =
|
406
|
+
|
404
|
-
|
407
|
+
3.0 2.0 -1.0 | 0.3
|
408
|
+
|
409
|
+
0.0 -1.0 4.3 | 3.9
|
410
|
+
|
411
|
+
0.0 0.0 0.5 | 2.1
|
412
|
+
|
413
|
+
A, b =
|
414
|
+
|
405
|
-
3.0
|
415
|
+
3.0 2.0 -1.0 | 0.0
|
406
|
-
|
416
|
+
|
407
|
-
0.0
|
417
|
+
0.0 -1.0 4.3 | 3.9
|
408
|
-
|
418
|
+
|
409
|
-
0.0
|
419
|
+
0.0 0.0 0.5 | 2.1
|
3
正しい答えに最も近づいたソースコードへの変更
test
CHANGED
File without changes
|
test
CHANGED
@@ -32,11 +32,11 @@
|
|
32
32
|
|
33
33
|
for( j = 0 ; j < n ; j++){
|
34
34
|
|
35
|
-
printf("%6.
|
35
|
+
printf("%6.1f\t", *(ai+j));
|
36
|
-
|
36
|
+
|
37
|
-
}
|
37
|
+
}
|
38
|
-
|
38
|
+
|
39
|
-
printf("|%6.
|
39
|
+
printf("|%6.1f\n",*(b+i));
|
40
40
|
|
41
41
|
ai+=n;
|
42
42
|
|
@@ -64,69 +64,73 @@
|
|
64
64
|
|
65
65
|
scanf("%d",&N);
|
66
66
|
|
67
|
+
|
68
|
+
|
69
|
+
/*行列Aのメモリ確保*/
|
70
|
+
|
71
|
+
A = (double *)malloc(N*N*sizeof(double));
|
72
|
+
|
73
|
+
if(A==NULL){
|
74
|
+
|
75
|
+
printf("Can’t allocate memory. Y=n");
|
76
|
+
|
77
|
+
exit(1);
|
78
|
+
|
79
|
+
}
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
/*ベクトルbのメモリ確保*/
|
84
|
+
|
85
|
+
b = (double *)malloc(N*sizeof(double));
|
86
|
+
|
87
|
+
if(b==NULL){
|
88
|
+
|
89
|
+
printf("Can’t allocate memory. Y=n");
|
90
|
+
|
91
|
+
exit(1);
|
92
|
+
|
93
|
+
}
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
/*行列・ベクトルの入力*/
|
98
|
+
|
99
|
+
ai = A;
|
100
|
+
|
101
|
+
ak = A;
|
102
|
+
|
103
|
+
for(i = 0 ; i < N ; i++ ){
|
104
|
+
|
105
|
+
for( j = 0 ; j < N ; j++ ){
|
106
|
+
|
107
|
+
printf("A[%d][%d] = ", i , j );
|
108
|
+
|
109
|
+
scanf("%lf", ai+j );
|
110
|
+
|
111
|
+
}
|
112
|
+
|
113
|
+
ai+=N;
|
114
|
+
|
115
|
+
}
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
for(i = 0 ; i < N ; i++ ){
|
120
|
+
|
121
|
+
printf("b[%d] = ", i );
|
122
|
+
|
123
|
+
scanf("%lf", b+i);
|
124
|
+
|
125
|
+
}
|
126
|
+
|
127
|
+
printf("\n");
|
128
|
+
|
67
129
|
|
68
130
|
|
69
|
-
/*行列Aのメモリ確保*/
|
70
|
-
|
71
|
-
A = (double *)malloc(N*N*sizeof(double));
|
72
|
-
|
73
|
-
if(A==NULL){
|
74
|
-
|
75
|
-
printf("Can’t allocate memory. Y=n");
|
76
|
-
|
77
|
-
exit(1);
|
78
|
-
|
79
|
-
}
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
/*ベクトルbのメモリ確保*/
|
84
|
-
|
85
|
-
b = (double *)malloc(N*sizeof(double));
|
86
|
-
|
87
|
-
if(b==NULL){
|
88
|
-
|
89
|
-
printf("Can’t allocate memory. Y=n");
|
90
|
-
|
91
|
-
exit(1);
|
92
|
-
|
93
|
-
}
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
/*行列・ベクトルの入力*/
|
98
|
-
|
99
|
-
ai = A;
|
100
|
-
|
101
|
-
ak = A;
|
102
|
-
|
103
|
-
for(i = 0 ; i < N ; i++ ){
|
104
|
-
|
105
|
-
for( j = 0 ; j < N ; j++ ){
|
106
|
-
|
107
|
-
printf("A[%d][%d] = ", i , j );
|
108
|
-
|
109
|
-
scanf("%lf", ai+j );
|
110
|
-
|
111
|
-
}
|
112
|
-
|
113
|
-
ai+=N;
|
114
|
-
|
115
|
-
}
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
for(i = 0 ; i < N ; i++ ){
|
120
|
-
|
121
|
-
printf("b[%d] = ", i );
|
122
|
-
|
123
|
-
scanf("%lf", b+i);
|
124
|
-
|
125
|
-
}
|
126
|
-
|
127
|
-
|
131
|
+
PrintAb(A, b, N);
|
128
|
-
|
129
|
-
|
132
|
+
|
133
|
+
|
130
134
|
|
131
135
|
/* 前進消去(ピボット選択)*/
|
132
136
|
|
@@ -150,7 +154,7 @@
|
|
150
154
|
|
151
155
|
printf("column %d: row %d is max\n", k, m);
|
152
156
|
|
153
|
-
if(m != k){ /* 第k行と第m行
|
157
|
+
if(m != k){ /* 第k行と第m行を交換 */
|
154
158
|
|
155
159
|
for(i = k; i < N; i++){/* 係数行列 */
|
156
160
|
|
@@ -172,45 +176,37 @@
|
|
172
176
|
|
173
177
|
}
|
174
178
|
|
179
|
+
ai = A;
|
180
|
+
|
181
|
+
ak = A;
|
182
|
+
|
183
|
+
/* 第k列消去 */
|
184
|
+
|
185
|
+
for (k = 0; k < N - 1; k++){
|
186
|
+
|
187
|
+
for (i = k + 1; i < N; i++){
|
188
|
+
|
189
|
+
r = *(ai+i*N+k) / *(ak+k);
|
190
|
+
|
191
|
+
for (j = k; j < N; j++){
|
192
|
+
|
193
|
+
*(ai+i*N+j) -= *(ak+j) * r;
|
194
|
+
|
195
|
+
}
|
196
|
+
|
197
|
+
b[i] -= b[k] * r;
|
198
|
+
|
199
|
+
}
|
200
|
+
|
201
|
+
ak+=N;
|
202
|
+
|
203
|
+
}
|
204
|
+
|
175
205
|
PrintAb(A, b, N);
|
176
206
|
|
177
207
|
}
|
178
208
|
|
179
|
-
|
180
|
-
|
181
|
-
|
209
|
+
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
/*前進消去*/
|
186
|
-
|
187
|
-
ai = A;
|
188
|
-
|
189
|
-
ak = A;
|
190
|
-
|
191
|
-
for (k = 0; k < N - 1; k++){
|
192
|
-
|
193
|
-
for (i = k + 1; i < N; i++){
|
194
|
-
|
195
|
-
r = *(ai+i*N+k) / *(ak+k);
|
196
|
-
|
197
|
-
for (j = k; j < N; j++){
|
198
|
-
|
199
|
-
*(ai+i*N+j) -= *(ak+j) * r;
|
200
|
-
|
201
|
-
}
|
202
|
-
|
203
|
-
b[i] -= b[k] * r;
|
204
|
-
|
205
|
-
}
|
206
|
-
|
207
|
-
PrintAb(A, b, N);
|
208
|
-
|
209
|
-
ak+=N;
|
210
|
-
|
211
|
-
}
|
212
|
-
|
213
|
-
|
214
210
|
|
215
211
|
/*後退代入*/
|
216
212
|
|
@@ -232,7 +228,7 @@
|
|
232
228
|
|
233
229
|
}
|
234
230
|
|
235
|
-
|
231
|
+
|
236
232
|
|
237
233
|
/*メモリの解放*/
|
238
234
|
|
@@ -240,7 +236,7 @@
|
|
240
236
|
|
241
237
|
free(b);
|
242
238
|
|
243
|
-
|
239
|
+
|
244
240
|
|
245
241
|
return 0;
|
246
242
|
|
@@ -370,70 +366,44 @@
|
|
370
366
|
|
371
367
|
|
372
368
|
|
369
|
+
A, b =
|
370
|
+
|
371
|
+
1.00 1.00 2.00 | 4.00
|
372
|
+
|
373
|
+
3.00 2.00 -1.00 | -1.00
|
374
|
+
|
375
|
+
2.00 -1.00 1.00 | 5.00
|
376
|
+
|
373
377
|
column 0: row 1 is max
|
374
378
|
|
375
379
|
A, b =
|
376
380
|
|
377
381
|
3.00 2.00 -1.00 | -1.00
|
378
382
|
|
383
|
+
0.00 0.33 2.33 | 4.33
|
384
|
+
|
379
|
-
|
385
|
+
0.00 0.00 18.00 | 36.00
|
380
|
-
|
381
|
-
|
386
|
+
|
382
|
-
|
383
|
-
column 1: row 2 is max
|
384
|
-
|
385
|
-
A, b =
|
387
|
+
A, b =
|
386
|
-
|
388
|
+
|
387
|
-
3.00
|
389
|
+
3.00 2.00 -1.00 | -1.00
|
390
|
+
|
388
|
-
|
391
|
+
0.00 0.33 2.33 | 4.33
|
392
|
+
|
389
|
-
|
393
|
+
0.00 0.00 18.00 | 2.00
|
390
|
-
|
391
|
-
|
394
|
+
|
392
|
-
|
393
|
-
A, b =
|
395
|
+
A, b =
|
394
|
-
|
396
|
+
|
395
|
-
3.00
|
397
|
+
3.00 2.00 -1.00 | -1.00
|
398
|
+
|
396
|
-
|
399
|
+
0.00 0.33 2.33 | -1.00
|
400
|
+
|
397
|
-
|
401
|
+
0.00 0.00 18.00 | 2.00
|
398
|
-
|
399
|
-
|
402
|
+
|
400
|
-
|
401
|
-
A, b =
|
403
|
+
A, b =
|
402
|
-
|
404
|
+
|
403
|
-
3.00
|
405
|
+
3.00 2.00 -1.00 | 1.00
|
404
|
-
|
406
|
+
|
405
|
-
0.00
|
407
|
+
0.00 0.33 2.33 | -1.00
|
406
|
-
|
407
|
-
|
408
|
+
|
408
|
-
|
409
|
-
A, b =
|
410
|
-
|
411
|
-
3.00 -1.00 1.00 | -1.00
|
412
|
-
|
413
|
-
0.00 1.33 1.67 | 5.33
|
414
|
-
|
415
|
-
0.00 0.00
|
409
|
+
0.00 0.00 18.00 | 2.00
|
416
|
-
|
417
|
-
A, b =
|
418
|
-
|
419
|
-
3.00 -1.00 1.00 | -1.00
|
420
|
-
|
421
|
-
0.00 1.33 1.67 | 5.33
|
422
|
-
|
423
|
-
0.00 0.00 -5.00 | 1.20
|
424
|
-
|
425
|
-
A, b =
|
426
|
-
|
427
|
-
3.00 -1.00 1.00 | -1.00
|
428
|
-
|
429
|
-
0.00 1.33 1.67 | 2.50
|
430
|
-
|
431
|
-
0.00 0.00 -5.00 | 1.20
|
432
|
-
|
433
|
-
A, b =
|
434
|
-
|
435
|
-
3.00 -1.00 1.00 | 0.10
|
436
|
-
|
437
|
-
0.00 1.33 1.67 | 2.50
|
438
|
-
|
439
|
-
0.00 0.00 -5.00 | 1.20
|
2
ソースコードの修正
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
C言語 ピボット選択付ガウスの消去法
|
1
|
+
C言語 部分ピボット選択付ガウスの消去法
|
test
CHANGED
@@ -164,11 +164,11 @@
|
|
164
164
|
|
165
165
|
/* 既知ベクトル */
|
166
166
|
|
167
|
-
m = b[k];
|
167
|
+
temp = b[k];
|
168
168
|
|
169
169
|
b[k] = b[m];
|
170
170
|
|
171
|
-
b[m] = m;
|
171
|
+
b[m] = temp;
|
172
172
|
|
173
173
|
}
|
174
174
|
|
@@ -374,9 +374,9 @@
|
|
374
374
|
|
375
375
|
A, b =
|
376
376
|
|
377
|
-
3.00 2.00 -1.00 |
|
377
|
+
3.00 2.00 -1.00 | -1.00
|
378
|
-
|
378
|
+
|
379
|
-
1.00 1.00 2.00 |
|
379
|
+
1.00 1.00 2.00 | 4.00
|
380
380
|
|
381
381
|
2.00 -1.00 1.00 | 5.00
|
382
382
|
|
@@ -384,56 +384,56 @@
|
|
384
384
|
|
385
385
|
A, b =
|
386
386
|
|
387
|
-
3.00 -1.00 1.00 |
|
388
|
-
|
389
|
-
1.00 1.00 2.00 |
|
390
|
-
|
391
|
-
2.00 2.00 -1.00 |
|
392
|
-
|
393
|
-
A, b =
|
394
|
-
|
395
|
-
3.00 -1.00 1.00 |
|
396
|
-
|
397
|
-
1.00 1.00 2.00 |
|
398
|
-
|
399
|
-
2.00 2.00 -1.00 |
|
400
|
-
|
401
|
-
A, b =
|
402
|
-
|
403
|
-
3.00 -1.00 1.00 |
|
404
|
-
|
405
|
-
0.00 1.33 1.67 |
|
406
|
-
|
407
|
-
0.00 2.67 -1.67 |
|
408
|
-
|
409
|
-
A, b =
|
410
|
-
|
411
|
-
3.00 -1.00 1.00 |
|
412
|
-
|
413
|
-
0.00 1.33 1.67 |
|
414
|
-
|
415
|
-
0.00 0.00 -5.00 |
|
416
|
-
|
417
|
-
A, b =
|
418
|
-
|
419
|
-
3.00 -1.00 1.00 |
|
420
|
-
|
421
|
-
0.00 1.33 1.67 |
|
422
|
-
|
423
|
-
0.00 0.00 -5.00 |
|
424
|
-
|
425
|
-
A, b =
|
426
|
-
|
427
|
-
3.00 -1.00 1.00 |
|
428
|
-
|
429
|
-
0.00 1.33 1.67 |
|
430
|
-
|
431
|
-
0.00 0.00 -5.00 |
|
432
|
-
|
433
|
-
A, b =
|
434
|
-
|
435
|
-
3.00 -1.00 1.00 | 0.
|
436
|
-
|
437
|
-
0.00 1.33 1.67 |
|
438
|
-
|
439
|
-
0.00 0.00 -5.00 |
|
387
|
+
3.00 -1.00 1.00 | -1.00
|
388
|
+
|
389
|
+
1.00 1.00 2.00 | 5.00
|
390
|
+
|
391
|
+
2.00 2.00 -1.00 | 4.00
|
392
|
+
|
393
|
+
A, b =
|
394
|
+
|
395
|
+
3.00 -1.00 1.00 | -1.00
|
396
|
+
|
397
|
+
1.00 1.00 2.00 | 5.00
|
398
|
+
|
399
|
+
2.00 2.00 -1.00 | 4.00
|
400
|
+
|
401
|
+
A, b =
|
402
|
+
|
403
|
+
3.00 -1.00 1.00 | -1.00
|
404
|
+
|
405
|
+
0.00 1.33 1.67 | 5.33
|
406
|
+
|
407
|
+
0.00 2.67 -1.67 | 4.67
|
408
|
+
|
409
|
+
A, b =
|
410
|
+
|
411
|
+
3.00 -1.00 1.00 | -1.00
|
412
|
+
|
413
|
+
0.00 1.33 1.67 | 5.33
|
414
|
+
|
415
|
+
0.00 0.00 -5.00 | -6.00
|
416
|
+
|
417
|
+
A, b =
|
418
|
+
|
419
|
+
3.00 -1.00 1.00 | -1.00
|
420
|
+
|
421
|
+
0.00 1.33 1.67 | 5.33
|
422
|
+
|
423
|
+
0.00 0.00 -5.00 | 1.20
|
424
|
+
|
425
|
+
A, b =
|
426
|
+
|
427
|
+
3.00 -1.00 1.00 | -1.00
|
428
|
+
|
429
|
+
0.00 1.33 1.67 | 2.50
|
430
|
+
|
431
|
+
0.00 0.00 -5.00 | 1.20
|
432
|
+
|
433
|
+
A, b =
|
434
|
+
|
435
|
+
3.00 -1.00 1.00 | 0.10
|
436
|
+
|
437
|
+
0.00 1.33 1.67 | 2.50
|
438
|
+
|
439
|
+
0.00 0.00 -5.00 | 1.20
|
1
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
C言語 ピボット
|
1
|
+
C言語 ピボット選択付ガウスの消去法
|
test
CHANGED
File without changes
|