QQ登录

只需要一步,快速开始

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

几种常见的数值积分的比较

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

2620

主题

162

听众

1万

积分

升级  0%

  • TA的每日心情
    开心
    2015-3-12 15:35
  • 签到天数: 207 天

    [LV.7]常住居民III

    社区QQ达人 发帖功臣 新人进步奖 优秀斑竹奖 金点子奖 原创写作奖 最具活力勋章 助人为乐奖 风雨历程奖

    群组第六届国赛赛前冲刺培

    群组国赛讨论

    群组2014美赛讨论

    群组2014研究生数学建模竞

    群组数学中国试看培训视频

    跳转到指定楼层
    1#
    发表于 2015-1-9 09:58 |只看该作者 |倒序浏览
    |招呼Ta 关注Ta
    不知道要选什么的被积函数比较合适,
    format long
    fun=@(x)cos(x);
    x0=2;
    x1=3;
    tol=10.^[-3:-2:-7,-8];
    n=length(tol);
    info=num2str(tol');
    info=mat2cell(info,ones(n,1),size(info,2));

    y=sin(x1)-sin(x0);  %精确的解
    for i=1:n
            subplot(2,2,i);
            [y1,n1,yiter1]=RectangInt(fun,x0,x1,tol);
            [y2,n2,yiter2]=TrapzInt(fun,x0,x1,tol);
            [y3,n3,yiter3]=SimpsonInt(fun,x0,x1,tol);
            [y4,n4,yiter4]=RombergInt(fun,x0,x1,tol);
            plot(1:log2(n1)+1,yiter1,1:log2(n2)+1,yiter2,1:log2(n3),yiter3,...
                     1:log2(n4)+1,yiter4([(1:log2(n4)+1).*(2:log2(n4)+2)/2]));
            legend('矩形法','梯形法','Simpson','Romberg')
            xlabel('对半次数')
            ylabel('int');
            title(info{i})
    end
    %%%%指定容限比较
    abs([y1,y2,y3,y4]-y)  %残差
    [n1,n2,n3,n4]



    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %%%%矩形法是比较差的一种方法
    fun=@(x)exp(-x.^2);
    x0=0.5;
    x1=2;
    tol=1e-12;
    y=erf(x1)-erf(x0);
    tic;        [y2,n2,yiter2]=TrapzInt(fun,x0,x1,tol);                t2=toc;
    tic;        [y3,n3,yiter3]=SimpsonInt(fun,x0,x1,tol);        t3=toc;
    tic;        [y4,n4,yiter4]=RombergInt(fun,x0,x1,tol);        t4=toc;
    figure
    plot(1:log2(n2)+1,yiter2,1:log2(n3),yiter3,...
             1:log2(n4)+1,yiter4([(1:log2(n4)+1).*(2:log2(n4)+2)/2]));
    abs([y2,y3,y4]-y)  %残差
    [n2,n3,n4]
    [t2,t3,t4]

    legend('梯形法','Simpson','Romberg')
    format
    复制代码
    在本例中。
    对于1e-9容限,矩形法就比较吃力。
    对于1e-15容限,梯形法也比较吃力。


    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-5-22 13:29 , Processed in 0.442419 second(s), 49 queries .

    回顶部