📄 golden.m~
字号:
%xmin - returns this%fxmin - this%n - and thisfunction[xmin,fxmin,n] = golden (xl,xu,maxit,tol,g)% xl = 0.5;% xu = 2;% maxit = 100;% tol = 0.001;% f= x^3 - 2*sin(x);R = (5^0.5 - 1)/2;d = R.* (xu - xl);x1 = xl + d;x2 = xu - d;f1 = feval(g,x1);f2 = feval(g,x2);if f1 > f2 xopt = x1; fx = f1;else xopt = x2; fx = f2;endwhile (ea > tol & n<maxit) d = R*d; if f1 > f2 xl = x2; x2 = x1; x1 = xl + d; f2 = f1; f1 = feval(g,x1); else xu = x1; x1 = x2; x2 = xu - d; f1 = f2; f2 = f); end n = n +1; if f1 > f2 xopt = x1; fx = f1; else xopt = x2; fx = f2; end if xopt ~= 0; ea = (1.-R)*abs((xu-xl)/xopt)*100; endendxmin = xopt;fxmin = fx;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -