1. Trang chủ
  2. » Kỹ Thuật - Công Nghệ

Advanced Mathematics and Mechanics Applications Using MATLAB phần 4 doc

61 323 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 61
Dung lượng 6,24 MB

Nội dung

184 ADVANCED MATH AND MECHANICS APPLICATIONS USING MATLAB −2 −1 0 1 2 0 1 2 3 4 0 0.5 1 1.5 2 2.5 3 3.5 4 x axis Surface Plot of a General Polyhedron y axis z axis Figure 5.6: Surface Plot of a General Polyhedron © 2003 by CRC Press LLC GAUSS INTEGRATION WITH GEOMETRIC PROPERTY APPLICATIONS 185 Program polhdrun 1: function polhdrun 2: % Example: polhdrun 3: % ~~~~~~~~~~~~~~~~~ 4: % 5: % This program illustrates the use of routine 6: % polhedrn to calculate the geometrical 7: % properties of a polyhedron. 8: % 9: % User m functions called: 10: % crosmat, polyxy, cubrange, pyramid, 11: % polhdplt, polhedrn 12: 13: x=[2 2 2 2 2 2 0 0 0 0 0 0]-1; 14: y=[0 4 4 2 3 3 0 4 4 2 3 3]; 15: z=[0 0 4 1 1 2 0 0 4 1 1 2]; 16: idface=[1 2 365463; 17: 13970000; 18: 17820000; 19: 28930000; 20: 7 9 12 10 11 12 9 8; 21: 4101260000; 22: 4511100000; 23: 5612110000]; 24: polhdplt(x,y,z,idface,[1,1,1]); 25: [v,rc,vrr,irr]=polhedrn(x,y,z,idface) 26: 27: %============================================= 28: 29: function [v,rc,vrr,irr]=polhedrn(x,y,z,idface) 30: % 31: % [v,rc,vrr,irr]=polhedrn(x,y,z,idface) 32: % ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 33: % 34: % This function determines the volume, 35: % centroidal coordinates and inertial moments 36: % for an arbitrary polyhedron. 37: % 38: % x,y,z - vectors containing the corner 39: % indices of the polyhedron 40: % idface - a matrix in which row j defines the 41: % corner indices of the j’th face. © 2003 by CRC Press LLC 186 ADVANCED MATH AND MECHANICS APPLICATIONS USING MATLAB 42: % Each face is traversed in a 43: % counterclockwise sense relative to 44: % the outward normal. The column 45: % dimension equals the largest number 46: % of indices needed to define a face. 47: % Rows requiring fewer than the 48: % maximum number of corner indices are 49: % padded with zeros on the right. 50: % 51: % v - the volume of the polyhedron 52: % rc - the centroidal radius 53: % vrr - the integral of R*R’*d(vol) 54: % irr - the inertia tensor for a rigid body 55: % of unit mass obtained from vrr as 56: % eye(3,3)*sum(diag(vrr))-vrr 57: % 58: % User m functions called: pyramid 59: % 60: 61: r=[x(:),y(:),z(:)]; nf=size(idface,1); 62: v=0; vr=0; vrr=0; 63: for k=1:nf 64: i=idface(k,:); i=i(find(i>0)); 65: [u,ur,urr]=pyramid(r(i,:)); 66: v=v+u; vr=vr+ur; vrr=vrr+urr; 67: end 68: rc=vr/v; irr=eye(3,3)*sum(diag(vrr))-vrr; 69: 70: %============================================= 71: 72: function [area,xbar,ybar,axx,axy,ayy]=polyxy(x,y) 73: % 74: % [area,xbar,ybar,axx,axy,ayy]=polyxy(x,y) 75: % ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 76: % 77: % This function computes the area, centroidal 78: % coordinates, and inertial moments of an 79: % arbitrary polygon. 80: % 81: % x,y - vectors containing the corner 82: % coordinates. The boundary is 83: % traversed in a counterclockwise 84: % direction 85: % 86: % area - the polygon area © 2003 by CRC Press LLC GAUSS INTEGRATION WITH GEOMETRIC PROPERTY APPLICATIONS 187 87: % xbar,ybar - the centroidal coordinates 88: % axx - integral of x^2*dxdy 89: % axy - integral of xy*dxdy 90: % ayy - integral of y^2*dxdy 91: % 92: % User m functions called: none 93: % 94: 95: n=1:length(x); n1=n+1; 96: x=[x(:);x(1)]; y=[y(:);y(1)]; 97: a=(x(n).*y(n1)-y(n).*x(n1))’; 98: area=sum(a)/2; a6=6*area; 99: xbar=a*(x(n)+x(n1))/a6; ybar=a*(y(n)+y(n1))/a6; 100: ayy=a*(y(n).^2+y(n).*y(n1)+y(n1).^2)/12; 101: axy=a*(x(n).*(2*y(n)+y(n1))+x(n1).* 102: (2*y(n1)+y(n)))/24; 103: axx=a*(x(n).^2+x(n).*x(n1)+x(n1).^2)/12; 104: 105: %============================================= 106: 107: function [v,vr,vrr,h,area,n]=pyramid(r) 108: % 109: % [v,vr,vrr,h,area,n]=pyramid(r) 110: % ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 111: % 112: % This function determines geometrical 113: % properties of a pyramid with the apex at the 114: % origin and corner coordinates of the base 115: % stored in the rows of r. 116: % 117: % r - matrix containing the corner 118: % coordinates of a polygonal base stored 119: % in the rows of matrix r. 120: % 121: % v - the volume of the pyramid 122: % vr - the first moment of volume relative to 123: % the origin 124: % vrr - the second moment of volume relative 125: % to the origin 126: % h - the pyramid height 127: % area - the base area 128: % n - the outward directed unit normal to 129: % the base 130: % 131: % User m functions called: crosmat, polyxy © 2003 by CRC Press LLC 188 ADVANCED MATH AND MECHANICS APPLICATIONS USING MATLAB 132: % 133: 134: ns=size(r,1); 135: na=sum(crosmat(r,r([2:ns,1],:)))’/2; 136: area=norm(na); n=na/area; p=null(n’); 137: i=p(:,1); j=p(:,2); 138: if det([p,n])<0, j=-j; end; 139: r1=r(1,:); rr=r-r1(ones(ns,1),:); 140: x=rr*i; y=rr*j; 141: [areat,xc,yc,axx,axy,ayy]=polyxy(x,y); 142: rc=r1’+xc*i+yc*j; h=r1*n; 143: v=h*area/3; vr=v*3/4*rc; 144: axx=axx-area*xc^2; ayy=ayy-area*yc^2; 145: axy=axy-area*xc*yc; 146: vrr=h/5*(area*rc*rc’+axx*i*i’+ayy*j*j’+ 147: axy*(i*j’+j*i’)); 148: 149: %============================================= 150: 151: function polhdplt(x,y,z,idface,colr) 152: % 153: % polhdplt(x,y,z,idface,colr) 154: % ~~~~~~~~~~~~~~~~~~~~~~~~~~~ 155: % 156: % This function makes a surface plot of an 157: % arbitrary polyhedron. 158: % 159: % x,y,z - vectors containing the corner 160: % indices of the polyhedron 161: % idface - a matrix in which row j defines the 162: % corner indices of the j’th face. 163: % Each face is traversed in a 164: % counterclockwise sense relative to 165: % the outward normal. The column 166: % dimension equals the largest number 167: % of indices needed to define a face. 168: % Rows requiring fewer than the 169: % maximum number of corner indices are 170: % padded with zeros on the right. 171: % colr - character string or a vector 172: % defining the surface color 173: % 174: % User m functions called: cubrange 175: % 176: © 2003 by CRC Press LLC GAUSS INTEGRATION WITH GEOMETRIC PROPERTY APPLICATIONS 189 177: if nargin<5, colr=[1 0 1]; end 178: hold off, close; nf=size(idface,1); 179: v=cubrange([x(:),y(:),z(:)],1.1); 180: for k=1:nf 181: i=idface(k,:); i=i(find(i>0)); 182: xi=x(i); yi=y(i); zi=z(i); 183: fill3(xi,yi,zi,colr); hold on; 184: end 185: axis(v); grid on; 186: xlabel(’x axis’); ylabel(’y axis’); 187: zlabel(’z axis’); 188: title(’Surface Plot of a General Polyhedron’); 189: figure(gcf); hold off; 190: 191: %============================================= 192: 193: function c=crosmat(a,b) 194: % 195: % c=crosmat(a,b) 196: % ~~~~~~~~~~~~~~ 197: % 198: % This function computes the vector cross 199: % product for vectors stored in the rows 200: % of matrices a and b, and returns the 201: % results in the rows of c. 202: % 203: % User m functions called: none 204: % 205: 206: c=[a(:,2).*b(:,3)-a(:,3).*b(:,2), 207: a(:,3).*b(:,1)-a(:,1).*b(:,3), 208: a(:,1).*b(:,2)-a(:,2).*b(:,1)]; 209: 210: %============================================= 211: 212: % function range=cubrange(xyz,ovrsiz) 213: % See Appendix B © 2003 by CRC Press LLC 190 ADVANCED MATH AND MECHANICS APPLICATIONS USING MATLAB 5.8 Evaluating Integrals Having Square Root Type Singularities Consider the problem of evaluating the following three integrals having square root type singularities at one or both ends of the integration interval: I 1 = b  a f(x) √ x − a dx , I 2 = b  a f(x) √ b − x dx , I 3 = b  a f(x)  (x − a)(b − x) dx. The singularities in these integrals can be removed using substitutions x − a = t 2 ,b− x = t 2 , and (x −a)(b − x)=(b + a)/2+(b − a)/2cos(t) which lead to I 1 =2 √ b−a  0 f(a + t 2 ) dt , I 2 =2 √ b−a  0 f(b − t 2 ) dt I 3 = π  0 f( b + a 2 + b − a 2 cos(t))dt. These modiÞed integrals can be evaluated using gcquad or quadl by creating in- tegrands with appropriate argument shifts. Two integration functions quadgsqrt and quadlsqrt were written to handle each of the three integral types. Shown be- low is a program called sqrtquadtest which computes results for the case where f(x)=e ux cos(vx) with constants u and v being parameters passed to the inte- grators using the varargin construct in MATLAB. Function quadgsqrt uses Gauss quadrature to evaluate I 1 and I 2 , and uses Chebyshev quadrature [1] to evaluate I 3 . When f(x) is a polynomial, then taking parameter norder in function quadgsqrt equal to the polynomial order gives exact results. With norder taken sufÞciently high, more complicated functions can also be integrated accurately. Function quadl- sqrt evaluates the three integral types using the adaptive integrator quadl, which accommodates f(x) of quite general form. The program shown below integrates the test function for parameter choices corresponding to [a, b, u, v]=[1, 4, 3, 10] with norder=10 in quadgsqrt and tol=1e-12 in quadlsqrt . Output from the program for this data case appears as comments at lines 14 thru 35 of sqrtquadtest. The integrators apparently work well and give results agreeing to Þfteen digits. How- ever, quadlsqrt took more than four hundred times as long to run as quadgsqrt. Furthermore, the structure of quadgsqrt is such that it could easily be modiÞed to accommodate a form of f(x) which returns a vector. 5.8.1 Program Listing Singular Integral Program 1: function [vg,tg,vL,tL,pctdiff]=sqrtquadtest © 2003 by CRC Press LLC GAUSS INTEGRATION WITH GEOMETRIC PROPERTY APPLICATIONS 191 2: % 3: % [vg,tg,vL,tL,pctdiff]=sqrtquadtest 4: %~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 5: % This function compares the accuracy and 6: % computation time for functions quadgsqrt 7: % and quadlsqrt to evaluate: 8: % integral(exp(u*x)*cos(v*x)/radical(x), a<x<b) 9: % where radical(x) is sqrt(x-a), sqrt(b-x), or 10: % sqrt((x-a)*(b-x)) 11: 12: % 13: % Program Output 14: 15: % >> sqrtquadtest; 16: 17: % EVALUATING INTEGRALS WITH SQUARE ROOT TYPE 18: % SINGULARITIES AT THE END POINTS 19: 20: % Function integrated: 21: % ftest(x,u,v)=exp(u*x).*cos(v*x) 22: 23: %a=1 b=4 24: %u=3 v=10 25: 26: % Results from function gquadsqrt 27: % 4.836504484e+003 -8.060993912e+003 -4.264510048e+003 28: % Computation time = 0.0159 sec. 29: 30: % Results from function quadlsqrt 31: % 4.836504484e+003 -8.060993912e+003 -4.264510048e+003 32: % Computation time = 7.03 sec. 33: 34: % Percent difference for the two methods 35: % -3.6669e-012 -1.5344e-012 1.4929e-012 36: %>> 37: 38: % 39: 40: % The test function 41: ftest=inline(’exp(u*x).*cos(v*x)’,’x’,’u’,’v’); 42: 43: % Limits and function parameters 44: a=1; b=4; u=3; v=10; 45: 46: nloop=100; tic; © 2003 by CRC Press LLC 192 ADVANCED MATH AND MECHANICS APPLICATIONS USING MATLAB 47: for j=1:nloop 48: v1g=quadgsqrt(ftest,1,a,b,40,1,u,v); 49: v2g=quadgsqrt(ftest,2,a,b,40,1,u,v); 50: v3g=quadgsqrt(ftest,3,a,b,40,1,u,v); 51: end 52: vg=[v1g,v2g,v3g]; tg=toc/nloop; 53: disp(’ ’) 54: disp(’EVALUATING INTEGRALS WITH SQUARE ROOT TYPE’) 55: disp(’ SINGULARITIES AT THE END POINTS’) 56: disp(’ ’) 57: disp(’Function integrated:’) 58: disp(’ftest(x,u,v)=exp(u*x).*cos(v*x)’) 59: disp(’ ’) 60: disp([’a = ’,num2str(a),’ b = ’,num2str(b)]) 61: disp([’u = ’,num2str(u),’ v = ’,num2str(v)]) 62: disp(’ ’) 63: disp(’Results from function gquadsqrt’) 64: fprintf(’%17.9e %17.9e %17.9e\n’,vg) 65: disp([’Computation time = ’,num2str(tg),’ sec.’]) 66: 67: tol=1e-12; tic; 68: v1L=quadlsqrt(ftest,1,a,b,tol,[],u,v); 69: v2L=quadlsqrt(ftest,2,a,b,tol,[],u,v); 70: v3L=quadlsqrt(ftest,3,a,b,tol,[],u,v); 71: vL=[v1L,v2L,v3L]; tL=toc; 72: 73: disp(’ ’) 74: disp(’Results from function quadlsqrt’) 75: fprintf(’%17.9e %17.9e %17.9e\n’,vL) 76: disp([’Computation time = ’,num2str(tL),’ sec.’]) 77: 78: pctdiff=100*(vg-vL)./vL; disp(’ ’) 79: disp(’Percent difference for the two methods’) 80: fprintf(’%13.4e %12.4e %12.4e\n’,pctdiff) 81: 82: %========================================= 83: 84: function v=quadgsqrt( 85: func,type,a,b,norder,nsegs,varargin) 86: % 87: % v=quadgsqrt(func,type,a,b,norder,nsegs,varargin) 88: % 89: %~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 90: % 91: % This function evaluates an integral having a © 2003 by CRC Press LLC GAUSS INTEGRATION WITH GEOMETRIC PROPERTY APPLICATIONS 193 92: % square root type singularity at one or both ends 93: % of the integration interval a<x<b. Composite 94: % Gauss integration is used with func(x) treated 95: % as a polynomial of degree norder. 96: % The integrand has the form: 97: % func(x)/sqrt(x-a) if type==1. 98: % func(x)/sqrt(b-x) if type==2. 99: % func(x)/sqrt((x-a)*(b-x)) if type==3. 100: % The integration interval is subdivided into 101: % nsegs subintervals of equal length. 102: % 103: % func - a character string or function handle 104: % naming a function continuous in the 105: % interval from x=a to x=b 106: % type - 1 if the integrand is singular at x=a 107: % 2 if the integrand is singular at x=b 108: % 3 if the integrand is singular at both 109: % x=a and x=b. 110: % a,b - integration limits with b>a 111: % norder - polynomial interpolation order within 112: % each interval. Lowest norder is 20. 113: % nsegs - number of integration subintervals 114: % 115: % User m functions called: gcquad 116: % 117: % Reference: Abromowitz and Stegun, ’Handbook of 118: % Mathematical Functions’, Chapter 25 119: % 120: 121: if nargin<6, nsegs=1; end; 122: if nargin<5, norder=50; end 123: switch type 124: case 1 % Singularity at the left end. 125: % Use Gauss quadrature 126: [dumy,bp,wf]=gcquad( 127: ’’,0,sqrt(b-a),norder+1,nsegs); 128: t=a+bp.^2; y=feval(func,t,varargin{:}); 129: v=wf(:)’*y(:)*2; 130: case 2 % Singularity at the right end. 131: % Use Gauss quadrature 132: [dumy,bp,wf]=gcquad( 133: ’’,0,sqrt(b-a),norder+1,nsegs); 134: t=b-bp.^2; y=feval(func,t,varargin{:}); 135: v=wf(:)’*y(:)*2; 136: case 3 % Singularity at both ends. © 2003 by CRC Press LLC [...]... tmin and tmax % ybase - piecewise linearly interpolated % base motion % % User m functions called: lintrp % 1 24: 125: 126: 127: 128: 129: 130: 131: 132: 133: 1 34: 135: 136: 137: 138: 139: 140 : 141 : 142 : 143 : 144 : tft=[ 0.00 1.26 2. 64 4.01 5.79 7. 74; 8.65 9. 74 13.06 15.07 21.60 25 .49 ; 31.56 34. 94 36.66 38.03 41 .87; 48 .40 51. 04 53.80 0 0 0 ]’; yft=[ 0 0.92 -0.25 1.00 0 .46 -0.16;...1 94 ADVANCED MATH AND MECHANICS APPLICATIONS USING MATLAB % Use Chebyshev integration n=norder; bp=cos(pi/(2*n+2)*(1:2:2*n+1)); c1=(b+a)/2; c2=(b-a)/2; t=c1+c2*bp; y=feval(func,t,varargin{:}); v=pi/(n+1)*sum(y); 137: 138: 139: 140 : 141 : 142 : end 143 : 144 : %========================================= 145 : 146 : 147 : 148 : 149 : 150: 151: 152: 153: 1 54: 155: 156: 157: 158: 159: 160: 161: 162: 163: 1 64: 165:... LLC 197 198 ADVANCED MATH AND MECHANICS APPLICATIONS USING MATLAB 41 : 42 : 43 : 44 : 45 : 46 : 47 : 48 : 49 : 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: % The approximation produced from a 20 point % Gauss formula is accurate within 007 percent % % f - a function f(x,y,z) which must return % a vector value when x is a vector, % and y and z are scalar % a1,a2... ADVANCED MATH AND MECHANICS APPLICATIONS USING MATLAB 131: 132: x=-sqrt(1-y.^2-z.^2); 133: 1 34: %============================================= 135: 136: 137: 138: 139: 140 : 141 : function x=as2(y,z) % % x=as2(y,z) % ~~~~~~~~~~ % Upper x integration limit % 142 : 143 : x=sqrt(1-y.^2-z.^2); 144 : 145 : %============================================= 146 : 147 : 148 : 149 : 150: 151: 152:... max(n) < 30 and % max(z) < 30, nft=256 gives about % ten digit accuracy % J - a matrix of values for the integer © 2003 by CRC Press LLC 41 : 42 : 43 : 44 : 45 : 46 : 47 : 48 : % order Bessel function of the first % kind Row position matches orders % defined by n, and column position % corresponds to arguments defined by % components of z % % User m functions called: none % 49 : 50: 51:... 20-Term Fourier Series’) figure(gcf); disp(’Press [Enter] to continue’); dumy=input(’’,’s’); % print -deps 20trmplt 34: 35: 36: % Show how magnitudes of Fourier coefficients % decrease with increasing harmonic order 37: 38: 39: 40 : 41 : 42 : 43 : 44 : 45 : 46 : fcof=fft(imptp((0:1023)/10 24, 1))/10 24; clf; plot(abs(fcof(1:100))); xlabel(’harmonic order’); ylabel(’coefficient magnitude’); title([’Coefficient Magnitude... 0.92 -0.25 1.00 0 .46 -0.16; -0.97 -0 .49 0.95 0.86 -0.76 0.85; 0.36 -0.52 -0.38 0.02 0.08; -0.26 0. 24 0.00 0 0 0 ]’; tft=tft(:); yft=yft(:); tft=tft(1: 24) ; yft=yft(1: 24) ; if nargin == 2 tft=tft*period/max(tft); end ybase=lintrp(tft,yft,t); 5.10 10.77 27.38 40 .67 0 -0.29 -0.83 -0.55 -0.19 0 145 : 146 : %============================================= 147 : 148 : 149 : 150: 151: 152: function [t,ys,ys0,vs0,as]=... unitized displacement 0 .4 0.2 0 −0.2 −0 .4 −0.6 −0.8 −1 0 10 20 30 time, seconds 40 50 Figure 6 .4: Result from a 20-Term Fourier Series © 2003 by CRC Press LLC 60 Coefficient Magnitude in Base Motion Expansion 0.16 0. 14 coefficient magnitude 0.12 0.1 0.08 0.06 0. 04 0.02 0 0 10 20 30 40 50 60 harmonic order 70 80 90 100 Figure 6.5: CoefÞcient Magnitude in Base Motion Expansion Total and Homogeneous Response... and z, b1 % and b2 are functions of z, and c is a vector % containing constant limits on the z variable % Hence, as many as five external functions may % be involved in the call list For example, % when the integrand and limits are: % % f = x.^2+y^2+z^2 % a2 = sqrt (4- y^2-z^2) % a1 = -a2 % b2 = sqrt (4- z^2) % b1 = -b2 % c = [-2,2] % % Then the exact value is 128*pi/5 © 2003 by CRC Press LLC 197 198 ADVANCED. .. can be changed into one with constant limits by the substitutions z = cp + cm u , −1 ≤ u ≤ 1, y = bp + bm t , −1 ≤ t ≤ 1, x = ap + am s , −1 ≤ s ≤ 1 © 2003 by CRC Press LLC 196 ADVANCED MATH AND MECHANICS APPLICATIONS USING MATLAB where c2 + c1 c2 − c1 , cm = , 2 2 b2 + b1 b2 − b1 , bm = , bp = 2 2 a2 + a1 a2 − a1 , am = ap = 2 2 cp = The above integral becomes 1 1 1 −1 −1 −1 I= cm bm am f (s, t, . LLC 192 ADVANCED MATH AND MECHANICS APPLICATIONS USING MATLAB 47 : for j=1:nloop 48 : v1g=quadgsqrt(ftest,1,a,b ,40 ,1,u,v); 49 : v2g=quadgsqrt(ftest,2,a,b ,40 ,1,u,v); 50: v3g=quadgsqrt(ftest,3,a,b ,40 ,1,u,v); 51:. quadlsqrt 31: % 4. 8365 044 84e+003 -8.060993912e+003 -4. 2 645 10 048 e+003 32: % Computation time = 7.03 sec. 33: 34: % Percent difference for the two methods 35: % -3.6669e-012 -1.5 344 e-012 1 .49 29e-012 36:. Press LLC 198 ADVANCED MATH AND MECHANICS APPLICATIONS USING MATLAB 41 : % The approximation produced from a 20 point 42 : % Gauss formula is accurate within .007 percent. 43 : % 44 : % f - a function

Ngày đăng: 08/08/2014, 11:21

TỪ KHÓA LIÊN QUAN