QQ登录

只需要一步,快速开始

 注册地址  找回密码
查看: 1024|回复: 0
打印 上一主题 下一主题

请问 对于以下的黄金分割搜索算法如何改动?

[复制链接]
字体大小: 正常 放大

6

主题

10

听众

459

积分

  • TA的每日心情
    擦汗
    2016-10-21 17:52
  • 签到天数: 195 天

    [LV.7]常住居民III

    自我介绍
    可以站上数学建模的高峰!

    群组2016国赛优秀论文解析

    群组2016数学建模算法集锦

    群组2016美赛优秀论文解析

    群组2015美赛优秀论文解析

    群组2015美赛护航(强化)

    跳转到指定楼层
    1#
    发表于 2014-12-13 03:53 |只看该作者 |倒序浏览
    |招呼Ta 关注Ta
    我要求解f(x)=x^2+sin(x)在(0,1)上的最小值,然后精确度大概到0.000001位就行了,以下的代码该如何改?需要在前面加些什么?如何加呢?求大神!

    function [S,E,G]=golden(f,a,b,delta,epsilon)

    %Input  - f is the object function input as a string 'f'
    %       - 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

    %  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 07458

    r1=(sqrt(5)-1)/2;
    r2=r1^2;
    h=b-a;
    ya=feval(f,a);
    yb=feval(f,b);
    c=a+r2*h;
    d=a+r1*h;
    yc=feval(f,c);
    yd=feval(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=feval(f,c);
       else
          a=c;
          ya=yc;
          c=d;
          yc=yd;
          h=b-a;
          d=a+r1*h;
          yd=feval(f,d);
       end
       A(k)=a; B(k)=b; C(k)=c; D(k)=d;
    end

    dp=abs(b-a);
    dy=abs(yb-ya);
    p=a;
    yp=ya;

    if (yb<ya)
       p=b;
       yp=yb;
    end

    G=[A' C' D' B'];
    S=[p yp];
    E=[dp dy];
    zan
    转播转播0 分享淘帖0 分享分享0 收藏收藏0 支持支持0 反对反对0 微信微信
    您需要登录后才可以回帖 登录 | 注册地址

    qq
    收缩
    • 电话咨询

    • 04714969085
    fastpost

    关于我们| 联系我们| 诚征英才| 对外合作| 产品服务| QQ

    手机版|Archiver| |繁體中文 手机客户端  

    蒙公网安备 15010502000194号

    Powered by Discuz! X2.5   © 2001-2013 数学建模网-数学中国 ( 蒙ICP备14002410号-3 蒙BBS备-0002号 )     论坛法律顾问:王兆丰

    GMT+8, 2025-9-5 09:58 , Processed in 0.427249 second(s), 49 queries .

    回顶部