请教高手帮忙编程序~~用matlab编写数值优化方法(最速下降法,惩罚函数法),具体题目如下:

1. Unconstrained Minimization

Minimize following quadratic functions by resorting to the steepest descent. Use different starting points and discuss the results.

(A) f(x) = 2x12 + x22 _2x1x2 + 8x1 _6x2 +5

(B) f(x) = 100x12 + x22 _2x1x2 _198x1 + 99

(C) f(x) = x12 + x22 + 2x1x2 _2x1 + 1

2. Quasi-unconstrained Minimization

You are provided with two main FORTRAN programs (2D.for and 10D.for) calling a subroutine (QUASI.for). This subroutine has to be completed by you to solve quadratic unconstrained minimization problems with the steepest descent method.

First introduce in QUASI.for the same changes as in part 1. You must therefore introduce lower and upper bounds on the variables.

The following quadratic functions are considered:

(A) f(x) = 2x12 + x22 _2x1x2 + 8x1 _6x2 +5 (2D.for)

Case 1: 5 > xi > -5

Case 2: 5 > xi > 0

Case 3: 1 > xi > -5

Case 4: 1 > xi > 0
(B) (10D.for)
Case 1: 10 > xi > -10

Case 2: 5 > xi > -5

Case 3: 5 > xi > 0

Case 4: 0 > xi > -5

Case 5: 10 > xi > 0

Case 6: 0 > xi > -10

3. Constrained Minimization

Consider the following quadratic problem with the constrained minimization. You must solve it by developing the programs with the internal penalty method and external penalty method respectively.

Use the different the penalty factors and discuss the results.

min (x1-1)2+(x2-1)2
s.t. x1+x2-1<0
x1>0
有哪位高手给解决以下啊,有加分哦~~~~~~~

例1 求 f = 2 在0<x<8中的最小值与最大值
主程序为wliti1.m:
f='2*exp(-x).*sin(x)';
fplot(f,[0,8]); %作图语句
[xmin,ymin]=fminbnd (f, 0,8)
f1='-2*exp(-x).*sin(x)';
[xmax,ymax]=fminbnd (f1, 0,8)
运行结果:
xmin = 3.9270 ymin = -0.0279
xmax = 0.7854 ymax = 0.6448
★(借助课件说明过程、作函数的图形)
例2 对边长为3米的正方形铁板,在四个角剪去相等的正方形以制成方形无盖水槽,问如何剪法使水槽的容积最大?
设剪去的正方形的边长为x,则水槽的容积为: ,建立无约束优化模型为:min y=- , 0<x<1.5
先编写M文件fun0.m如下:
function f=fun0(x)
f=-(3-2*x).^2*x;
主程序为wliti2.m:
[x,fval]=fminbnd('fun0',0,1.5);
xmax=x
fmax=-fval
运算结果为: xmax = 0.5000,fmax =2.0000.即剪掉的正方形的边长为0.5米时水槽的容积最大,最大容积为2立方米.
★(借助课件说明过程、作函数的图形、并编制计算程序)
例3
1、编写M-文件 fun1.m:
function f = fun1 (x)
f = exp(x(1))*(4*x(1)^2+2*x(2)^2+4*x(1)*x(2)+2*x(2)+1);

2、输入M文件wliti3.m如下:
x0 = [-1, 1];
x=fminunc(‘fun1’,x0);
y=fun1(x)
3、运行结果:
x= 0.5000 -1.0000
y = 1.3029e-10
★(借助课件说明过程、作函数的图形并编制计算程序)
例4 Rosenbrock 函数 f(x1,x2)=100(x2-x12)2+(1-x1)2 的最优解(极小)为x*=(1,1),极小值为f*=0.试用不同算法(搜索方向和步长搜索)求数值最优解.初值选为x0=(-1.2 , 2).
为获得直观认识,先画出Rosenbrock 函数的三维图形, 输入以下命令:
[x,y]=meshgrid(-2:0.1:2,-1:0.1:3);
z=100*(y-x.^2).^2+(1-x).^2;
mesh(x,y,z)
画出Rosenbrock 函数的等高线图,输入命令:
contour(x,y,z,20)
hold on
plot(-1.2,2,' o ');
text(-1.2,2,'start point')
plot(1,1,'o')
text(1,1,'solution')
f='100*(x(2)-x(1)^2)^2+(1-x(1))^2';
[x,fval,exitflag,output]=fminsearch(f, [-1.2 2])
运行结果:
x =1.0000 1.0000
fval =1.9151e-010
exitflag = 1
output =
iterations: 108
funcCount: 202
algorithm: 'Nelder-Mead simplex direct search'
★(借助课件说明过程、作函数的图形并编制计算程序)
(五)、 作业
陈酒出售的最佳时机问题
某酒厂有批新酿的好酒,如果现在就出售,可得总收入R0=50万元(人民币),如果窖藏起来待来日(第n年)按陈酒价格出售,第n年末可得总收入 (万元),而银行利率为r=0.05,试分析这批好酒窖藏多少年后出售可使总收入的现值最大. (假设现有资金X万元,将其存入银行,到第n年时增值为R(n)万元,则称X为R(n)的现值.)并填下表:
温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-12-11
这种方法叫做“灰色预测法”,即“GM(1,1)模型”。现在,想用matlab编程function GM1_1(X0) %format long ; [m,n]=size(X0); X1=cumsum(
相似回答