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

Advanced Mathematics and Mechanics Applications Using MATLAB phần 2 ppt

61 249 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,4 MB

Nội dung

176: R2=[real(u2);imag(u2);z2]; 177: 178: % Get curve properties from crvprp3d 179: [T,N,B,kappa]=crvprp3d(R1,R2); 180: 181: %============================================== 182: 183: function val=splined(xd,yd,x,if2) 184: % 185: % val=splined(xd,yd,x,if2) 186: % ~~~~~~~~~~~~~~~~~~~~~~~~ 187: % 188: % This function evaluates the first or second 189: % derivative of the piecewise cubic 190: % interpolation curve defined by the intrinsic 191: % function spline provided in MATLAB.If fewer 192: % than four data points are input, then simple 193: % polynomial interpolation is employed 194: % 195: % xd,yd - data vectors determining the spline 196: % curve produced by function spline 197: % x - vector of values where the first or 198: % the second derivative are desired 199: % if2 - a parameter which is input only if 200: % y’’(x) is required. Otherwise, y’(x) 201: % is returned. 202: % 203: % val - the first or second derivative values 204: % for the spline 205: % 206: % User m functions called: none 207: 208: n=length(xd); [b,c]=unmkpp(spline(xd,yd)); 209: if n>3 % Use a cubic spline 210: if nargin==3, c=[3*c(:,1),2*c(:,2),c(:,3)]; 211: else, c=[6*c(:,1),2*c(:,2)]; end 212: val=ppval(mkpp(b,c),x); 213: else % Use a simple polynomial 214: c=polyder(polyfit(xd(:),yd(:),n-1)); 215: if nargin==4, c=polyder(c); end 216: val=polyval(c,x); 217: end 218: 219: %================================================= 220: © 2003 by CRC Press LLC 221: % function range=cubrange(xyz,ovrsiz) 222: % See Appendix B 2.8.2 Surface Properties Surfaces are two-dimensional regions described parametrically as R(u, v)= ˆ ıx(u, v)+ ˆ u(u, v)+ ˆ kz(u, v) where u and v are scalar parameters. This parametric form is helpful for generating a grid of points on the surface as well as for computing surface tangents and the surface normal. Holding v Þxed while u varies generates a curve in the surface called a u coordinate line. A tangent vector to the u-line is given by g u = ∂R ∂u = ˆ ı ∂x ∂u + ˆ  ∂y ∂u + ˆ k ∂z ∂u . Similarly, holding u Þxed and varying v produces a v-line with tangent vector g v = ∂R ∂v = ˆ ı ∂x ∂v + ˆ  ∂y ∂v + ˆ k ∂z ∂v . Consider the following cross product. g u × g v du dv =ˆndS. In this equation ˆn is the unit surface normal and dS is the area of a parallelogram shaped surface element having sides deÞned by g u du and g v dv. The intrinsic functions surf(X,Y,Z) and mesh(X,Y,Z) depict surfaces by showing a grid network and related surface patches characterized when parameters u and v are varied over constant limits. Thus, values (u ı ,v  ) , 1 ≤ ı ≤ n, 1 ≤  ≤ m lead to matrices X =[x(u ı ,v  )] ,Y=[y(u ı ,v  )] ,Z=[z(u ı ,v  )] from which surface plots are obtained. Function surf colors the surface patches whereas mesh colors the grid lines. As a simple example, consider the ellipsoidal surface described parametrically as x = a cos θ cos φ, y= b cos θ sin φ, z= c sin θ where − π 2 ≤ θ ≤ π 2 , −π ≤ φ ≤ π. The surface equation evidently satisÞes the familiar equation  x a  2 +  y b  2 +  z c  2 =1 © 2003 by CRC Press LLC for an ellipsoid. The function elipsoid(a,b,c) called with a =2, b =1.5, c =1 produces the surface plot in Figure 2.18. Many types of surfaces can be parameterized in a manner similar to the ellipsoid. We will examine two more problems involving a torus and a conical frustum. Con- sider a circle of radius b lying in the xz-plane with its center at [a,0,0]. Rotating the circle about the z-axis produces a torus having the surface equation x =[a + b cos θ]cosφ, y=[a + b cos θ] , sin φ, z= b sin φ where −π ≤ θ ≤ π, −π ≤ φ ≤ π. This type of equation is used below in an example involving several bodies. Let us also produce a surface covering the ends and side of a conical frustum (a cone with the top cut off). The frustum has base radius r b , top radius r t , and height h, with the symmetry axis along the z-axis. The surface can be parameterized using an azimuthal angle θ and an arc length parameter relating to the axial direction. The lateral side length is r s =  h 2 +(r b − r t ) 2 . Let us take 0 ≤ s ≤ (r b + r s + r t ) and describe the surface R(s, θ) by coordinate functions x = r(s)cosθ, y= r(s)sinθ, z= z(s) where 0 ≤ θ ≤ 2π and r(s)=s, 0 ≤ s ≤ r b r(s)=r b + (r t − r b )(s −r b ) r s ,z= h(s − r b ) r s ,r b ≤ s ≤ (r b + r s ) r(s)=r b + r s + r t − r,z= h, (r b + r s ) ≤ s ≤ (r b + r s + r t ) . The function frus produces a grid of points on the surface in terms of r b , r t , h, the number of increments on the base, the number of increments on the side, and the number of increments on the top. Figure 2.16 shows the plot generated by frus. An example called srfex employs the ideas just discussed and illustrates how MATLAB represents several interesting surfaces. Points on the surface of an an- nulus symmetric about the z-axis are created, and two more annuli are created by interchanging axes. A pyramid with a square base is also created and the combina- tion of four surfaces is plotted by Þnding a data range to include all points and then plotting each surface in succession using the hold instruction (See Figure 2.16). Al- though the rendering of surface intersections is not perfect, a useful description of a fairly involved geometry results. Combined plotting of several intersecting surfaces is implemented in a general purpose function surfmany. The default data case for surfmany produces the six=legged geometry shown in Figure 2.17. This section is concluded with a discussion of how a set of coordinate points can be moved to a new position by translation and rotation of axes. Suppose a vector r = ˆ ıx + ˆ y + ˆ kz © 2003 by CRC Press LLC Spike and Intersecting Toruses Figure 2.16: Spike and Intersecting Toruses undergoes a coordinate change which moves the initial coordinate origin to (X o ,Y o ,Z o ) and moves the base vectors ˆ ı, ˆ , ˆ k into ˆe 1 , ˆe 2 , ˆe 3 . Then the endpoint of r passes to R = ˆ ıX + ˆ Y + ˆ kZ = R o +ˆe 1 x +ˆe 2 y +ˆe 3 z where R o = ˆ ıX o + ˆ Y o + ˆ kZ o . Let us specify the directions of the new base vectors by employing the columns of a matrix V where we take ˆe 3 = V (:, 1) norm[V (:, 1)] . If V (:, 2) exists we take V (:, 1) × V (:, 2) and unitize this vector to produce ˆe 2 . The triad is completed by taking ˆe 1 =ˆe 2 × ˆe 3 . In the event that V (:, 2) is not provided, we use [1;0;0] and proceed as before. The functions rgdbodmo and rotatran can be used to transform points in the manner described above. © 2003 by CRC Press LLC −5 0 5 −5 0 5 −8 −6 −4 −2 0 2 4 6 8 x axis SEVERAL SURFACES COMBINED y axis z axis Figure 2.17: Surface With Six Legs © 2003 by CRC Press LLC 2 2.5 3 3.5 4 3 3.5 4 4.5 5 4 4.5 5 5.5 6 x axis ROTATED AND TRANSLATED ELLIPSOID y axis z axis Figure 2.18: Rotated and Translated Ellipsoid Surfaces © 2003 by CRC Press LLC 2.8.3 Program Output and Code Function srfex 1: function [x1,y1,x2,y2,x3,y3,xf,yf,zf]= 2: srfex(da,na,df,nf) 3: % [x1,y1,x2,y2,x3,y3,xf,yf,zf]= 4: % srfex(da,na,df,nf) 5: % ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 6: % 7: % This graphics example draws three toruses 8: % intersecting a spike. 9: % 10: % User m functions called: frus, surfmany 11: 12: if nargin==0 13: da=[4.0,.45]; na=[42,15]; 14: df=[2.2,0,15]; nf=[43,4]; 15: end 16: 17: % Create a torus with polygonal cross section. 18: % Data for the torus is stored in da and na 19: 20: r0=da(1); r1=da(2); nfaces=na(1); nlat=na(2); 21: t=linspace(0,2*pi,nlat)’; 22: xz=[r0+r1*cos(t),r1*sin(t)]; 23: z1=xz(:,2); z1=z1(:,ones(1,nfaces+1)); 24: th=linspace(0,2*pi,nfaces+1); 25: x1=xz(:,1)*cos(th); y1=xz(:,1)*sin(th); 26: y2=x1; z2=y1; x2=z1; y3=x2; z3=y2; x3=z2; 27: 28: % Create a frustum of a pyramid. Data for the 29: % frustum is stored in df and nf 30: rb=df(1); rt=df(2); h=df(3); 31: [xf,yf,zf]=frus(rb,rt,h,nf); zf=zf 35*h; 32: 33: % Plot four figures combined together 34: hold off; clf; close; 35: surfmany(x1,y1,z1,x2,y2,z2,x3,y3,z3,xf,yf,zf) 36: xlabel(’x axis’); ylabel(’y axis’); 37: zlabel(’z axis’); 38: title(’Spike and Intersecting Toruses’); 39: axis equal; axis(’off’); 40: colormap([1 1 1]); figure(gcf); hold off; © 2003 by CRC Press LLC 41: % print -deps srfex 42: 43: %============================================= 44: 45: function [X,Y,Z]=frus(rb,rt,h,n,noplot) 46: % 47: % [X,Y,Z]=frus(rb,rt,h,n,noplot) 48: % ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 49: % 50: % This function computes points on the surface 51: % of a conical frustum which has its axis along 52: % the z axis. 53: % 54: % rb,rt,h - the base radius,top radius and 55: % height 56: % n - vector of two integers defining the 57: % axial and circumferential grid 58: % increments on the surface 59: % noplot - parameter input when no plot is 60: % desired 61: % 62: % X,Y,Z - points on the surface 63: % 64: % User m functions called: none 65: 66: if nargin==0 67: rb=2; rt=1; h=3; n=[23, 35]; 68: end 69: 70: th=linspace(0,2*pi,n(2)+1)’-pi/n(2); 71: sl=sqrt(h^2+(rb-rt)^2); s=sl+rb+rt; 72: m=ceil(n(1)/s*[rb,sl,rt]); 73: rbot=linspace(0,rb,m(1)); 74: rside=linspace(rb,rt,m(2)); 75: rtop=linspace(rt,0,m(3)); 76: r=[rbot,rside(2:end),rtop(2:end)]; 77: hbot=zeros(1,m(1)); 78: hside=linspace(0,h,m(2)); 79: htop=h*ones(1,m(3)); 80: H=[hbot,hside(2:end),htop(2:end)]; 81: Z=repmat(H,n(2)+1,1); 82: xy=exp(i*th)*r; X=real(xy); Y=imag(xy); 83: if nargin<5 84: surf(X,Y,Z); title(’Frustum’); xlabel(’x axis’) 85: ylabel(’y axis’), zlabel(’z axis’) © 2003 by CRC Press LLC 86: grid on, colormap([1 1 1]); 87: figure(gcf); 88: end 89: 90: %============================================= 91: 92: function surfmany(varargin) 93: %function surfmany(x1,y1,z1,x2,y2,z2, 94: % x3,y3,z3, ,xn,yn,zn) 95: % This function plots any number of surfaces 96: % on the same set of axes without shape 97: % distortion. When no input is given then a 98: % six-legged solid composed of spheres and 99: % cylinders is shown. 100: % 101: % User m functions called: none 102: % 103: 104: if nargin==0 105: % Default data for a six-legged solid 106: n=10; rs=.25; d=7; rs=2; rc=.75; 107: [xs,ys,zs]=sphere; [xc,yc,zc]=cylinder; 108: xs=rs*xs; ys=rs*ys; zs=rs*zs; 109: xc=rc*xc; yc=rc*yc; zc=2*d*zc-d; 110: x1=xs; y1=ys; z1=zs; 111: x2=zs+d; y2=ys; z2=xs; 112: x3=zs-d; y3=ys; z3=xs; 113: x4=xs; y4=zs-d; z4=ys; 114: x5=xs; y5=zs+d; z5=ys; 115: x6=xs; y6=ys; z6=zs+d; 116: x7=xs; y7=ys; z7=zs-d; 117: x8=xc; y8=yc; z8=zc; 118: x9=zc; y9=xc; z9=yc; 119: x10=yc; y10=zc; z10=xc; 120: varargin={x1,y1,z1,x2,y2,z2,x3,y3,z3, 121: x4,y4,z4,x5,y5,z5,x6,y6,z6,x7,y7,z7, 122: x8,y8,z8,x9,y9,z9,x10,y10,z10}; 123: end 124: 125: % Find the data range 126: n=length(varargin); 127: r=realmax*[1,-1,1,-1,1,-1]; 128: s=inline(’min([a;b])’,’a’,’b’); 129: b=inline(’max([a;b])’,’a’,’b’); 130: for k=1:3:n © 2003 by CRC Press LLC 131: x=varargin{k}; y=varargin{k+1}; 132: z=varargin{k+2}; 133: x=x(:); y=y(:); z=z(:); 134: r(1)=s(r(1),x); r(2)=b(r(2),x); 135: r(3)=s(r(3),y); r(4)=b(r(4),y); 136: r(5)=s(r(5),z); r(6)=b(r(6),z); 137: end 138: 139: % Plot each surface 140: hold off, newplot 141: for k=1:3:n 142: x=varargin{k}; y=varargin{k+1}; 143: z=varargin{k+2}; 144: surf(x,y,z); axis(r), hold on 145: end 146: 147: % Set axes and display the combined plot 148: axis equal, axis(r), grid on 149: xlabel(’x axis’), ylabel(’y axis’) 150: zlabel(’z axis’) 151: title(’SEVERAL SURFACES COMBINED’) 152: % colormap([127/255 1 212/255]); % aquamarine 153: colormap([1 1 1]);, figure(gcf), hold off Function rgdbodmo 1: function [X,Y,Z]=rgdbodmo(x,y,z,v,R0) 2: % 3: % [X,Y,Z]=rgdbodmo(x,y,z,v,R0) 4: % ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 5: % 6: % This function transforms coordinates x,y,z to 7: % new coordinates X,Y,Z by rotating and 8: % translating the reference frames. When no 9: % input is given, an example involving an 10: % ellipsoid is run. 11: % 12: % x,y,z - initial coordinate matrices referred 13: % to base vectors [1;0;0], [0;1;0] and 14: % [0;0;1]. Columns of v are used to 15: % create new basis vectors i,j,k such 16: % that a typical point [a;b;c] is 17: % transformed into [A;B;C] according 18: % to the equation © 2003 by CRC Press LLC [...]... (K − ω 2 M )X1 + ωCX2 = F1 , −ωCX1 + (K − ω 2 M )X2 = F2 The equivalent partitioned matrix is (K − ω 2 M ) ωC −ωC (K − ω 2 M ) X1 X2 = F1 F2 A simple MATLAB function to produce X 1 and X2 when M , C, K, F1 , F2 , and ω are known is function [x1,x2,xmax]=forcresp(m,c,k,f1,f2,w) kwm=k-(w*w)*m; wc=w*c; x=[kwm,wc;-wc,kwm]\[f1;f2]; n=length(f1); x1=x(1:n); x2=x(n+1 :2* n); xmax=sqrt(x1.*x1+x2.*x2); The... 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20 : 21 : 22 : 23 : 24 : 25 : 26 : 27 : 28 : 29 : 30: 31: 32: 33: 34: function [dfl,cof]=membran(h,np,ns,nx,ny) % [dfl,cof]=membran(h,np,ns,nx,ny) % ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ % This function computes the transverse % deflection of a uniformly tensioned membrane % which is subjected to uniform pressure The % membrane shape is a rectangle of width h and % height... = F1 cos(ωt) + F2 sin(ωt) ¨ ˙ where M , C, and K are constant matrices and F 1 and F2 are constant vectors The steady-state solution has the form x = X1 cos(ωt) + X2 sin(ωt) where X1 and X2 are chosen so that the differential equation is satisÞed Evidently x = −ωX1 sin(ωt) + ωX2 cos(ωt) ˙ and x = −ω 2 x ¨ Substituting the assumed form into the differential equation and comparing sine and cosine terms...19: 20 : 21 : 22 : 23 : 24 : 25 : 26 : 27 : 28 : 29 : 30: 31: % % % % % % % % % % % % % v R0 [A;B;C]=R0(:)+[i,j,k]*[a;b;c] - a matrix having three rows and either one or two columns used to construct the new basis [i,j,k] according to methods employed function rotatran - a vector which... disp(’Calculating’); 11: 12: 13: 14: 15: 16: % Set data for series term and boundary % condition points if nargin==0 nser=80; nf=100; ng=100; neval=500; end 17: 18: 19: % Compute the series coefficients [cof,y]=mbvp(’cos’,pi /2, nser,nf,ng,neval); 20 : 21 : 22 : 23 : 24 : 25 : % Evaluate the exact solution for comparison thp=linspace(0,pi,neval)’; y=cos(thp*(0:nser-1))*cof; ye=cos(thp)+sin(thp /2) .* sqrt (2* abs(cos(thp))).*(thp>=pi /2) ;... a reasonable method to handle the mixed boundary value problem © 20 03 by CRC Press LLC Mixed Boundary Value Problem Solution for 80 Terms 1 .2 Function value Solution Error 1 function value and error 0.8 0.6 0.4 0 .2 0 −0 .2 0 20 40 60 80 100 polar angle 120 140 160 Figure 3.3: Mixed Boundary Value Problem Solution © 20 03 by CRC Press LLC 180 MATLAB Example Program mbvprun 1: 2: 3: 4: 5: function mbvprun(nser,nf,ng,neval)... 0. 025 3 % 0.0489 0 .25 16 % 0 .25 95 0.1069 % 0.0945 0.01 02 % 0.0068 0.0001 41: 42: 43: 44: 45: 46: 47: 48: 49: % Generate a polar coordinate grid to describe % the mapping near the corner of the square % Then evaluate the mapping function r1=.95; r2=1; nr= 12; t1=.9*pi/4; t2=1.1*pi/4; nt=101; [r,th]=meshgrid(linspace(r1,r2,nr), linspace(t1,t2,nt)); z=r.*exp(i*th); w=z.*raterp(ctop,cbot,z.^4); 50: 51: 52: ... z=exp(i*linspace(0,pi/4,np)); w=sqmp(nsc,1,1,1,0,45,np); w=mean(real(w))+i*imag(w); z=[z,conj(z)]; w=[w,conj(w)]; 22 : 23 : 24 : 25 : 26 : % Compute the series coefficients for a % rational function fit to the boundary data [ctop,cbot]=ratcof(z.^4,w./z,ntop,nbot); ctop=real(ctop); cbot=real(cbot); 27 : 28 : 29 : 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: % The above calculations produce the following % coefficients % [top,bot]=... differential equation ∂2u ∂2u + 2 = −γ , (x,y) inside L ∂x2 ∂y where γ is a physical constant Properties of harmonic functions [18] imply that the differential equation is satisÞed by a series of the form n u=γ © 20 03 by CRC Press LLC −|z |2 + c real(z −1 ) 4 =1 Membrane Deflection 0.3 0 .25 deflection 0 .2 0.15 0.1 0.05 0 −0.05 1 0.5 0 −0.5 y axis −1 −0.8 −0.6 −0.4 −0 .2 0 0 .2 0.4 0.6 0.8 1 x axis... number of series terms used in % the numerator and the % denominator % % User m functions called: none % 124 : 125 : 126 : 127 : 128 : 129 : 130: 131: 1 32: 133: 134: ydata=ydata(:); xdata=xdata(:); m=length(ydata); if nargin==3, nbot=ntop; end; x=ones(m,ntop+nbot); x(:,ntop+1)=-ydata.*xdata; for i =2: ntop, x(:,i)=xdata.*x(:,i-1); end for i =2: nbot x(:,i+ntop)=xdata.*x(:,i+ntop-1); end . na 19: 20 : r0=da(1); r1=da (2) ; nfaces=na(1); nlat=na (2) ; 21 : t=linspace(0 ,2* pi,nlat)’; 22 : xz=[r0+r1*cos(t),r1*sin(t)]; 23 : z1=xz(: ,2) ; z1=z1(:,ones(1,nfaces+1)); 24 : th=linspace(0 ,2* pi,nfaces+1); 25 :. y1=xz(:,1)*sin(th); 26 : y2=x1; z2=y1; x2=z1; y3=x2; z3=y2; x3=z2; 27 : 28 : % Create a frustum of a pyramid. Data for the 29 : % frustum is stored in df and nf 30: rb=df(1); rt=df (2) ; h=df(3); 31:. z10=xc; 120 : varargin={x1,y1,z1,x2,y2,z2,x3,y3,z3, 121 : x4,y4,z4,x5,y5,z5,x6,y6,z6,x7,y7,z7, 122 : x8,y8,z8,x9,y9,z9,x10,y10,z10}; 123 : end 124 : 125 : % Find the data range 126 : n=length(varargin); 127 :

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

TỪ KHÓA LIÊN QUAN

w