MATLAB Mathematics - SERC - Index of
MATLAB Mathematics - SERC - Index of MATLAB Mathematics - SERC - Index of
4 Function Functions end function stop = myoutput(x,optimvalues,state); stop = false; if state == 'iter' history = [history; x]; end end function z = objfun(x) z = exp(x(1))*(4*x(1)^2+2*x(2)^2+x(1)*x(2)+2*x(2)); end 3 Save the file as myproblem.m in a directory on the MATLAB path. 4 At the MATLAB prompt, enter [x fval history] = myproblem([-1 1]) The function fminsearch returns x, the optimal point, and fval, the value of the objective function at x. x = 0.1290 -0.5323 fval = -0.5689 In addition, the output function myoutput returns the matrix history, which contains the points generated by the algorithm at each iteration, to the MATLAB workspace. The first four rows of history are history(1:4,:) ans = -1.0000 1.0000 -1.0000 1.0500 -1.0750 0.9000 -1.0125 0.8500 4-18
Minimizing Functions and Finding Zeros The final row of points is the same as the optimal point, x. history(end,:) ans = 0.1290 -0.5323 objfun(history(end,:)) ans = -0.5689 Fields in optimValues The following table lists the fields of the optimValues structure that are provided by all three optimization functions, fminbnd, fminsearch, and fzero. The function fzero also provides additional fields that are described in its reference page. The “Command-Line Display Headings” column of the table lists the headings, corresponding to the optimValues fields that are displayed at the command line when you set the Display parameter of options to 'iter'. optimValues Field (optimValues.field) funcount fval Description Cumulative number of function evaluations. Function value at current point. Command-Line Display Heading Func-count min f(x) iteration Iteration number — starts at 0. Iteration procedure Procedure messages Procedure 4-19
- Page 70 and 71: 2 Polynomials and Interpolation Int
- Page 72 and 73: 2 Polynomials and Interpolation for
- Page 74 and 75: 2 Polynomials and Interpolation Con
- Page 76 and 77: 2 Polynomials and Interpolation Lat
- Page 78 and 79: 2 Polynomials and Interpolation −
- Page 80 and 81: 2 Polynomials and Interpolation −
- Page 82 and 83: 2 Polynomials and Interpolation 7 3
- Page 84 and 85: 2 Polynomials and Interpolation T =
- Page 86 and 87: 2 Polynomials and Interpolation Bec
- Page 88 and 89: 2 Polynomials and Interpolation Int
- Page 90 and 91: 2 Polynomials and Interpolation 2-3
- Page 92 and 93: 2 Polynomials and Interpolation 2-3
- Page 94 and 95: 3 Fast Fourier Transform (FFT) Intr
- Page 96 and 97: 3 Fast Fourier Transform (FFT) 200
- Page 98 and 99: 3 Fast Fourier Transform (FFT) 2 x
- Page 100 and 101: 3 Fast Fourier Transform (FFT) 500
- Page 102 and 103: 3 Fast Fourier Transform (FFT) Func
- Page 104 and 105: 4 Function Functions Function Summa
- Page 106 and 107: 4 Function Functions You can also c
- Page 108 and 109: 4 Function Functions 25 20 15 10 5
- Page 110 and 111: 4 Function Functions Minimizing Fun
- Page 112 and 113: 4 Function Functions To try fminsea
- Page 114 and 115: 4 Function Functions Plotting the R
- Page 116 and 117: 4 Function Functions The number of
- Page 118 and 119: 4 Function Functions and displays t
- Page 122 and 123: 4 Function Functions States of the
- Page 124 and 125: 4 Function Functions 100 80 60 40 2
- Page 126 and 127: 4 Function Functions You can verify
- Page 128 and 129: 4 Function Functions Troubleshootin
- Page 130 and 131: 4 Function Functions A three-dimens
- Page 132 and 133: 4 Function Functions Parameterizing
- Page 134 and 135: 4 Function Functions “Anonymous F
- Page 136 and 137: 5 Differential Equations Initial Va
- Page 138 and 139: 5 Differential Equations odephas3 o
- Page 140 and 141: 5 Differential Equations This secti
- Page 142 and 143: 5 Differential Equations The basic
- Page 144 and 145: 5 Differential Equations 2 Code the
- Page 146 and 147: 5 Differential Equations function.
- Page 148 and 149: 5 Differential Equations One way to
- Page 150 and 151: 5 Differential Equations y0, yp0 Ve
- Page 152 and 153: 5 Differential Equations For exampl
- Page 154 and 155: 5 Differential Equations 1 0.8 0.6
- Page 156 and 157: 5 Differential Equations 2.5 Soluti
- Page 158 and 159: 5 Differential Equations To run thi
- Page 160 and 161: 5 Differential Equations 2 u′ i =
- Page 162 and 163: 5 Differential Equations dydt(i+1,:
- Page 164 and 165: 5 Differential Equations refine = 4
- Page 166 and 167: 5 Differential Equations Example: A
- Page 168 and 169: 5 Differential Equations function [
4 Function Functions<br />
end<br />
function stop = myoutput(x,optimvalues,state);<br />
stop = false;<br />
if state == 'iter'<br />
history = [history; x];<br />
end<br />
end<br />
function z = objfun(x)<br />
z = exp(x(1))*(4*x(1)^2+2*x(2)^2+x(1)*x(2)+2*x(2));<br />
end<br />
3 Save the file as myproblem.m in a directory on the <strong>MATLAB</strong> path.<br />
4 At the <strong>MATLAB</strong> prompt, enter<br />
[x fval history] = myproblem([-1 1])<br />
The function fminsearch returns x, the optimal point, and fval, the value <strong>of</strong><br />
the objective function at x.<br />
x =<br />
0.1290 -0.5323<br />
fval =<br />
-0.5689<br />
In addition, the output function myoutput returns the matrix history, which<br />
contains the points generated by the algorithm at each iteration, to the<br />
<strong>MATLAB</strong> workspace. The first four rows <strong>of</strong> history are<br />
history(1:4,:)<br />
ans =<br />
-1.0000 1.0000<br />
-1.0000 1.0500<br />
-1.0750 0.9000<br />
-1.0125 0.8500<br />
4-18