Permalink
Showing
with
3,557 additions
and 63 deletions.
- BIN lecture_07/.lecture_07.md.swo
- +36 −0 lecture_08/goldmin.m
- +969 −63 lecture_08/lecture_08.ipynb
- +626 −0 lecture_08/lecture_08.md
- +168 −0 lecture_08/lecture_08_files/lecture_08_11_0.svg
- +163 −0 lecture_08/lecture_08_files/lecture_08_12_0.svg
- +163 −0 lecture_08/lecture_08_files/lecture_08_13_0.svg
- +142 −0 lecture_08/lecture_08_files/lecture_08_16_1.svg
- +136 −0 lecture_08/lecture_08_files/lecture_08_17_1.svg
- +135 −0 lecture_08/lecture_08_files/lecture_08_19_1.svg
- +196 −0 lecture_08/lecture_08_files/lecture_08_23_0.svg
- +147 −0 lecture_08/lecture_08_files/lecture_08_3_0.svg
- +169 −0 lecture_08/lecture_08_files/lecture_08_6_1.svg
- +169 −0 lecture_08/lecture_08_files/lecture_08_7_1.svg
- +169 −0 lecture_08/lecture_08_files/lecture_08_8_1.svg
- +169 −0 lecture_08/lecture_08_files/lecture_08_9_1.svg
- BIN lecture_08/octave-workspace
Binary file not shown.
@@ -0,0 +1,36 @@ | ||
function [x,fx,ea,iter]=goldmin(f,xl,xu,es,maxit,varargin) | ||
% goldmin: minimization golden section search | ||
% [x,fx,ea,iter]=goldmin(f,xl,xu,es,maxit,p1,p2,...): | ||
% uses golden section search to find the minimum of f | ||
% input: | ||
% f = name of function | ||
% xl, xu = lower and upper guesses | ||
% es = desired relative error (default = 0.0001%) | ||
% maxit = maximum allowable iterations (default = 50) | ||
% p1,p2,... = additional parameters used by f | ||
% output: | ||
% x = location of minimum | ||
% fx = minimum function value | ||
% ea = approximate relative error (%) | ||
% iter = number of iterations | ||
if nargin<3,error('at least 3 input arguments required'),end | ||
if nargin<4|isempty(es), es=0.0001;end | ||
if nargin<5|isempty(maxit), maxit=50;end | ||
phi=(1+sqrt(5))/2; | ||
iter=0; | ||
while(1) | ||
d = (phi-1)*(xu - xl); | ||
x1 = xl + d; | ||
x2 = xu - d; | ||
if f(x1,varargin{:}) < f(x2,varargin{:}) | ||
xopt = x1; | ||
xl = x2; | ||
else | ||
xopt = x2; | ||
xu = x1; | ||
end | ||
iter=iter+1; | ||
if xopt~=0, ea = (2 - phi) * abs((xu - xl) / xopt) * 100;end | ||
if ea <= es | iter >= maxit,break,end | ||
end | ||
x=xopt;fx=f(xopt,varargin{:}); |

Oops, something went wrong.