- 35
- 0
- 约1.02万字
- 约 32页
- 2017-10-05 发布于河南
- 举报
matlab编程(matlab编程)
matlab编程(matlab编程)
用大m法求解
my w = 2x1 + x2 - x3 and x4
s.t x1 - x2 + x4 = 2 are being built.
- 3x3 2x1 + x2 + x4 = 6
x1 + x2 + x3 + x4 = 7
xi≥0, i = 1, 2, 3, 4
用matlab求解如下:
f = [2.1, - 1, - 1200200200];
a = [1 1 2 1 1 0 0; 2 1 3 1 0 1 0, 1 1 1 1 0 0 1];
b = [2 6 7];
lb = zeroes (7.1);
[x, fval, exitflag, output, lambda] = linprog (f, [], [], a, b, lb)
optimization terminated.
运行结果如下:
x =
3.0000
0.0000
1.0000
3.0000
0.0000
0.0000
0.0000
fval =
2.0000
exitflag =
1
output =
iterations: 7
algorithm: large - scale: interior point.
cgiterations: 0
message: optimization terminated.
lambda =
ineqlin: [0x1 double]
eqlin: [3x1 double]
upper: [7x1 double]
lower: [7x1 double]
从上述运行结果可以得出: 最优解为x =, 最小值约为f * = 2.
用共轭梯度算法求f (x) = (x1 - 1) ^ 2 + 5 * (x2 - x1 ^ 2) ^ 2的极小点, 取初始点x0 =.
用matlab求解如下:
function mg = mg ()
%
% 共轭梯度法求解习题三第26题
%
clc;
clear;
n = 2;
x = 0 [2];
max _ k = 100;
count _ k = 1;
trace (1,1) = x (1);
trace (2,1) = x (2);
trace (3,1) = f _ fun (x);
k = 0;
g1 = f _ dfun (x);
s = - g1;
while count _ k = max _ k
if (k = = n
g0 = f _ dfun (x);
s = - g0;
k = 0;
else
r _ my = fminbnd (@ (t) f _ fun (x + t * s), 100100);
x = x + r _ my * s;
g0 = g1;
g1 = f _ dfun (x);
if standard (g1) 10 ^ (- 6)
break;
than
m = (norm (g1) ^ 2) / (norm (g0) ^ 2);
s = - g1 + m * s;
count _ k = count _ k + 1;
trace (1 count _ k) = x (1);
trace (2 count _ k) = x (2);
trace (3 count _ k) = f _ fun (x);
k = k + 1;
than
than
count _ k
x
f = f (x) _ fun
function g = f (x) _ dfun
g (1,1) = 20 * x (1) ^ 3 - 20 * x (1) * x (2) + 2 * x (1) - 2;
g (2,1) = 10 * x (2) - 10 * x (1) ^ 2;
function f = f (x) _ fun
f = 5 * x (1) ^ 4 - 10 * x (1) ^ 2 * x (2) + x (1) ^ 2 - 2 * x (1) + 1 + 5 * x (2) ^ 2;
运行结果如下:
k =
59
x0 =
1.0000
1.0000
f0 =
0
从上述运行结果可以得出: 最优解为x 最小值约为f =, * = 0.
用bfgs算法求f (x) = (x1 - 1) ^ 2 + 5 * (x2 - x1 ^ 2) ^ 2的极小点, 取初始点x0 =.
用matlab求解如下:
syms x1 x2;
f = (x1 - 1) ^ 2 + 5 * (x2 - x1 ^ 2) ^ 2;
v = [x1, x2];
df = jacobian (f, v);
df = df. ;
x0 = [2.0]; g1 = subs (df {x1, x2}, {x0 (1,1), x0 (2,1)}
您可能关注的文档
- (转)什么是西南大旱的最坏准备_月是故乡明_新浪博客((trans) what's the worst preparation for a drought in Southwest China _ is home next month _ Sina blog).doc
- (人教版)八年级下册语文课后生字词拼音及解释(完整版)((PEP) grade eight Chinese Pinyin words epigenetic and interpretation (full version)).doc
- 0-90度正弦值(0-90 degree sine).doc
- - 上海lng加气站 上海cng加气站博客上海lng加气站 上海cng加气站博客(- Shanghai LNG filling station, Shanghai CNG filling station blog, Shanghai LNG filling station, Shanghai CNG filling station blog).doc
- 010年顺义区中考二模数学试题(010 years of Shunyi District senior high school entrance examination mathematics examination the second mock exam).doc
- (设计)工作细则 - 上海工程技术大学 继续教育学院((Design) working rules - Continuing Education College of Shanghai University of Engineering Science).doc
- 02-03第一学期初三语文试卷52898(02-03 Chinese exam paper for the first semester 52898).doc
- 020我国基层群众自治制度地位的重大提升(020, the important promotion of our country's grass-roots mass autonomy system).doc
- 05-2-1.汉王降价,能降出个怎样的未来(05-2-1. Hanvon prices can drop out of what the future).doc
- 05.无形资产(5 intangible assets).doc
原创力文档

文档评论(0)