在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
1 clc, clear 2 %%%求解线性规划 3 %%min(x) c'x,c、x为n维列向量 4 %%s.t. {Ax <= b; Aeq * x = beq; lb <= x <= ub} 5 %max z = 2x1 + 3x2 - 5x3; 6 %{x1 + x2 + x3 = 7; 2x1 - 5x2 + x3 >= 10; x1 + 3x2 + x3 <= 12; x1, x2, x3 >= 0} 7 % c = [2; 3; -5]; 8 % a = [-2, 5, -1; 1, 3, 1]; 9 % b = [-10; 12]; 10 % aeq = [1, 1, 1]; 11 % beq = 7; 12 %[x, fval] = linprog(c, A, b, Aeq, beq, LB, UB, X0, 13 %OPTIONS),fval返回目标函数的值,LB和UB分别是x的下界和上界,x0是x的初始值,options是控制参数 14 % x = linprog(-c, a, b, aeq, beq, zeros(3, 1))%zeros(3, 1)是LB 15 % value = c' * x 16 % [x, fval] = linprog(-c, a, b, aeq, beq, zeros(3, 1)) 17 18 % 无相等项 19 % c = [2; 3; 1]; 20 % a = [1, 4, 2; 3, 2, 0]; 21 % b = [8; 6]; 22 % [x, y] = linprog(c, -a, -b, [], [], zeros(3, 1)) 23 24 %%循环搜索a 25 % a = 0; 26 % hold on%只要hold in在循环之前或循环中,就可以发挥作用 27 % while a < 0.05 28 % c = [-0.05, -0.27, -0.19, -0.185, -0.185]; 29 % A = [zeros(4, 1), diag([0.025, 0.015, 0.055, 0.026])];%diag创建对角矩阵或获取矩阵的对角元素 30 % b = a * ones(4, 1); 31 % Aeq = [1, 1.01, 1.02, 1.045, 1.065]; 32 % beq = 1; 33 % LB = zeros(5, 1); 34 % [x, Q] = linprog(c, A, b, Aeq, beq, LB); 35 % Q = -Q; 36 % plot(a, Q, '*r'); 37 % 38 % a = a + 0.001; 39 % end 40 % xlabel('a'), ylabel('Q') 41 %
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论