Page 319 - MATLAB an introduction with applications
P. 319
304 ——— MATLAB: An Introduction with Applications
. 2
y = 3*(sin(x) – (x )/12)
3
2
1
0
y –1
–2
–3
–4
–5
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
x
Fig. E5.23
To compute the exact value of the maximum of the function, calculate the negative of the function (y). Use
fminbnd on this new function (fun) to calculate the minimum value. The maximum of the original function
occurs at the same x as the minimum of the new function. The maximum value of the original function is the
negative of the new function.
EDU>> Run_EN_5_23
fun =
@(x)(–1.0)* (3*(sin(x))–(x.^2)/12)
x =
1.4880
fun =
–2.8052
Therefore, the maximum of the original function, f, is
y = 2.8052 at
x = 1.4880
Run_EN_5_23
fun = @(x)(–1.0)* (3*(sin(x)) – (x.^2)/12)
x = fminbnd(fun, 0,5.0)
fun = –1.0 * (3*(sin(x)) – (x.^2)/12)