⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 golden.m

📁 数值计算常用方法代码集合。对正在学习该课程的同学非常有用。
💻 M
字号:
function [S,E,G]=golden(f,a,b,delta,epsilon)%Input    - f is the object function %            - a and b are the endpoints of the interval%            - delta is the tolerance for the abscissas%            - epsilon is the tolerance for the ordinates%Output - S=(p,yp) contains the abscissa p and%              the ordinate yp of the minimum%            - E=(dp,dy) contains the error bounds for p and yp%            - G is an n x 4 matrix: the kth row contains [ak ck dk bk];%              the values of a, c, d, and b at the kth iteration%If f is defined as an M-file function use the @ notation% call [S,E,G]=golden(@f,a,b,delta,epsilon).%If f is defined as an anonymous function use the% call [S,E,G]=golden(f,a,b,delta,epsilon).%  NUMERICAL METHODS: Matlab Programs% (c) 2004 by John H. Mathews and Kurtis D. Fink%  Complementary Software to accompany the textbook:%  NUMERICAL METHODS: Using Matlab, Fourth Edition%  ISBN: 0-13-065248-2%  Prentice-Hall Pub. Inc.%  One Lake Street%  Upper Saddle River, NJ 07458r1=(sqrt(5)-1)/2;r2=r1^2;h=b-a;ya=f(a);yb=f(b);c=a+r2*h;d=a+r1*h;yc=f(c);yd=f(d);k=1;A(k)=a; B(k)=b; C(k)=c; D(k)=d;while (abs(yb-ya)>epsilon)|(h>delta)   k=k+1;   if (yc<yd)      b=d;      yb=yd;      d=c;      yd=yc;      h=b-a;      c=a+r2*h;      yc=f(c);   else      a=c;      ya=yc;      c=d;      yc=yd;      h=b-a;      d=a+r1*h;      yd=f(d);   end   A(k)=a; B(k)=b; C(k)=c; D(k)=d;enddp=abs(b-a);dy=abs(yb-ya);p=a;yp=ya;if (yb<ya)   p=b;   yp=yb;endG=[A' C' D' B'];S=[p yp];E=[dp dy];

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -