Nested numerical integration

前端 未结 2 694
执笔经年
执笔经年 2021-01-25 08:53

The problem in the link: \"http://i.imgur.com/4w9YWTb.png\" can be integrated analytically and the answer is 4, however I\

2条回答
  •  无人及你
    2021-01-25 09:17

    by no means, this is elegant. hope someone can make better use of matlab functions than me. i have tried the brute force way just to practice numerical integration. i have tried to avoid the pole in the inner integral at z=0 by exploiting the fact that it is also being multiplied by z. i get 3.9993. someone must get better solution by using something better than trapezoidal rule

    function []=sofn
    clear all
    
    global x y z xx yy zz dx dy
    
    dx=0.05;
    x=0:dx:1;
    dy=0.002;
    dz=0.002;
    y=0:dy:1;
    z=0:dz:2;
    
    xx=length(x);
    yy=length(y);
    zz=length(z);
    
    s1=0;
    for i=1:zz-1
        s1=s1+0.5*dz*(z(i+1)*exp(inte1(z(i+1)))+z(i)*exp(inte1(z(i))));
    end
    s1
    
    end
    
    function s2=inte1(localz)
    global y yy dy
    
    if localz==0
        s2=0;
    else
    s2=0;
    for j=1:yy-1
        s2=s2+0.5*dy*(inte2(y(j),localz)+inte2(y(j+1),localz));
    end
    end
    
    end
    
    function s3=inte2(localy,localz)
    global x xx dx
    
    s3=0;
    for k=1:xx-1
        s3=s3+0.5*dx*(2/(localy+localz));
    end
    
    end
    

提交回复
热议问题