Page 320 - MATLAB an introduction with applications
P. 320
Optimization ——— 305
Example E5.24: Using the MATLAB function fminsearch,
Maximize the function
2
f (x , x ) = 3*x *x + 5*x –x – 3*x with initial guess
2
2
1
2
1
1
1
2
x = –1.0, x = 1.0
1
2
Solution:
The minimum of –f occurs at x = 10.0 y = 5.0 and the minimum has a value of –25.0.
The maximum of the original function, f, occurs at x = 10.0 y = 5.0 and has a value of 25.0.
EDU>> Run_EN_5_24
x =
10.0000 5.0000
fval =
–25.0000
Run_EN_5_24
y=@(x)–1.0 * (3.*x(1).*x(2)+5.*x(1) –x(1).^2 – 3.*(x(2).^2));
[x,fval] = fminsearch(y,[–1.0,1.0])
Example E5.25: Use Powell’s method to find the minimum of the function:
2 2
2
f = 120(y – x ) + (1 – x) starting with (–1, 1)
Solution:
The minimum = 0 at x = 1, y = 1
EDU>> Run_EN_5_25
y =
4.8369e–021
xMin =
1.0000
1.0000
fMin =
4.8369e–021 (which is 0)
nCyc =
12
Run_EN_5_25
global X FUNC
FUNC = @fpr3_15;
X=[–1.0;1.0];
[xMin,fMin,nCyc]=Powell
fpr5_25
function y = fpr3_15(X)
y=120*(X(2)–X(1)^2)^2 + (1.–X(1))^2