Appendix AList of MATLAB Routines with Descriptions Table A.1: Description of MATLAB Programs and Selected Functions map-ping of a circular disk inside a square.. smdsolve 2 Function to
Trang 1148: num2str(dbest),’, CPU TIME = ’,
149: num2str(t),’ SECS’])
150: rotate3d on, shg, disp(’ ’)
151: disp(’Rotate the figure or press’)
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
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
Trang 2204: % This function plots the geometries
205: % pertaining to four data cases used
206: % to test closest proximity problems
207: % involving two circular cylinders
Trang 3243: hold off, subplot
244: % print -deps cylclose
253: % This function generates point grids on the
254: % surfaces of two circular cylinders and plots
255: % both cylinders together
Trang 4285: % surface of a circular cylinder
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
314: % v - vector of points in increasing order
Trang 5328: % This function generates a rotation matrix
329: % having v(:)/norm(v) as the third column
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: %
356: % epsx - convergence tolerance on x
357: % epsf - convergence tolerance on
361: % ifpr - when this parameter equals one,
364: % varargin - variable length list of parameters
366: % xmin - coordinates of the smallest
368: % fmin - smallest function value found
Trang 6375: % shrinkages performed
376: %
377: % User m functions called: objective function
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
396: alpha=1.0; % Reflection coefficient
397: beta= 0.5; % Contraction coefficient
398: gamma=2.0; % Expansion coefficient
406: % Exit if maximum allowable number of
407: % function values is exceeded
408: if m>M, xmin=x(:,1); fmin=f(1); return; end
Trang 7418: % Expand and take best from expansion
437: % Reflected point exceeds the second
438: % highest value so either use contraction
Trang 8482: % 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
490: % r,R - vectors containing the coordinates of the
Trang 9520: % 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
525: % r,R - vectors containing the coordinates of the
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);
Trang 10555: % xn,yn,zn)
556: % See Appendix B
Trang 11Appendix A
List of MATLAB Routines with Descriptions
Table A.1: Description of MATLAB Programs and Selected Functions
map-ping of a circular disk inside a square.
smdsolve 2 Function to solve a constant coefÞcient
linear second order differential tion with a harmonic forcing function.
string with given initial deßection.
Trang 12Routine Chapter Description
geome-try properties of a space curve.
curvprpsp 2 Function using spline interpolation to
compute differential properties of a space curve.
derivatives of a cubic spline.
of several surfaces.
frus-tum.
surfmany 2 Function to plot several functions
to-gether without distortion.
rgdbodmo 2 Program illustrating 3D rigid body
ro-tation and translation.
rota-tion.
membran 3 Program illustrating static deßection of
a membrane.
value problem for a circular disk.
of a square using rational functions.
rational function interpolation.
func-tion using coefÞcients from funcfunc-tion
raterp.
dy-namics equation using eigenvector methods.
or-der matrix differential equation having
a harmonic forcing function.
null and eig to compute rectangular
membrane frequencies.
continued on next page
Trang 13LIST OF MATLAB ROUTINES WITH DESCRIPTIONS 609
in-trinsic MATLAB matrix multiplication and slow Fortran style using loops.
interpo-lation allowing Þnite jump ities.
area bounded by a curve deÞned by spline interpolation.
interpo-lation coefÞcients used by function
spterp.
and integrate a cubic spline having general end conditions.
spterp.
splineq 4 Function to interpolate, integrate, and
differentiate using the intrinsic
func-tion spline.
used by splineg to handle general end
conditions.
MAT-LAB using a spline.
formulas.
formulas for derivatives of arbitrary der.
inte-grate an exact function or one deÞned
by spline interpolation.
integration of arbitrary order, and turn the base points and weight factors.
of gcquad and quadl for several test
functions.
continued on next page
Trang 14Routine Chapter Description
coordinates and inertial properties
of general areas bounded by spline curves.
prop-erties of general areas.
prop-erties of partial volumes of revolution bounded by spline curves.
prop-erties of partial volumes of revolution.
rotasurf 5 Function to plot a partial surface of
rev-olution.
computation to evaluate geometrical properties of a rope shaped solid.
ropedraw 5 Function to draw a twisted rope shaped
surface.
to obtain geometrical properties.
prop-erties of a solid speciÞed by general surface coordinates.
prop-erties and a surface plot of an arbitrary polyhedron.
polhedron 5 Function for geometrical properties of
a polyhedron.
a polygon.
evaluate integrals having square root type singularities at the integration end points.
quadqsqrt 5 Function applying gcquad to integrals
having square root type singularities.
having square root type singularities.
continued on next page
Trang 15LIST OF MATLAB ROUTINES WITH DESCRIPTIONS 611
evaluate a triple integral with variable integration limits.
order Bessel functions using the FFT.
earthquake data.
fouapprox 6 Function for Fourier series
approxima-tion of a general funcapproxima-tion.
se-ries expansions of general functions.
fousum 6 Function to sum a Fourier series and
in-clude coefÞcient smoothing.
analysis of a swinging cable.
re-sponse of a second order matrix ential equation with general initial con- ditions.
differ-strdynrk 7 Function using ode45 to solve a second
order matrix differential equation.
and fourth order integrators which use Þxed stepsize.
second order Þxed stepsize integrator.
a fourth order Þxed stepsize integrator.
Runge-Kutta integrators.
calculation of an inverted pendulum.
spinning top.
nonlin-ear dynamic response for a multi-link cable of rigid links.
continued on next page
Trang 16Routine Chapter Description
re-sponse of a cable.
dy-namics of an elastic cable shaken at both ends.
the Laplace equation in a rectangle having general boundary conditions.
func-tion and gradient components in a angular region.
rect-stringft 9 Program for Fourier series solution and
animated response for a string with given initial displacement.
sub-jected to a moving concentrated load.
rectangular or circular membrane jected to an oscillating concentrated force.
rectangular membrane.
memcirwv 9 Function for dynamic response of a
cir-cular membrane.
besjroot 9 Function to compute a table of integer
order Bessel function roots.
response.
a simply supported beam subjected to
an oscillating end moment.
beamanim 9 Function to animate the motion of a
vi-brating beam.
pilevibs 9 Program illustrating the response of a
pile embedded in an oscillating elastic foundation.
having sinusoidally varying end perature.
tem-continued on next page
Trang 17LIST OF MATLAB ROUTINES WITH DESCRIPTIONS 613
con-duction in a circular cylinder.
tempstdy 9 Function for the steady-state
tempera-ture in a circular cylinder with general boundary conditions.
Fourier-Bessel series.
besjtabl 9 Function giving a table of integer order
Bessel function roots.
in a beam of rectangular cross section.
a second order differential equation computed using Þnite difference meth- ods and using collocation with spline interpolation.
prnstres 10 Function to compute principal stresses
and principal directions for a ric second order stress tensor.
anima-tion of the natural vibraanima-tion modes of a general pin connected truss.
drawtruss 10 Function to draw the deßection modes
of a truss.
eigenvalue problem associated with
an elastic structure Þxed as selected points.
matrices of a pin connected truss.
a variable depth column with general end conditions.
natural frequencies computed by act, Þnite difference, and Þnite element methods.
ex-continued on next page
Trang 18Routine Chapter Description
beam frequencies.
frequencies using Þnite difference methods.
frequencies using the Þnite element method.
animation of the mode shapes of an liptic membrane.
el-frqsimpl 10 Function to compute elliptic membrane
natural frequencies and mode shapes.
eigenrec 10 Function to solve a rectangular
eigen-value problem of the form: XA +
BX = λ(XC + DX).
plotmode 10 Function to plot the mode shapes of the
membrane.
slope, and deßection in a variable depth multi-support beam with general external loading conditions.
defor-mation quantities for distributed and concentrated loading on a beam.
beam loads.
trapsum 11 Trapezoidal rule function used to
inte-grate beam functions.
sqrtsurf 12 Function used to illustrate branch cut
discontinuities for an analytic function.
map-ping the exterior of a circle onto the terior of an ellipse.
ex-elipdplt 12 Program showing grid lines for
confor-mal mapping of a circular disk onto an elliptic disk.
continued on next page
Trang 19LIST OF MATLAB ROUTINES WITH DESCRIPTIONS 615
elipdisk 12 Function mapping an elliptic disk onto
and straight lines under a linear tional transformation.
frac-ecentric 12 Function to determine a concentric
an-nulus which maps onto a given tric annulus.
eccen-swcsq10 12 Program illustrating both interior and
exterior maps regarding a circle and a square.
squarat 12 Rational function map taking the inside
of a circle onto the interior of a square
or the exterior of a square onto the terior of a square.
ex-swcsqmap 12 Function using truncated series
expan-sions in relation to circle to square maps.
in a circular disk for either Dirichlet or Neumann boundary conditions.
solve a mixed boundary value problem for a circular disk.
Cauchy integral.
elipcyl 12 Program illustrating inviscid ßuid ßow
about an elliptic cylinder in an inÞnite stream.
conformal mapping to compute sional stresses in a beam.
func-tions to compute stresses in a plate with
a circular hole.
continued on next page
Trang 20Routine Chapter Description
platecrc 12 Function computing series coefÞcients
for complex stress functions pertaining
to a plate with a circular hole.
phi and psi.
func-tions to evaluate Cartesian stress ponents.
compo-nents from Cartesian to polar nates.
complex stress functions to compute stress in a plate with an elliptic hole.
to optimize a projectile trajectory.
search to Þt a nonlinear equation to vibration response data.
static equilibrium of a loaded cable.
descent curve (brachistochrone).
search to Þnd the closest points on two adjacent circular cylinders.
Þnd the closest points on two surfaces.
implements the Nelder and Mead rithm for multi-dimensional search.
Trang 215: % This function performs animation of a 2D curve
6: % x,y - arrays with columns containing curve positions
11: % titl- title for the graph
12: % tim - the time in seconds between successive plots
13:
14: if nargin<5, trace=0; else, trace=1; end;
15: if nargin<4, tim=.05; end
16: if nargin<3, trac=’’; end; [np,nt]=size(y);
17: if min(size(x))==1, j=ones(1,nt); x=x(:);
18: else, j=1:nt; end; ax=newplot;
19: if trace, XOR=’none’; else, XOR=’xor’; end
Trang 221: function [p,zplot]=aprop(xd,yd,kn)
2: %
3: % [p,zplot]=aprop(xd,yd,kn)
4: % ~~~~~~~~~~~~~~~~~~~~~~~~~
5: % This function determines geometrical properties
6: % of a general plane area bounded by a spline
7: % curve
8: %
9: % xd,yd - data points for spline interpolation
13: % kn - vector of indices of points where the
17: % p - the vector [a,xcg,ycg,axx,axy,ayy]
22: % zplot - complex vector of boundary points for
Trang 235: % This function computes an array of positive roots
6: % of the integer order Bessel functions besselj of
7: % the first kind for various orders A chosen number
8: % of roots is computed for each order
9: % norder - a vector of function orders for which
12: % nrts - the number of positive roots computed for
14: % rts - an array of roots having length(norder)
18: % tol - error tolerance for root computation
Trang 241: function range=cubrange(xyz,ovrsiz)
2: %
3: % range=cubrange(xyz,ovrsiz)
4: % ~~~~~~~~~~~~~~~~~~~~~~~~~~
5: % This function determines limits for a square
6: % or cube shaped region for plotting data values
7: % in the columns of array xyz to an undistorted
8: % scale
9: %
10: % xyz - a matrix of the form [x,y] or [x,y,z]
13: % ovrsiz - a scale factor for increasing the
16: %
17: % range - a vector used by function axis to set
28: if nargin==1, ovrsiz=1; end
29: pmin=min(xyz); pmax=max(xyz); pm=(pmin+pmax)/2;
Trang 253: % [z,zplot,zp]=curve2d(xd,yd,kn,t)
4: %~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5: % This function generates a spline curve through
6: % given data points with corners (slope
dis-7: % continuities) allowed as selected points
8: % xd,yd - real data vectors of length nd
11: % kn - vectors of point indices, between one
14: % t - a vector of parameter values at which
22: % z - vector of points on the spline curve
24: % zplot - a complex vector of points suitable
26: % zp - first derivative of z with respect to
Trang 265: % This function solves the eigenvalue of the
6: % constrained eigenvalue problem
Trang 2711: %
18: %
19: % evecs - matrix of eigenvectors orthogonal
24: % eigvals - a vector of the eigenvalues
5: % This function uses eigenfunction analysis to solve
6: % the matrix differential equation
7: % m*y’’(t)+c*y’(t)+k*y(t)=f1*cos(w*t)+f2*sin(w*t)
8: % with initial conditions of y(0)=y0, y’(0)=v0
9: % The solution is general unless 1) a zero or repeated
Trang 2816: % f1,f2 - amplitude vectors for the sine and cosine
19: % tlim - a vector containing the minimum and
22: % nt - the number of times at which the solution
25: % y0,v0 - initial position and velocity vectors
26: %
30: % lam - the complex natural frequencies arranged
40: % Determine eigenvalues and eigenvectors for
41: % the homogeneous solution
42: A=[zeros(n,n), eye(n,n); -m\[k, c]];
43: [U,lam]=eig(A); [lam,j]=sort(diag(lam)); U=U(:,j);
44:
45: % Check for zero or repeated eigenvalues and
46: % for undamped resonance
47: wmin=abs(lam(1)); tol=wmin/1e6;
48: [dif,J]=min(abs(lam-i*w)); lj=num2str(lam(J));
49: if wmin==0, disp(’ ’)
50: disp(’The homogeneous equation has a zero’)
51: disp(’eigenvalue which is not allowed.’)
52: disp(’Execution is terminated’), disp(’ ’)
53: t=nan; y=nan; return
elseif any(abs(diff(lam))<tol)
Trang 2959: disp(’The system is undamped and the forcing’)
60: disp([’function resonates with ’,
81: waterfall(t,(1:n),y’), xlabel(’time axis’)
82: ylabel(’mass index’), zlabel(’Displacements’)
83: title([’DISPLACEMENT HISTORY FOR A ’,
5: % This function approximates the k’th derivative
6: % of a function using function values at n
7: % interpolation points Let f(x) be a general
8: % function having its k’th derivative denoted
Trang 3015: % error which decreases like h^m and
16: % TruncationError=(h^m)*(e(1)*F(x,n)+
17: % e(2)*F(x,n+1)*h+e(3)*F(x,n+2)*h^2+O(h^3))
18: %
19: % a - a vector of length n defining the
22: % k - order of derivative evaluated at x
23: % c - the weighting coeffients in the
26: % e - error component vector in the above
28: % m - order of truncation order in the
30: % crat - a matrix of integers such that c is
32:
33: a=a(:); n=length(a); m=n-k; mat=ones(n,n+4);
34: for j=2:n+4; mat(:,j)=a/(j-1).*mat(:,j-1); end
9: % This function integrates a general function using
10: % a composite Gauss formula of arbitrary order The
11: % integral value is returned along with base points
Trang 3116: % making nquad function evaluations Results are
17: % exact for polynomials of degree up to 2*nquad-1
18: % ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
26: % xlow,xhigh - integration limits
30: % varargin - variable length parameter used to
42: % gives value = 1.935685556078172e+040 which is
43: % accurate within an error of 1.9e-13 percent
44: %
45: % User m functions called: the function name passed
47:
48:
% -49:
50: if isempty(nquad), nquad=10; end
51: if isempty(mparts), mparts=1; end
52:
53: % Compute base points and weight factors
54: % for the single interval [-1,1] (Ref:
55: % ’Methods of Numerical Integration’ by
% P Davis and P Rabinowitz, page 93)
Trang 3263: % to apply for a composite interval
6: % This function views a surface from the top
7: % to show the coordinate lines of the surface
8: % It is useful for illustrating how coordinate
9: % lines distort in a conformal transformation
10: % Calling gridview with no arguments depicts the
11: % mapping of a polar coordinate grid map under
12: % a transformation of the form
13: % z=R*(zeta+m/zeta)
14: %
17: % xlabl,ylabl - labels for x and y axes
19: %
20: % User m functions called: cubrange
21:
Trang 3333: a=2; b=1; R=(a+b)/2; m=(a-b)/(a+b);
34: z=R*(zeta+m./zeta); x=real(z); y=imag(z);
35: titl=[’Circular Annulus Mapped onto an ’,
43: plot(x,y,’-k’); xlabel(xlabl); ylabel(ylabl);
44: title(titl); axis(’equal’); axis(range);
45: grid on; figure(gcf);
52: xlabel(xlabl); ylabel(ylabl); title(titl);
53: axis(’equal’); axis(range); grid on;