Форум программистов, компьютерный форум, киберфорум
C для начинающих
Войти
Регистрация
Восстановить пароль
Карта форума Темы раздела Блоги Сообщество Поиск Заказать работу  
 
Рейтинг 4.93/15: Рейтинг темы: голосов - 15, средняя оценка - 4.93
0 / 0 / 1
Регистрация: 29.01.2012
Сообщений: 5
1

Двойственная задача/симплекс-метод [c]

23.03.2012, 18:55. Показов 2899. Ответов 1
Метки нет (Все метки)

Author24 — интернет-сервис помощи студентам
Дана была прямая задача, необходимо найти решение, а после по полученному решению найти решение двойственной ей задачи.
https://www.cyberforum.ru/cgi-bin/latex.cgi?f\left(\bar{x} \right) = 2 \cdot    {x}_{1} + 3 \cdot {x}_{2} \rightarrow max
при данной системе ограничений:
https://www.cyberforum.ru/cgi-bin/latex.cgi?\left\{\begin{matrix}-3\cdot{x}_{1}& +2\cdot{x}_{2}  & \leq 6 \\ {x}_{1}& -4\cdot{x}_{2}  & \leq 2 \\ {x}_{1}&-{x}_{2}  & \leq 5 \\ x_1, & x_2\geq  0   & \end{matrix}\right.

Решить прямую задачу симплекс-методом получилось, вывод двойственной задачи, задачи в канонической форме тоже, но что делать дальше я не знаю, сказано, что решение двойственной задачи может быть найдено из формулы:
https://www.cyberforum.ru/cgi-bin/latex.cgi?\bar{y*} = \bar {C_B} \cdot D^{-1}
где D - матрица, составленная из векторов, входящих в последний базис, а https://www.cyberforum.ru/cgi-bin/latex.cgi?\bar {C_B}
- вектор базисных переменных(последний получившийся в ходе преобразований)
Проблема-то, собственно, в том, что я не знаю, как получить обратную матрицу D, кроме того верно ее составив. И не помню, как верно перемножить вектор на матрицу.
И код не является универсальным, написан для конкретно этой задачи, и я не знаю, как теперь все пристроить.

C
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
#include <stdio.h>
#include <stdlib.h>
#include <float.h>
#define WIDTH 5
#define HIGH 3
 
void printCanonic(const int arr1[], const double mat[][WIDTH], const double vect[], const int len1, const int len2);
void printTask(const int arr1[], const double mat[][WIDTH], const double vect[], const int len); // вывод задачи
void inverseMatrix(double **, double **, int);
void printDuality(const int arr1[], const double mat[][WIDTH], const double vect[], const int len1, const int len2); // вывод двойствеоон задачи
double simplex(double A[HIGH][WIDTH], double A0[]); // 3-5 столбец - базис, 0 - вектор свободных членов
void printSimplex(int [], int[], int [], int[], double[], double[], double[][HIGH], int, double); //вывод симлекс-таблицы
int nminpos(double [], int); // минимальный отрицательный, позиция, -1 в случае отсутвия отриц.
int pminpos(double [], double[], int); // позиция минимального неотрицательго частного 
double vectorMultiple(int [], double [], int); //скалярное
void swap(int *, int *);
 
const int f[5] = { 2, 3 }; // последние 3 для введенных переменных
 
int main()
{
    double A[HIGH][WIDTH] = { {-3,2,1,0,0}, { 1, -4, 0, 1, 0}, { 1, -1, 0, 0, 1} };
    double b[HIGH] = { 6, 2, 5 };
 
    printTask(f, A, b, 2);
    printCanonic(f,A,b,2,HIGH);
    printDuality(f,A,b,2,HIGH);
 
    simplex(A, b);
    return 0;
 
}
 
void printCanonic(const int arr1[], const double mat[][5], const double vect[], const int len1, const int len2)
{
    int i, j;
    printf("##################################\n");
    printf("#     Task in canonical form     #\n");
    printf("##################################\n\n");
 
    printf("f(x) = ");
    for (i = 0; i < len1; i++)
        printf("%c%dx%d", (i>0 && arr1[i]>0) ? '+' : ' ' ,arr1[i], i+1);
    printf("-> max\n");
 
    printf("System of restrictions: \n");
    for (i = 0; i < len2; i++) {
        for (j = 0; j < 5; j++)
            printf("%c%.lfx%d", (j>0 && mat[i][j]>=0) ? '+' : ' ' ,mat[i][j], j+1);
        printf(" = %.lf\n", vect[i]);
    }
    putchar('\n');
}
 
void printDuality(const int arr1[], const double mat[][WIDTH], const double vect[], const int len1, const int len2)
{
    int i, j;
    printf("##################################\n");
    printf("#           Twofold task         #\n");
    printf("##################################\n\n");
 
    printf("g(y) = ");
    for (i = 0; i < len2; i++)
        printf("%c%.lfy%d", (i>0 && vect[i]>0) ? '+' : ' ' ,vect[i], i+1);
    printf("-> min\n");
 
    printf("System of restrictions: \n");
    for (i = 0; i < len1; i++) {
        for (j = 0; j < len2; j++)
            printf("%c%.lfx%d", (j>0 && mat[j][i]>=0) ? '+' : ' ' ,mat[j][i], j+1);
        printf(" >= %d\n", arr1[i]);
    }
    putchar('\n');
}
 
void printTask(const int arr[], const double mat[][WIDTH], const double vect[], const int len1)
{
    int i, j;
    printf("##################################\n");
    printf("#           Straight task        #\n");
    printf("##################################\n\n");
 
    printf("f(x) = ");
    for (i = 0; i < len1; i++)
        printf("%c%dx%d", (i>0 && arr[i]>0 && arr[i] != 1) ? '+' : ' ' ,arr[i], i+1);
    printf("-> max\n");
 
    printf("System of restrictions: \n");
    for (i = 0; i < HIGH; i++) {
        for (j = 0; j < len1; j++)
            printf("%c%.lfx%d", (j>0 && mat[i][j]>=0) ? '+' : ' ' ,mat[i][j], j+1);
        printf(" <= %.lf\n", vect[i]);
    }
    putchar('\n');
}
 
double simplex(double A[HIGH][WIDTH], double A0[])
{
    int Cbasis[HIGH] = { 0, 0, 0 };
    int basis[HIGH] = {3, 4, 5};
    int notbase[2] = {1,2};
    int Cj[2] = { f[0], f[1] };
    double fstr[2]/*, x[WIDTH] = { 0, 0, A0[0], A0[1], A0[2]}*/;
    double matr[WIDTH][HIGH], commonmatr[WIDTH][HIGH], Q, **D, **D1;
    int r, s, i, j, counter = 0;
 
    for(i=0; i<WIDTH; i++)
        for (j=0; j<HIGH; j++)
            matr[i][j] = A[j][i];
 
    for (i=0; i<2;i++)
        fstr[i] = vectorMultiple(Cbasis, matr[i], HIGH) - f[i];
    Q = vectorMultiple(Cbasis, A0, HIGH);
    
    printf("\nSimplex-matrix:\n");
    printSimplex(Cbasis, basis, Cj, notbase, fstr, A0, matr, 2, Q);
 
    while ((r = nminpos(fstr, 2)) != -1) {
        counter++;
        if ((s = pminpos(matr[r], A0, HIGH)) == -1)
            return -1;
        
        for(i=0; i<WIDTH; i++)
            for (j=0; j<HIGH; j++)
                commonmatr[i][j] = matr[i][j];
 
        matr[r][s] = 1/commonmatr[r][s];
 
        for (i = 0; i < HIGH; i++)
            if (i!=s) matr[r][i] = -commonmatr[r][i] / commonmatr[r][s];
 
        for (i = 0; i < 2; i++)
            if (i!=r) matr[i][s] = commonmatr[i][s] / commonmatr[r][s];
 
        for (i = 0; i < HIGH; i++)
            for (j=0; j<2; j++)
                if ((i != r) && (j!=s))
                    matr[i][j] = (commonmatr[i][j] * commonmatr[r][s] - commonmatr[r][j] * commonmatr[i][s])/commonmatr[r][s];
        
        for (i = 0; i < HIGH; i++) {
            if (i!=s)
                A0[i] = (A0[i] * commonmatr[r][s] - commonmatr[r][i] * A0[s])/commonmatr[r][s]; }
        A0[s] /= commonmatr[r][s];
 
        //f-строка
        for (i = 0; i < 2; i++) {
            if (i!=r)
                fstr[i] = (fstr[i] * commonmatr[r][s] - commonmatr[i][s] * f[r])/commonmatr[r][s]; }
        fstr[r] /= (-commonmatr[r][s]);
 
        swap(&Cbasis[s], &Cj[r]);
        swap(&basis[s], &notbase[r]);
 
        Q = vectorMultiple(Cbasis, A0, HIGH);
        printf("\nSimplex-matrix after %d iteration:\n", counter);
        printSimplex(Cbasis, basis, Cj, notbase, fstr, A0, matr, 2, Q);
    }
    return Q;
}
 
void swap(int *x, int *y)
{
    int temp = *x;
    *x = *y;
    *y = temp;
}
 
int pminpos(double A[], double A0[], int length)
{
    int i, minp = -1;
    double min;
    min = DBL_MAX;
    for (i = 0; i < length; i++) {
        if ((A[i] > 0) && (A0[i]/A[i] < min)) {
            min = A0[i]/A[i];
            minp = i; }
    }
    return minp;
}
 
int nminpos(double A[], int length)
{
    int minp = -1, i;
    double min = 0;
 
    for (i = 0; i < length; i++) {
        if (A[i] < min) {
            min = A[i];
            minp = i; }
    }
    return minp;
}
 
void printSimplex(int Cbas[], int bas[], int cj[], int notb[], double fs[], double a0[], double matrix[][HIGH], int clmn, double Q)
{
    int i;
    printf("_____|__Cj__|__%-5d|__%-5d|_____\n", cj[0], cj[1]);
    printf("Basis|______|_x%-5d|_x%-5d|__A0_\n", notb[0], notb[1]);
    for (i = 0; i < HIGH; i++)
        printf("__%-3d|_x%-4d|%7.2lf|%7.2lf|%5.2lf\n", Cbas[i], bas[i], matrix[0][i], matrix[1][i], a0[i]);
    printf("_____|___f__|%7.2lf|%7.2lf|%5.2lf\n", fs[0], fs[1], Q);
    printf("_____|______|_DELTA1|_DELTA2|__Q__\n");
}
 
double vectorMultiple(int a1[], double a2[], int length)
{
    int i;
    double sum = 0;
 
    for (i = 0; i < length; i++)
        sum += a1[i]*a2[i];
    
    return sum;
}
В общем я совсем запутался, вполне возможно, забыл что-то ещё сделать или сделал не так.
0
Programming
Эксперт
94731 / 64177 / 26122
Регистрация: 12.04.2006
Сообщений: 116,782
23.03.2012, 18:55
Ответы с готовыми решениями:

Симплекс метод - нужен пример реализации
Подскажите как реализовать на си данный метод, алгоритм вроде понятен, но не могу пока все связать!...

Странная задача на симплекс-метод
Всем доброго времени суток. Давече в вузе мне выдали для решения задачу на использование...

Транспортная задача (симплекс-метод)
Помогите, пожалуйста, решить в MathCAD. Заранее спасибо Два предприятия могут производить три...

Задача о диете Симплекс метод
Постановка задачи. Фирме, занимающейся составлением диет, поступил заказ на диету, содержащую по...

1
0 / 0 / 1
Регистрация: 29.01.2012
Сообщений: 5
25.03.2012, 01:31  [ТС] 2
Страшно смотреть на код, но все же реализовал. Ни о какой универсальности речи нет, естественно, ну да ладно, криво-косо, но мб сдам.

C
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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
#include <stdio.h>
#include <stdlib.h>
#include <float.h>
#define WIDTH 5
#define HIGH 3
 
void printCanonic(const int arr1[], const double mat[][WIDTH], const double vect[], const int len1, const int len2);
void printTask(const int arr1[], const double mat[][WIDTH], const double vect[], const int len);
void inverseMatrix(double **, int);
void printDuality(const int arr1[], const double mat[][WIDTH], const double vect[], const int len1, const int len2);
double simplex(double A[HIGH][WIDTH], double A0[]); // 3-5 базис, 0 - вектор свободных членов
void printSimplex(int [], int[], int [], int[], double[], double[], double[][HIGH], int, double);
int nminpos(double [], int);
int pminpos(double [], double[], int);
double vectorMultiple(int [], double [], int);
void swap(int *, int *);
void matrXvect(double **, double *, int);
 
const int f[5] = { 2, 3 };
 
 
int main()
{
    double A[HIGH][WIDTH] = { {-3,2,1,0,0}, { 1, -4, 0, 1, 0}, { 1, -1, 0, 0, 1} };
    double b[HIGH] = { 6, 2, 5 }, result;
 
    printTask(f, A, b, 2);
    printCanonic(f,A,b,2,HIGH);
    printDuality(f,A,b,2,HIGH);
 
    result = simplex(A, b);
    if (result!=-1)
        printf("\nMaximim is %.2lf\nResult is correct.\n", result);
    else
        printf("\nInclorrect result/undecidability problem\n");
    return 0;
 
}
 
void printCanonic(const int arr1[], const double mat[][5], const double vect[], const int len1, const int len2)
{
    int i, j;
    printf("##################################\n");
    printf("#     Task in canonical form     #\n");
    printf("##################################\n\n");
 
    printf("f(x) = ");
    for (i = 0; i < len1; i++)
        printf("%c%dx%d", (i>0 && arr1[i]>0) ? '+' : ' ' ,arr1[i], i+1);
    printf("-> max\n");
 
    printf("System of restrictions: \n");
    for (i = 0; i < len2; i++) {
        for (j = 0; j < 5; j++)
            printf("%c%.lfx%d", (j>0 && mat[i][j]>=0) ? '+' : ' ' ,mat[i][j], j+1);
        printf(" = %.lf\n", vect[i]);
    }
    putchar('\n');
}
 
void printDuality(const int arr1[], const double mat[][WIDTH], const double vect[], const int len1, const int len2)
{
    int i, j;
    printf("##################################\n");
    printf("#           Twofold task         #\n");
    printf("##################################\n\n");
 
    printf("g(y) = ");
    for (i = 0; i < len2; i++)
        printf("%c%.lfy%d", (i>0 && vect[i]>0) ? '+' : ' ' ,vect[i], i+1);
    printf("-> min\n");
 
    printf("System of restrictions: \n");
    for (i = 0; i < len1; i++) {
        for (j = 0; j < len2; j++)
            printf("%c%.lfx%d", (j>0 && mat[j][i]>=0) ? '+' : ' ' ,mat[j][i], j+1);
        printf(" >= %d\n", arr1[i]);
    }
    putchar('\n');
}
 
void printTask(const int arr[], const double mat[][WIDTH], const double vect[], const int len1)
{
    int i, j;
    printf("##################################\n");
    printf("#           Straight task        #\n");
    printf("##################################\n\n");
 
    printf("f(x) = ");
    for (i = 0; i < len1; i++)
        printf("%c%dx%d", (i>0 && arr[i]>0 && arr[i] != 1) ? '+' : ' ' ,arr[i], i+1);
    printf("-> max\n");
 
    printf("System of restrictions: \n");
    for (i = 0; i < HIGH; i++) {
        for (j = 0; j < len1; j++)
            printf("%c%.lfx%d", (j>0 && mat[i][j]>=0) ? '+' : ' ' ,mat[i][j], j+1);
        printf(" <= %.lf\n", vect[i]);
    }
    putchar('\n');
}
 
double simplex(double A[HIGH][WIDTH], double A0[])
{
    int Cbasis[HIGH] = { 0, 0, 0 };
    int basis[HIGH] = {3, 4, 5};
    int notbase[2] = {1,2};
    int Cj[2] = { f[0], f[1] };
    double fstr[2]/*, x[WIDTH] = { 0, 0, A0[0], A0[1], A0[2]}*/;
    double matr[WIDTH][HIGH], commonmatr[WIDTH][HIGH], Q, Qy, D[3][3], *x[3], basdouble[HIGH], commonA0[HIGH];
    int r, s, i, j, counter = 0;
 
    for (j=0; j<HIGH; j++)
        commonA0[j] = A0[j];
 
    for(i=0; i<WIDTH; i++)
        for (j=0; j<HIGH; j++)
            matr[i][j] = A[j][i];
 
    for (i=0; i<2;i++)
        fstr[i] = vectorMultiple(Cbasis, matr[i], HIGH) - f[i];
    Q = vectorMultiple(Cbasis, A0, HIGH);
    
    printf("\nSimplex-matrix:\n");
    printSimplex(Cbasis, basis, Cj, notbase, fstr, A0, matr, 2, Q);
 
    while ((r = nminpos(fstr, 2)) != -1) {
        counter++;
        if ((s = pminpos(matr[r], A0, HIGH)) == -1)
            return -1;
        
        for(i=0; i<WIDTH; i++)
            for (j=0; j<HIGH; j++)
                commonmatr[i][j] = matr[i][j];
 
        matr[r][s] = 1/commonmatr[r][s];
 
        for (i = 0; i < HIGH; i++)
            if (i!=s) matr[r][i] = -commonmatr[r][i] / commonmatr[r][s];
 
        for (i = 0; i < 2; i++)
            if (i!=r) matr[i][s] = commonmatr[i][s] / commonmatr[r][s];
 
        for (i = 0; i < HIGH; i++)
            for (j=0; j<2; j++)
                if ((i != r) && (j!=s))
                    matr[i][j] = (commonmatr[i][j] * commonmatr[r][s] - commonmatr[r][j] * commonmatr[i][s])/commonmatr[r][s];
        
        for (i = 0; i < HIGH; i++) {
            if (i!=s)
                A0[i] = (A0[i] * commonmatr[r][s] - commonmatr[r][i] * A0[s])/commonmatr[r][s]; }
        A0[s] /= commonmatr[r][s];
 
        //f-строка
        for (i = 0; i < 2; i++) {
            if (i!=r)
                fstr[i] = (fstr[i] * commonmatr[r][s] - commonmatr[i][s] * f[r])/commonmatr[r][s]; }
        fstr[r] /= (-commonmatr[r][s]);
 
        swap(&Cbasis[s], &Cj[r]);
        swap(&basis[s], &notbase[r]);
 
        Q = vectorMultiple(Cbasis, A0, HIGH);
        printf("\nSimplex-matrix after %d iteration:\n", counter);
        printSimplex(Cbasis, basis, Cj, notbase, fstr, A0, matr, 2, Q);
    }
 
    for (i=0; i<3; i++)
        for (j=0;j<3;j++)
            D[i][j] = A[j][basis[i]-1];
 
    printf("\nMatrix D of last basis columns:\n");
 
    for (i=0; i<3; i++) {
        x[i] = D[i];
        for (j=0;j<3;j++)
        printf("%.2lf ", x[i][j] = D[i][j]);
        putchar('\n');}
 
    inverseMatrix(x, 3);
 
    printf("\nInvert matrix D^-1:\n");
 
    for (i=0; i<3; i++) {
        for (j=0;j<3;j++)
            printf("%.2lf ", x[i][j]);
        putchar('\n');}
 
 
    for (i=0; i<3; i++)
        basdouble[i] = Cbasis[i];
 
    matrXvect(x, basdouble, 3);
 
    printf("\nVector y = (");
    for (i=0; i<3; i++)
        printf("%.2lf, ",basdouble[i]);
    printf(")\n");
 
    printf("\nValue of duality funclion:\n");
    printf("g(y) = ");
    Qy = 0;
    for (i = 0; i < HIGH; i++) {
        Qy+=commonA0[i]*basdouble[i];
        printf("%c%.lfy%d", (i>0 && commonA0[i]>0) ? '+' : ' ' ,commonA0[i], i+1); }
    printf(" = %.2lf\n", Qy);
 
    if (Q!=Qy)
        return -1;
 
    return Q;
}
 
void swap(int *x, int *y)
{
    int temp = *x;
    *x = *y;
    *y = temp;
}
 
int pminpos(double A[], double A0[], int length)
{
    int i, minp = -1;
    double min;
    min = DBL_MAX;
    for (i = 0; i < length; i++) {
        if ((A[i] > 0) && (A0[i]/A[i] < min)) {
            min = A0[i]/A[i];
            minp = i; }
    }
    return minp;
}
 
int nminpos(double A[], int length)
{
    int minp = -1, i;
    double min = 0;
 
    for (i = 0; i < length; i++) {
        if (A[i] < min) {
            min = A[i];
            minp = i; }
    }
    return minp;
}
 
void printSimplex(int Cbas[], int bas[], int cj[], int notb[], double fs[], double a0[], double matrix[][HIGH], int clmn, double Q)
{
    int i;
    printf("_____|__Cj__|__%-5d|__%-5d|_____\n", cj[0], cj[1]);
    printf("Basis|______|_x%-5d|_x%-5d|__A0_\n", notb[0], notb[1]);
    for (i = 0; i < HIGH; i++)
        printf("__%-3d|_x%-4d|%7.2lf|%7.2lf|%5.2lf\n", Cbas[i], bas[i], matrix[0][i], matrix[1][i], a0[i]);
    printf("_____|___f__|%7.2lf|%7.2lf|%5.2lf\n", fs[0], fs[1], Q);
    printf("_____|______|_DELTA1|_DELTA2|__Q__\n");
}
 
double vectorMultiple(int a1[], double a2[], int length)
{
    int i;
    double sum = 0;
 
    for (i = 0; i < length; i++)
        sum += a1[i]*a2[i];
    
    return sum;
}
 
void inverseMatrix(double **A, int n)
{
 
    ///Метод гауссса-йордана
    int i,j,k,m;
    double akk, aik, r, E[HIGH][HIGH] = { {1,0,0}, {0,1,0}, {0,0,1} };
    m = 0;
 
    for (k=0; k <= n-1; k++)
    {
        if ((A[k][k]) == 0) {
            m = k +1;
            while (m<=n && A[m][k]==0)
                m++;
            if (m > n)// {
                printf("Matrix is degenerate\n");
                //return -1 }
            for (i = 0; i<n; i++) {
                r = A[m][i];
                A[m][i] = A[k][i];
                A[k][i] = r;
                
                r = E[m][i];
                E[m][i] = E[k][i];
                E[k][i] = r; }
        }
        akk = A[k][k];
        //A[k][k]/=akk;
        E[k][k]/=akk;
        for (i = 0; i < n; i++)
            if (i!=k) {
                aik = A[i][k]/akk;
                for (j = k; j < n; j++) {
                    A[i][j] = A[i][j] - aik*A[k][j];
                    E[i][j] = (E[i][j] - aik*E[k][j])/A[i][i]; }
            };
 
    };
 
    for (i = 0; i < n; i++)
        for (j = 0; j < n; j++)
            A[i][j] = E[i][j];
}
 
void matrXvect(double **A, double *c, int n)
{
    double ii;
    int i, j;
 
    for (i = 0; i < n; i++) {
        ii = 0;
        for (j = 0; j < n; j++)
            ii += A[j][i]*c[i];
        c[i] = ii; }
}
Закрывайте штоле...
0
25.03.2012, 01:31
IT_Exp
Эксперт
87844 / 49110 / 22898
Регистрация: 17.06.2006
Сообщений: 92,604
25.03.2012, 01:31
Помогаю со студенческими работами здесь

Симплекс метод. Задача с двусторонними ограничениями
Нужна задачка, без разницы как реализована....главное чтобы работала. И именно не просто симлекс...

Двойственная задача
Добрый вечер! Есть задача, к ней нужно написать двойственную и проверить её(на совпадение с...

Двойственная задача
Здравствуйте!Помогите в решении,пожалуйста.Предприятие может выпускать 2 вида продукции чистая...

Двойственная задача. Теория игр
Здравствуйте. Подскажите пожалуйста как решить двойственную задачу по теории игр. У меня есть...


Искать еще темы с ответами

Или воспользуйтесь поиском по форуму:
2
Ответ Создать тему
КиберФорум - форум программистов, компьютерный форум, программирование
Powered by vBulletin
Copyright ©2000 - 2024, CyberForum.ru