Advanced Mathematics and Mechanics Applications Using MATLAB phần 10 pdf

66 415 0
Advanced Mathematics and Mechanics Applications Using MATLAB phần 10 pdf

Đ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

148: num2str(dbest),’, CPU TIME = ’, 149: num2str(t),’ SECS’]) 150: rotate3d on, shg, disp(’ ’) 151: disp(’Rotate the figure or press’) 152: disp(’return to continue’) 153: dumy=input(’ ’,’s’); close 154: 155: end 156: 157: %=========================================== 158: 159: function r=cylpoint(w1,w2,r0,m,rdat,zdat) 160: % r=cylpoint(w1,w2,v,r0,m,rdat,zdat) 161: % ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 162: % This function computes the position of a 163: % point on the surface of a circular cylinder 164: % arbitrarily positioned in space. The argument 165: % list parameters have the following form, 166: % where rad means cylinder radius, and len 167: % means cylinder length. 168: % b=2*rad+len; 169: % zdat=[[0,0]; [rad/b, 0]; 170: % [(rad+len)/b, len];[ 1, len]]; 171: % rdat=zdat; rdat(2,2)=rad; 172: % rdat(3,2)=rad; rdat(4,2)=0; 173: 174: u=2*pi*sin(w1)^2; v=sin(w2)^2; 175: z=interp1(zdat(:,1),zdat(:,2),v); 176: rho=interp1(rdat(:,1),rdat(:,2),v); 177: x=rho*cos(u); y=rho*sin(u); 178: r=r0(:)+m*[x;y;z]; 179: 180: %=========================================== 181: 182: function dsqr=dcyl2cyl( 183: w,r0,m,rdat,zdat,R0,M,Rdat,Zdat) 184: %~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 185: % dsqr=dcyl2cyl(w,r0,m,rdat,zdat,R0,M,Rdat,Zdat) 186: % This function computes the square of the 187: % distance between generic points on the 188: % surfaces of two circular cylinders in three 189: % dimensions. 190: % 191: % User m functions called: cylpoint 192: © 2003 by CRC Press LLC 193: global fcount 194: fcount=fcount+1; 195: r=cylpoint(w(1),w(2),r0,m,rdat,zdat); 196: R=cylpoint(w(3),w(4),R0,M,Rdat,Zdat); 197: dsqr=norm(r-R)^2; 198: 199: %=========================================== 200: 201: function cylfigs 202: % cylfigs 203: % ~~~~~~~ 204: % This function plots the geometries 205: % pertaining to four data cases used 206: % to test closest proximity problems 207: % involving two circular cylinders 208: % 209: % User m functions called: plot2cyls 210: 211: w=rads; p=1:2; q=3:4; s=5:6; t=7:8; 212: 213: rad=1; len=3; r0=[4,0,0]; v=[0,0,1]; 214: Rad=1; Len=3; R0=[0,4,0]; V=[0,0,1]; 215: d=.4; subplot(2,2,1) 216: [x,y,z,X,Y,Z]=plot2cyls(rad,len,r0,v,Rad,Len, 217: R0,V,d,’CASE 1’); hold on 218: plot3(w(p,1),w(p,2),w(p,3),’linewidth’,2’) 219: hold off 220: 221: rad=1; len=3; r0=[4,0,0]; v=[3,0,4]; 222: Rad=1; Len=3; R0=[0,4,0]; V=[0,3,4]; 223: d=.4; subplot(2,2,2); 224: [x,y,z,X,Y,Z]=plot2cyls(rad,len,r0,v,Rad,Len, 225: R0,V,d,’CASE 2’); hold on 226: plot3(w(q,1),w(q,2),w(q,3),’linewidth’,2’) 227: hold off 228: 229: rad=1; len=5; r0=[4,0,0]; v=[-4,0,3]; 230: Rad=1; Len=5; R0=[0,4,0]; V=[0,0,1]; 231: d=.4; subplot(2,2,3) 232: [x,y,z,X,Y,Z]=plot2cyls(rad,len,r0,v,Rad,Len, 233: R0,V,d,’CASE 3’); hold on 234: plot3(w(s,1),w(s,2),w(s,3),’linewidth’,2’) 235: hold off 236: 237: rad=1; len=4*sqrt(2); r0=[4,0,0]; v=[-1,1,0]; © 2003 by CRC Press LLC 238: Rad=1; Len=3; R0=[0,0,-2]; V=[0,0,-1]; 239: d=.4; subplot(2,2,4); 240: [x,y,z,X,Y,Z]=plot2cyls(rad,len,r0,v,Rad,Len, 241: R0,V,d,’CASE 4’); hold on 242: plot3(w(t,1),w(t,2),w(t,3),’linewidth’,2’) 243: hold off, subplot 244: % print -deps cylclose 245: 246: %=========================================== 247: 248: function [x,y,z,X,Y,Z]=plot2cyls( 249: rad,len,r0,vc,Rad,Len,R0,Vc,d,titl) 250: % [x,y,z,X,Y,Z]=plot2cyls(rad,len,r0,vc,Rad, 251: % Len,R0,Vc,d,titl) 252: % ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 253: % This function generates point grids on the 254: % surfaces of two circular cylinders and plots 255: % both cylinders together 256: % 257: % User m functions called: cornrpts surfmany 258: % cylpts 259: if nargin==0 260: titl=’TWO CYLINDERS’; 261: rad=1; len=3; r0=[4,0,0]; vc=[3,0,4]; 262: Rad=1; Len=3; R0=[0,4,0]; Vc=[0,3,4]; d=.2; 263: end 264: if isempty(titl), titl=’ ’; end 265: u=2*rad+len; v=2*pi*rad; 266: nu=ceil(u/d); nv=ceil(v/d); 267: u=cornrpts([0,rad,rad+len,u],nu)/u; 268: v=linspace(0,1,nv); 269: [x,y,z]=cylpts(u,v,rad,len,r0,vc); 270: U=2*Rad+Len; V=2*pi*Rad; 271: Nu=ceil(U/d); Nv=ceil(V/d); 272: U=cornrpts([0,Rad,Rad+Len,U],Nu)/U; 273: V=linspace(0,1,Nv); 274: [X,Y,Z]=cylpts(U,V,Rad,Len,R0,Vc); 275: surfmany(x,y,z,X,Y,Z), title(titl) 276: colormap([1 1 0]), shg 277: 278: %=========================================== 279: 280: function [x,y,z]=cylpts( 281: axial,circum,rad,len,r0,vectax) 282: % [x,y,z]=cylpts(axial,circum,rad,len,r0,vectax) © 2003 by CRC Press LLC 283: % ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 284: % This function computes a grid of points on the 285: % surface of a circular cylinder 286: % 287: % User m functions called: ortbasis 288: 289: U=2*rad+len; u=U*axial(:); n=length(u); 290: v=2*pi*circum(:)’; m=length(v); 291: ud=[0,rad,rad+len,U]; 292: r=interp1(ud,[0,rad,rad,0],u); 293: z=interp1(ud,[0,0,len,len],u); 294: x=r*cos(v); y=r*sin(v); z=repmat(z,1,m); 295: % w=basis(vectax)*[x(:),y(:),z(:)]’; 296: w=ortbasis(vectax)*[x(:),y(:),z(:)]’; 297: 298: x=r0(1)+reshape(w(1,:),n,m); 299: y=r0(2)+reshape(w(2,:),n,m); 300: z=r0(3)+reshape(w(3,:),n,m); 301: 302: %=========================================== 303: 304: function v=cornrpts(u,N) 305: % v=cornrpts(u,N) 306: % ~~~~~~~~~~~~~~ 307: % This function generates approximately N 308: % points between min(u) and max(u) including 309: % all points in u plus additional points evenly 310: % spaced in each successive interval. 311: % u - vector of points 312: % N - approximate number of output points 313: % between min(u(:)) and max(u(:)) 314: % v - vector of points in increasing order 315: 316: u=sort(u(:))’; np=length(u); 317: d=u(np)-u(1); v=u(1); 318: for j=1:np-1 319: dj=u(j+1)-u(j); nj=max(1,fix(N*dj/d)); 320: v=[v,[u(j)+dj/nj*(1:nj)]]; 321: end 322: 323: %=========================================== 324: 325: function mat=ortbasis(v) 326: % mat=ortbasis(v) 327: % ~~~~~~~~~~~~~~ © 2003 by CRC Press LLC 328: % This function generates a rotation matrix 329: % having v(:)/norm(v) as the third column 330: 331: v=v(:)/norm(v); mat=[null(v’),v]; 332: if det(mat)<0, mat(:,1)=-mat(:,1); end 333: 334: %=========================================== 335: 336: function [xmin,fmin,m,ntype]=nelmed( 337: F,x0,dx,epsx,epsf,M,ifpr,varargin) 338: % [xmin,fmin,m,ntype]=nelmed( 339: % F,x0,dx,epsx,epsf,M,ifpr,varargin) 340: % ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 341: % This function performs multidimensional 342: % unconstrained function minimization using the 343: % direct search procedure developed by 344: % J. A. Nelder and R. Mead. The method is 345: % described in various books such as: 346: % ’Nonlinear Optimization’, by M. Avriel 347: % 348: % F - objective function of the form 349: % F(x,p1,p2, ) where x is vector 350: % in n space and p1,p2, are any 351: % auxiliary parameters needed to 352: % define F 353: % x0 - starting vector to initiate 354: % the search 355: % dx - initial polyhedron side length 356: % epsx - convergence tolerance on x 357: % epsf - convergence tolerance on 358: % function values 359: % M - function evaluation limit to 360: % terminate search 361: % ifpr - when this parameter equals one, 362: % different stages in the search 363: % are printed 364: % varargin - variable length list of parameters 365: % which can be passed to function F 366: % xmin - coordinates of the smallest 367: % function value 368: % fmin - smallest function value found 369: % m - total number of function 370: % evaluations made 371: % ntype - a vector containing 372: % [ninit,nrefl,nexpn,ncontr,nshrnk] © 2003 by CRC Press LLC 373: % which tells the number of reflect- 374: % ions, expansions, contractions,and 375: % shrinkages performed 376: % 377: % User m functions called: objective function 378: % named in the argument list 379: 380: if isempty(ifpr), ifpr=0; end 381: if isempty(M), M=500; end; 382: if isempty(epsf), epsf=1e-5; end 383: if isempty(epsx), epsx=1e-5; end 384: 385: % Initialize the simplex array 386: x0=x0(:); n=length(x0); N=n+1; f=zeros(1,N); 387: x=repmat(x0,1,N)+[zeros(n,1),dx*eye(n,n)]; 388: for k=1:N 389: f(k)=feval(F,x(:,k),varargin{:}); 390: end 391: 392: ninit=N; nrefl=0; nexpn=0; ncontr=0; 393: nshrnk=0; m=N; 394: 395: Erx=realmax; Erf=realmax; 396: alpha=1.0; % Reflection coefficient 397: beta= 0.5; % Contraction coefficient 398: gamma=2.0; % Expansion coefficient 399: 400: % Top of the minimization loop 401: 402: while Erx>epsx | Erf>epsf 403: 404: [f,k]=sort(f); x=x(:,k); 405: 406: % Exit if maximum allowable number of 407: % function values is exceeded 408: if m>M, xmin=x(:,1); fmin=f(1); return; end 409: 410: % Generate the reflected point and 411: % function value 412: c=sum(x(:,1:n),2)/n; xr=c+alpha*(c-x(:,N)); 413: fr=feval(F,xr,varargin{:}); m=m+1; 414: nrefl=nrefl+1; 415: if ifpr==1, fprintf(’ :RFL \n’); end 416: 417: if fr<f(1) © 2003 by CRC Press LLC 418: % Expand and take best from expansion 419: % or reflection 420: xe=c+gamma*(xr-c); 421: fe=feval(F,xe,varargin{:}); 422: m=m+1; nexpn=nexpn+1; 423: if ifpr==1, fprintf(’ :EXP \n’); end 424: 425: if fr<fe 426: % The reflected point was best 427: f(N)=fr; x(:,N)=xr; 428: else 429: % The expanded point was best 430: f(N)=fe; x(:,N)=xe; 431: end 432: 433: elseif fr<=f(n) % In the middle zone 434: f(N)=fr; x(:,N)=xr; 435: 436: else 437: % Reflected point exceeds the second 438: % highest value so either use contraction 439: % or shrinkage 440: if fr<f(N) 441: xx=xr; ff=fr; 442: else 443: xx=x(:,N); ff=f(N); 444: end 445: 446: xc=c+beta*(xx-c); 447: fc=feval(F,xc,varargin{:}); 448: m=m+1; ncontr=ncontr+1; 449: 450: if fc<=ff 451: % Accept the contracted value 452: x(:,N)=xc; f(N)=fc; 453: if ifpr==1, fprintf(’ :CNT \n’); end 454: 455: else 456: % Shrink the simplex toward 457: % the best point 458: x=(x+repmat(x(:,1),1,N))/2; 459: for j=2:N 460: f(j)=feval(F,x(:,j),varargin{:}); 461: end 462: m=m+n; nshrnk=nshrnk+n; © 2003 by CRC Press LLC 463: if ifpr==1, fprintf(’ :SHR \n’); end 464: end 465: end 466: 467: % Evaluate parameters to check convergence 468: favg=sum(f)/N; Erf=sqrt(sum((f-favg).^2)/n); 469: xcent=sum(x,2)/N; xdif=x-repmat(xcent,1,N); 470: Erx=max(sqrt(sum(xdif.^2))); 471: 472: end % Bottom of the optimization loop 473: 474: xmin=x(:,1); fmin=f(1); 475: ntype=[ninit,nrefl,nexpn,ncontr,nshrnk]; 476: 477: %================================================= 478: 479: function [d,r,R]=surf2surf(x,y,z,X,Y,Z,n) 480: % [d,r,R]=surf2surf(x,y,z,X,Y,Z,n) 481: % ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 482: % This function determines the closest points on two 483: % surfaces and the distance between these points. It 484: % is similar to function srf2srf except that large 485: % arrays can be processed. 486: % 487: % x,y,z - arrays of points on the first surface 488: % X,Y,Z - arrays of points on the second surface 489: % d - the minimum distance between the surfaces 490: % r,R - vectors containing the coordinates of the 491: % nearest points on the first and the 492: % second surface 493: % n - length of subvectors used to process the 494: % data arrays. Sending vectors of length 495: % n to srf2srf and taking the best of the 496: % subresults allows processing of large 497: % arrays of data points 498: % 499: % User m functions used: srf2srf 500: 501: if nargin<7, n=500; end 502: N=prod(size(x)); M=prod(size(X)); d=realmax; 503: kN=max(1,floor(N/n)); kM=max(1,floor(M/n)); 504: for i=1:kN 505: i1=1+(i-1)*n; i2=min(i1+n,N); i12=i1:i2; 506: xi=x(i12); yi=y(i12); zi=z(i12); 507: for j=1:kM © 2003 by CRC Press LLC 508: j1=1+(j-1)*n; j2=min(j1+n,M); j12=j1:j2; 509: [dij,rij,Rij]=srf2srf( 510: xi,yi,zi,X(j12),Y(j12),Z(j12)); 511: if dij<d, d=dij; r=rij; R=Rij; end 512: end 513: end 514: 515: %================================================= 516: 517: function [d,r,R]=srf2srf(x,y,z,X,Y,Z) 518: % [d,r,R]=srf2srf(x,y,z,X,Y,Z) 519: % ~~~~~~~~~~~~~~~~~~~~~~~~~~~ 520: % This function determines the closest points on two 521: % surfaces and the distance between these points. 522: % x,y,z - arrays of points on the first surface 523: % X,Y,Z - arrays of points on the second surface 524: % d - the minimum distance between the surfaces 525: % r,R - vectors containing the coordinates of the 526: % nearest points on the first and the 527: % second surface 528: 529: x=x(:); y=y(:); z=z(:); n=length(x); v=ones(n,1); 530: X=X(:)’; Y=Y(:)’; Z=Z(:)’; N=length(X); h=ones(1,N); 531: d2=(x(:,h)-X(v,:)).^2; d2=d2+(y(:,h)-Y(v,:)).^2; 532: d2=d2+(z(:,h)-Z(v,:)).^2; 533: [u,i]=min(d2); [d,j]=min(u); i=i(j); d=sqrt(d); 534: r=[x(i);y(i);z(i)]; R=[X(j);Y(j);Z(j)]; 535: 536: %================================================= 537: 538: function R=rads 539: % R=rads 540: % Radii for the problem solutions 541: 542: R=[ 543: 0.7045 3.2903 0.8263 544: 3.2932 0.7074 0.8295 545: 0.7783 3.4977 0.3767 546: 3.4994 0.7800 0.3755 547: 0.0026 3.0000 2.9934 548: 0.0028 1.0000 3.0001 549: 0.7034 0.7107 -2.0000 550: 1.5139 1.5320 -0.7382]; 551: 552: %================================================= © 2003 by CRC Press LLC 553: 554: % surfmany(x1,y1,z1,x2,y2,z2,x3,y3,z3, 555: % xn,yn,zn) 556: % See Appendix B © 2003 by CRC Press LLC [...]... spline interpolation Function to perform composite Gauss integration of arbitrary order, and return the base points and weight factors Program comparing the performance of gcquad and quadl for several test functions continued on next page © 2003 by CRC Press LLC 609 610 ADVANCED MATH AND MECHANICS APPLICATIONS USING MATLAB Routine areaprog Chapter 5 aprop 5 volrevol 5 volrev 5 rotasurf 5 ropesymu 5 ropedraw... and stiffness matrices of a pin connected truss Program to compute buckling loads of a variable depth column with general end conditions Program comparing cantilever beam natural frequencies computed by exact, Þnite difference, and Þnite element methods continued on next page © 2003 by CRC Press LLC 613 614 ADVANCED MATH AND MECHANICS APPLICATIONS USING MATLAB Routine cbfrqnwm Chapter 10 cbfrqfdm 10. .. a slab having sinusoidally varying end temperature continued on next page © 2003 by CRC Press LLC LIST OF MATLAB ROUTINES WITH DESCRIPTIONS Routine heatcyln Chapter 9 tempstdy 9 foubesco 9 besjtabl 9 rector 9 eigverr 10 prnstres 10 trusvibs 10 drawtruss 10 eigsym 10 elmstf 10 colbuc 10 cbfreq 10 Description Program analyzing transient heat conduction in a circular cylinder Function for the steady-state... 10 cbfrqfem 10 elipfreq 10 frqsimpl 10 eigenrec 10 plotmode 10 vdb 11 extload 11 sngf 11 trapsum 11 sqrtsurf 12 elipinvr 12 elipdplt 12 Description Function to compute exact cantilever beam frequencies Function to compute cantilever beam frequencies using Þnite difference methods Function to compute cantilever beam frequencies using the Þnite element method Program for natural frequencies and animation... functions spcof and spterp Function to interpolate, integrate, and differentiate using the intrinsic function spline Function that computes coefÞcients used by splineg to handle general end conditions Program that draws the word MATLAB using a spline Program to compute Þnite difference formulas Function to compute Þnite difference formulas for derivatives of arbitrary order Function using Simpson’s... next page © 2003 by CRC Press LLC 607 608 ADVANCED MATH AND MECHANICS APPLICATIONS USING MATLAB Routine splinerr Chapter 2 curvprpsp 2 splined 2 srfex 2 frus 2 surfmany 2 rgdbodmo 2 rotatran 2 membran 3 mbvprun 3 makratsq 3 ratcof 3 raterp 3 strdyneq 3 fhrmck 3 recmemfr 3 Description Program showing differential geometry properties of a space curve Function using spline interpolation to compute differential... 611 612 ADVANCED MATH AND MECHANICS APPLICATIONS USING MATLAB Routine plotmotn Chapter 8 sprchan 8 laplarec 9 recseris 9 stringft 9 forcmove 9 membwave 9 memrecwv 9 memcirwv 9 besjroot 9 membanim 9 bemimpac 9 beamanim 9 pilevibs 9 slabheat 9 Description Function to animate the dynamic response of a cable Program for animated nonlinear dynamics of an elastic cable shaken at both ends Program using Fourier... 616 ADVANCED MATH AND MECHANICS APPLICATIONS USING MATLAB Routine platecrc Chapter 12 strfun 12 cartstrs 12 rec2polr 12 elipmaxst 12 runtraj 13 vibÞt 13 cablsolv 13 brachist 13 cylclose 13 surf2surf 13 nelmed 13 © 2003 by CRC Press LLC Description Function computing series coefÞcients for complex stress functions pertaining to a plate with a circular hole Function to evaluate stress functions phi and. .. rectangular cross section Program comparing eigenvalues of a second order differential equation computed using Þnite difference methods and using collocation with spline interpolation Function to compute principal stresses and principal directions for a symmetric second order stress tensor Program to compute and show animation of the natural vibration modes of a general pin connected truss Function to draw... comparing execution of intrinsic MATLAB matrix multiplication and slow Fortran style using loops Function for piecewise linear interpolation allowing Þnite jump discontinuities Program to compute the length and area bounded by a curve deÞned by spline interpolation Function to compute spline interpolation coefÞcients used by function spterp Function to interpolate, differentiate, and integrate a cubic spline . difference, and Þnite element methods. continued on next page © 2003 by CRC Press LLC 614 ADVANCED MATH AND MECHANICS APPLICATIONS USING MATLAB Routine Chapter Description cbfrqnwm 10 Function. LLC 608 ADVANCED MATH AND MECHANICS APPLICATIONS USING MATLAB Routine Chapter Description splinerr 2 Program showing differential geome- try properties of a space curve. curvprpsp 2 Function using. multi-link cable of rigid links. continued on next page © 2003 by CRC Press LLC 612 ADVANCED MATH AND MECHANICS APPLICATIONS USING MATLAB Routine Chapter Description plotmotn 8 Function to animate the dynamic

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

Từ khóa liên quan

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan