Simple Test to Check Integration Routine

Simple Test to Check Integration Routine

<p>SIMPSON’S RULE Simple Test to check integration routine: Assume r = constant, r = 1</p><p> a g(0) ejk d y  2 ae jk  2 a cos( k )  sin( k ) j (7) a q</p><p> a = 0.001 m and k = /2 m-1</p><p> g(0) (2)(0.001) cos( / 2)  j sin(  / 2)  0  (0.002) j (9)</p><p> a = 0.001 m and k = 2 m-1</p><p> g(0) (2)(0.001) cos(2 )  j sin(2  )  0.002  0 j (10)</p><p>TEST INTEGRALS</p><p>The following integrals are not easy to evaluate within the ranges specified. Each function, at some point changes rapidly with small changes of the independent variable, making such functions extremely difficult to integrate if a high degree of accuracy is required.</p><p>1 x0.001d x  1000 /1001  0.99900999... 0</p><p>Simpson’s rule with matlab (n = 401) = 0.99817473769905 Simpson’s rule with matlab (n = 801) = 0.99858815461115 Simpson’s rule with matlab (n = 1801) = 0.99881766133986</p><p>1 dx  0.0134924856495 0 1+(230x-30)2</p><p>Simpson’s rule with matlab (n = 401) = 0.01345973729507 Simpson’s rule with matlab (n = 801) = 0.01349241039654 Simpson’s rule with matlab (n = 1801) = 0.01349248564961</p><p>4 x2( x 1) 2 ( x  2) 2 ( x  3) 2 ( x  4) 2 d x  1024 / 693  14.776334776 0</p><p>082 mat001.doc 9:34 PM 30/04/18 1 1 4</p><p>1 2</p><p>1 0</p><p>8</p><p>6</p><p>4</p><p>2</p><p>0 0 0 . 5 1 1 . 5 2 2 . 5 3 3 . 5 4</p><p> z = (yq.^2).*((yq-1).^2).*((yq-2).^2).*((yq-3).^2).*((yq-4).^2);</p><p>Simpson’s rule with matlab (n = 51) = 14.78272370632085 Simpson’s rule with matlab (n = 801) = 14.77633487632491 Simpson’s rule with matlab (n = 1801) = 14.77633478023653 Simpson’s rule with matlab (n = 2801) = 14.77633477700115</p><p>082 mat001.doc 9:34 PM 30/04/18 2 MATLAB FILES</p><p>Test for evaluating the integral (int002.doc 5):</p><p>7 -1 zp = 1 m, a = 0.001 m and k = 10 m fn010.m function z = fn010(r,k) z = exp(j*k*r)/r; fndistance.m %086 fndistance.m %calculating the distance between aperture point Q and observation point P %4 sep 00 function r = fndistance(xp,yp,zp,xq,yq,zq) r = ((xp-xq).^2+(yp-yq).^2+zp.^2); mint010.m (mid-point rule) %mint010.m %086 %5 sep 00 %numerical integration g(x): see 082 int002.doc %see file fn010.m for function f(r) = exp(jkr)/r %mid-point rule global a %radius of aperture global ay %lower y bound for integration global by %upper y bound for integration global yq %aperture point Q y coordinate global h %y increment global n %number of partitions global fy %integand fy = exp(jkr)/r global gx %integral of exp(jkr) / r global gx1 global gx1real global gx1imag global k %wave number global zp %z coordinate of point P global f2 clear tic %setup a = 0.001; ay = -a; by = a; n = 1024; k = 1e7; xp = 0;</p><p>082 mat001.doc 9:34 PM 30/04/18 3 yp = 0; zp = 1; xq = 0; zq = 0; h = (by-ay)/n; yq = ay+h/2:h:by-h/2; r = fndistance(xp,yp,zp,xq,yq,zq); for i = 1:n gx(i) = fn010(r(i),k); end gx1 = h*sum(gx); gx1real = real(gx1); gx1imag = imag(gx1); fprintf('midpoint rule: k = %.4e \n',k) fprintf('midpoint rule: n = %.0f \n',n) fprintf('midpoint rule: h = %.4e \n',h) fprintf('midpoint rule: elapsed time = %.4g \n',toc) gx1real gx1imag</p><p>Results for evaluation of integral (5) 7 -1 zp = 1 m, a = 0.001 m and k = 10 m</p><p> n t gx real gx imag h 512 0.17 -5.537041605126E-04 -3.190417940619E-04 3.91E-06 1024 0.33 -5.537135956746E-04 -3.190404021620E-04 1.95E-06</p><p>MINT012.M (SIMPSON’S RULE) </p><p>%mint012.m %086 %6 sep 00 %numerical integration g(x): see 082 int002.doc %see file fn010.m for function f(r) = exp(jkr)/r %Simpson's Rule global a %radius of aperture global ay %lower y bound for integration global by %upper y bound for integration global yq %aperture point Q y coordinate global h %y increment global n %number of partitions global fy %integand fy = exp(jkr)/r global gx %integral of exp(jkr) / r global gx1 global gx1real global gx1imag global k %wave number global zp %z coordinate of point P global f2 clear tic %setup</p><p>082 mat001.doc 9:34 PM 30/04/18 4 a = 0.001; ay = -a; by = a; n = 41; %n must be odd ************** k = 1e7; xp = 0; yp = 0; zp = 1; xq = 0; zq = 0; h = (by-ay)/(n-1); c= 2*ones(n,1); c2=2*ones((n-1)/2,1); c(2:2:n)=c(2:2:n)+c2; c(1)=1; c(n)=1; yq = ay:h:by;</p><p> r = fndistance(xp,yp,zp,xq,yq,zq); for i=1:n gx(i) = fn010(r(i),k); end gx1 = gx*c; gx1 = gx1*h/3; gx1real = real(gx1); gx1imag = imag(gx1); fprintf('midpoint rule: k = %.4e \n',k) fprintf('midpoint rule: n = %.0f \n',n) fprintf('midpoint rule: h = %.4e \n',h) fprintf('midpoint rule: elapsed time = %.4g \n',toc) gx1real gx1imag</p><p>Results for evaluation of integral (5) 7 -1 zp = 1 m, a = 0.001 m and k = 10 m</p><p> n t gx real gx imag h 25 -5.531812107398E-04 -3.193332076714E-04 8.33E-05 51 -5.536894728111E-04 -3.190531525594E-04 4.00E-05 -9.19E-04 8.77E-04 101 0.05 -5.537150540180E-04 -3.190407348213E-04 2.00E-05 -4.62E-05 3.89E-05 201 0.11 -5.537166353765E-04 -3.190399878565E-04 1.00E-05 -2.86E-06 2.34E-06 401 0.11 -5.537167342453E-04 -3.190399415876E-04 5.00E-06 -1.79E-07 1.45E-07</p><p>082 mat001.doc 9:34 PM 30/04/18 5 %mint016.m %086 %6 sep 00 %numerical integration g(x): see 082 int002.doc %see file fn010.m for function f(r) = exp(jkr)/r %calculation of the wave filed along a line in the X-direction %Simpson's Rule global a %radius of aperture global ay %lower y bound for integration global by %upper y bound for integration global ax %lower x bound for integration global ay %upper x bound for integration global yq %aperture point Q y coordinate global hy %y increment in aperture global hx %x increment in aperture global hpx %x increment for observation points global nx %number of partitions nx-1 global ny %number of partitional ny-1 global npx %number of observation points along x axis global fy %integand fy = exp(jkr)/r global gx %integral of exp(jkr) / r global gx1 global U %intreal of the function over the complete surface global k %wave number global wl %wavelength global xp %coordinates of point P - observation point global yp global zp global xpmin global xpmax global xq %coordinates of point Q in aperture global yq global zq global cx %Simpson coefficients 1 4 2 ... 2 4 1 global cy global ix %counters 1, 2, 3 global iy global ipx clear tic %setup a = 0.00005; ax = -a; bx = a; %*********** nx = 29; %n must be odd ************** ny = 59; npx = 100; wl = 633e-9; k = (2*pi)/wl;</p><p>082 mat001.doc 9:34 PM 30/04/18 6 xp = 0; yp = 0; zp = 1; xq = 0; yq = 0; zq = 0; xpmin = 0; xpmax = 0.02;</p><p>%Simpson's Coefficients cx= 2*ones(nx,1); cx2=2*ones((nx-1)/2,1); cx(2:2:nx)=cx(2:2:nx)+cx2; cx(1)=1; cx(nx)=1; gx(1) = 0; gx(nx) = 0; cy= 2*ones(ny,1); cy2=2*ones((ny-1)/2,1); cy(2:2:ny)=cy(2:2:ny)+cy2; cy(1)=1; cy(ny)=1; hx = (bx-ax)/(nx-1); xq = ax:hx:bx; hpx = (xpmax-xpmin)/(npx-1); xp = xpmin:hpx:xpmax; for ipx = 1 : npx; for ix = 2:nx-1 by = (a^2 - xq(ix)^2)^0.5; ay = - by; hy = (by-ay)/(ny-1);</p><p> yq = ay:hy:by;</p><p> for iy =1:ny r = ((xp(ipx)-xq(ix))^2+(yp-yq(iy))^2+zp^2)^0.5; gx1(iy) = exp(j*k*r)/r; %fn010(r,k); end %end for iy gx2 = gx1*cy; gx(ix) = gx2*hy/3; end %end for ix</p><p>U(ipx) = gx*cx; U(ipx) = U(ipx)*hx/3; end %end for ipx</p><p> intensity = conj(U).* U; intensity = intensity./intensity(1); plot(xp,intensity,'bo') hold; rho = (k*a/zp).*xp; rho(1)=rho(1)+eps;</p><p>082 mat001.doc 9:34 PM 30/04/18 7 intensity2 = (2.*besselj(1,rho)./rho).^2; plot(xp,intensity2,'m+') fprintf('nx = %.0f \n',nx) fprintf('ny = %.0f \n',ny) fprintf('k = %.4e \n',k) fprintf('wl = %.4e \n',wl) fprintf('radius a = %.4e \n',a) fprintf('F << 1 = %.4e \n',a^2/(zp*wl)) fprintf('elapsed time = %.4g \n',toc)</p><p>082 mat001.doc 9:34 PM 30/04/18 8</p>

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    8 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us