close

Вход

Забыли?

вход по аккаунту

?

Advanced Mathematics & Mechanics Applications using MatLab. 3rd Ed. 2003

код для вставкиСкачать
Howard B. Wilson, Louis H. Turcotte, David Halpern
Mathematics and Mechanics Applications Using
MATLAB*
Howard B. Wilson Louis H. Turcotte David Halpern
Third Edition
OHAPMAN ft HALL/CRC
Advanced Mathematics and Mechanics Applications Using
MATLAB®
Third Edition
Howard B. Wilson
University of Alabama
Louis H. Turcotte
Rose-Hulman Institute of Technology
David Halpern
University of Alabama
•H
CHAPMAN & HALL/CRC
---------------------- A CRC Press Company ---------------------
Boca Raton London New York Washington, D.C.
Library of Congress Cataloging-in-Publication Data
Wilson, H.B.
Advanced mathematics and mechanics applications using MATLAB / Howard B. Wilson, Louis H. Turcotte, David Halpern.—3rd ed. p. cm.
ISBN 1-58488-262-X 1. MATLAB. 2. Engineering mathematics—Data processing. 3. Mechanics, Applied—Data processing. I. Turcotte, Louis H. II. Halpern, David. III. Title.
TA345 . W55 2002
620'.00151—dc21 2002071267
This book contains information obtained from authentic and highly regarded sources. Reprinted material is quoted with permission, and sources are indicated. A wide variety of references are listed. Reasonable efforts have been made to publish reliable data and information, but the author and the publisher cannot assume responsibility for the validity of all materials or for the consequences of their use.
Neither this book nor any part may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, microfilming, and recording, or by any information storage or retrieval system, without prior permission in writing from the publisher.
The consent of CRC Press LLC does not extend to copying for general distribution, for promotion, for creating new works, or for resale. Specific permission must be obtained in writing from CRC Press LLC for such copying.
Direct all inquiries to CRC Press LLC, 2000 N.W. Corporate Blvd., Boca Raton, Florida 33431.
Trademark Notice: Product or corporate names may be trademarks or registered trademarks, and are used only for identification and explanation, without intent to infringe.
Visit the CRC Press Web site at www.crcpress.com
© 2003 by Chapman & Hall/CRC
No claim to original U.S. Government works International Standard Book Number 1-58488-262-X Library of Congress Card Number 2002071267 Printed in the United States of America 1 2 3 4 5 6 7 8 9 0 Printed on acid-free paper
For my dear wife, Emma. Howard B. Wilson
For my loving wife, Evelyn, our departed cat, Patches, and my parents. Louis H. Turcotte
Preface
This book uses MATLAB*® to analyze various applications in mathematics and me­
chanics. The authors hope to encourage engineers and scientists to consider this modern programming environment as an excellent alternative to languages such as FORTRAN or C++. MATLAB1 embodies an interactive environment with a high level programming language supporting both numerical and graphical commands for two- and three-dimensional data analysis and presentation. The wealth of intrinsic mathematical commands to handle matrix algebra, Fourier series, differential equa­
tions, and complex-valued functions makes simple calculator operations of many tasks previously requiring subroutine libraries with cumbersome argument lists.
We analyze problems, drawn from our teaching and research interests, empha­
sizing linear and nonlinear differential equation methods. Linear partial differential equations and linear matrix differential equations are analyzed using eigenfunctions and series solutions. Several types of physical problems are considered. Among these are heat conduction, harmonic response of strings, membranes, beams, and trusses, geometrical properties of areas and volumes, flexure and buckling of inde­
terminate beams, elastostatic stress analysis, and multi-dimensional optimization.
Numerical integration of matrix differential equations is used in several examples illustrating the utility of such methods as well as essential aspects of numerical ap­
proximation. Attention is restricted to the Runge-Kutta method which is adequate to handle most situations. Space limitation led us to omit some interesting MATLAB features concerning predictor-corrector methods, stiff systems, and event locations.
This book is not an introductory numerical analysis text. It is most useful as a ref­
erence or a supplementary text in computationally oriented courses emphasizing ap­
plications. The authors have previously solved many of the examples in FORTRAN. Our MATLAB solutions consume over three hundred pages (over twelve thousand lines). Although few books published recently present this much code, comparable FORTRAN versions would probably be signifcantly longer. In fact, the conciseness of MATLAB was a primary motivation for writing the book.
The programs contain many comments and are intended for study as separate en­
tities without an additional reference. Consequently, some deliberate redundancy
1 MATLAB is a registered trademark of The MathWorks, Inc. For additional information contact:
The MathWorks, Inc.
3 Apple Hill Drive Natick, MA 01760-1500 (508) 647-7000, Fax: (508) 647-7001 Email: info@mathworks.com
exists between program comments and text discussions. We also list programs in a style we feel will be helpful to most readers. The source listings show line numbers adjacent to the MATLAB code. MATLAB code does not use line numbers or permit goto statements. We have numbered the lines to aid discussions of particular pro­
gram segments. To conserve space, we often place multiple MATLAB statements on the same line when this does not interrupt the logical flow.
All of the programs presented are designed to operate under the 6.x version of MATLAB and Microsoft Windows. Both the text and graphics windows should be simultaneously visible. A windowed environment is essential for using capabilities like animation and interactive manipulation of three dimensional figures. The source code for all of the programs in the book is available from the CRC Press website at h t t p://w w w.c r c p r e s s.c o m
. The program collection is organized using an independent subdirectory for each of the thirteen chapters.
This third edition incorporates much new material on time dependent solutions of linear partial differential equations. Animation is used whenever seeing the solution evolve in time is helpful. Animation illustrates quite well phenomena like wave propagation in strings and membranes. The interactive zoom and rotation features in MATLAB are also valuable tools for interpreting graphical output.
Most programs in the book are academic examples, but some problem solutions are useful as stand-alone analysis tools. Examples include geometrical property cal­
culation, differentiation or integration of splines, Gauss integration of arbitrary order, and frequency analysis of trusses and membranes.
A chapter on eigenvalue problems presents applications in stress analysis, elastic stability, and linear system dynamics. A chapter on analytic functions shows the efficiency of MATLAB for applying complex valued functions and the Fast Fourier Transform (FFT) to harmonic and biharmonic functions. Finally, the book concludes with a chapter applying multidimensional search to several nonlinear programming problems.
We emphasize that this book is primarily for those concerned with physical appli­
cations. A thorough grasp of Euclidean geometry, Newtonian mechanics, and some mathematics beyond calculus is essential to understand most of the topics. Finally, the authors enjoy interacting with students, teachers, and researchers applying ad­
vanced mathematics to real world problems.The availability of economical computer hardware and the friendly software interface in MATLAB makes computing increas­
ingly attractive to the entire technical community. If we manage to cultivate interest in MATLAB among engineers who only spend part of their time using computers, our primary goal will have been achieved.
Howard B. Wilson Louis H. Turcotte David Halpern
hwilson@bama.ua.edu
turcotte@rose-hulman.edu
david.halpern@ua.edu
Contents
1 Introduction
1.1 MATLAB: A Tool for Engineering Analysis
1.2 MATLAB Commands and Related Reference Materials
1.3 Example Problem on Financial Analysis
1.4 Computer Code and Results
1.4.1 Computer Output
1.4.2 Discussion of the MATLAB Code
1.4.3 Code for Financial Problem
2 Elementary Aspects of MATLAB Graphics
2.1
Introduction
2.2
Overview of Graphics
2.3
Example Comparing Polynomial and Spline Interpolation
2.4
Conformal Mapping Example
2.5
Nonlinear Motion of a Damped Pendulum
2.6
A Linear Vibration Model
2.7
Example of Waves in an Elastic String
2.8
Properties of Curves and Surfaces
2.8.1 Curve Properties
2.8.2 Surface Properties
2.8.3 Program Output and Code
3 Summary of Concepts from Linear Algebra
3.1 Introduction
3.2 Vectors, Norms, Linear Independence, and Rank
3.3 Systems of Linear Equations, Consistency, and Least Squares Ap­
proximation
3.4 Applications of Least Squares Approximation
3.4.1 A Membrane Deflection Problem
3.4.2 Mixed Boundary Value Problem for a Function Harmonic Inside a Circular Disk
3.4.3 Using Rational Functions to Conformally Map a Circular Disk onto a Square
3.5 Eigenvalue Problems
3.5.1 Statement of the Problem
3.5.2 Application to Solution of Matrix Differential Equations
3.5.3 The Structural Dynamics Equation
3.6 Computing Natural Frequencies for a Rectangular Membrane
3.7 Column Space, Null Space, Orthonormal Bases, and SVD
3.8 Computation Time to Run a MATLAB Program
4 Methods for Interpolation and Numerical Differentiation
4.1 Concepts of Interpolation
4.2 Interpolation, Differentiation, and Integration by Cubic Splines
4.2.1 Computing the Length and Area Bounded by a Curve
4.2.2 Example: Length and Enclosed Area for a Spline Curve
4.2.3 Generalizing the Intrinsic Spline Function in MATLAB
4.2.4 Example: A Spline Curve with Several Parts and Corners
4.3 Numerical Differentiation Using Finite Differences
4.3.1 Example: Program to Derive Difference Formulas
5 Gauss Integration with Geometric Property Applications
5.1 Fundamental Concepts and Intrinsic Integration Tools in MATLAB
5.2 Concepts of Gauss Integration
5.3 Comparing Results from Gauss Integration and Function QUADL
5.4 Geometrical Properties of Areas and Volumes
5.4.1 Area Property Program
5.4.2 Program Analyzing Volumes of Revolution
5.5 Computing Solid Properties Using Triangular Surface Elements and Using Symbolic Math
5.6 Numerical and Symbolic Results for the Example
5.7 Geometrical Properties of a Polyhedron
5.8 Evaluating Integrals Having Square Root Type Singularities
5.8.1 Program Listing
5.9 Gauss Integration of a Multiple Integral
5.9.1 Example: Evaluating a Multiple Integral
6 Fourier Series and the Fast Fourier Transform
6.1 Definitions and Computation of Fourier Coefficients
6.1.1 Trigonometric Interpolation and the Fast Fourier Transform
6.2 Some Applications
6.2.1 Using the FFT to Compute Integer Order Bessel Functions
6.2.2 Dynamic Response of a Mass on an Oscillating Foundation
6.2.3 General Program to Plot Fourier Expansions
7 Dynamic Response of Linear Second Order Systems
7.1 Solving the Structural Dynamics Equations for Periodic Forces
7.1.1 Application to Oscillations of a Vertically Suspended Cable
7.2 Direct Integration Methods
7.2.1 Example on Cable Response by Direct Integration
8 Integration of Nonlinear Initial Value Problems
8.1 General Concepts on Numerical Integration of Nonlinear Matrix Dif­
ferential Equations
8.2 Runge-Kutta Methods and the ODE45 Integrator Provided in MAT­
LAB
8.3 Step-size Limits Necessary to Maintain Numerical Stability
8.4 Discussion of Procedures to Maintain Accuracy by Varying Integra­
tion Step-size
8.5 Example on Forced Oscillations of an Inverted Pendulum
8.6 Dynamics of a SpinningTop
8.7 Motion of a Projectile
8.8 Example on Dynamics of a Chain with Specified End Motion
8.9 Dynamics of an Elastic Chain
9 Boundary Value Problems for Partial Differential Equations
9.1 Several Important Partial Differential Equations
9.2 Solving the Laplace Equation inside a Rectangular Region
9.3 The Vibrating String
9.4 Force Moving on an Elastic String
9.4.1 Computer Analysis
9.5 Waves in Rectangular or Circular Membranes
9.5.1 Computer Formulation
9.5.2 Input Data for Program membwave
9.6 Wave Propagation in a Beam with an Impact Moment Applied to One End
9.7 Forced Vibration of a Pile Embedded in an Elastic Medium
9.8 Transient Heat Conduction in a One-Dimensional Slab
9.9 Transient Heat Conduction in a Circular Cylinder with Spatially Vary­
ing Boundary Temperature
9.9.1 Problem Formulation
9.9.2 Computer Formulation
9.10 Torsional Stresses in a Beam of Rectangular Cross Section
10 Eigenvalue Problems and Applications
10.1 Introduction
10.2 Approximation Accuracy in a Simple Eigenvalue Problem
10.3 Stress Transformation and Principal Coordinates
10.3.1 Principal Stress Program
10.3.2 Principal Axes of the Inertia Tensor
10.4 Vibration of Truss Structures
10.4.1 Truss Vibration Program
10.5 Buckling of Axially Loaded Columns
10.5.1 Example for a Linearly Tapered Circular Cross Section
10.5.2 Numerical Results
10.6 Accuracy Comparison for Euler Beam Natural Frequencies by Finite Element and Finite Difference Methods
10.6.1 Mathematical Formulation
10.6.2 Discussion of the Code
10.6.3 Numerical Results
10.7 Vibration Modes of an Elliptic Membrane
10.7.1 Analytical Formulation
10.7.2 Computer Formulation
11 Bending Analysis of Beams of General Cross Section
11.1 Introduction
11.1.1 Analytical Formulation
11.1.2 Program to Analyze Beams of General Cross Section
11.1.3 Program Output and Code
12 Applications of Analytic Functions
12.1 Properties of Analytic Functions
12.2 Definition of Analyticity
12.3 Series Expansions
12.4 IntegralProperties
12.4.1 Cauchy Integral Formula
12.4.2 Residue Theorem
12.5 Physical Problems Leading to Analytic Functions
12.5.1 Steady-State Heat Conduction
12.5.2 Incompressible Inviscid Fluid Flow
12.5.3 Torsion and Flexure of Elastic Beams
12.5.4 Plane Elastostatics
12.5.5 Electric Field Intensity
12.6 Branch Points and Multivalued Behavior
12.7 Conformal Mapping and Harmonic Functions
12.8 Mapping onto the Exterior or the Interior of an Ellipse
12.8.1 Program Output and Code
12.9 Linear Fractional Transformations
12.9.1 Program Output and Code
12.10 Schwarz-Christoffel Mapping onto a Square
12.10.1 Program Output and Code
12.11 Determining Harmonic Functions in a Circular Disk
12.11.1 Numerical Results
12.11.2 Program Output and Code
12.12 Inviscid Fluid Flow around an Elliptic Cylinder
12.12.1 Program Output and Code
12.13 Torsional Stresses in a Beam Mapped onto a Unit Disk
12.13.1 Program Output and Code
12.14 Stress Analysis by the Kolosov-Muskhelishvili Method
12.14.1 Program Output and Code
12.14.2 Stressed Plate with an Elliptic Hole
12.14.3 Program Output and Code
13 Nonlinear Optimization Applications
13.1 Basic Concepts
13.2 Initial Angle for a Projectile
13.3 Fitting Nonlinear Equations to Data
13.4 NonlinearDeflections of a Cable
13.5 Quickest Time Descent Curve (the Brachistochrone)
13.6 Determining the Closest Points on Two Surfaces
13.6.1 Discussion of the Computer Code
A List of MATLAB Routines with Descriptions
B Selected Utility and Application Functions
References
Chapiter 1
Introduction
1.1 MATLAB: A Tool for Engineering Analysis
This book presents various MATLAB applications in mechanics and applied math­
ematics. Our objective is to employ numerical methods in examples emphasizing the appeal of MATLAB as a programming tool. The programs are intended for study as a primary component of the text. The numerical methods used include interpola­
tion, numerical integration, finite differences, linear algebra, Fourier analysis, roots of nonlinear equations, linear differential equations, nonlinear differential equations, linear partial differential equations, analytic functions, and optimization methods. Many intrinsic MATLAB functions are used along with some utility functions devel­
oped by the authors. The physical applications vary widely from solution of linear and nonlinear differential equations in mechanical system dynamics to geometrical property calculations for areas and volumes.
For many years FORTRAN has been the favorite programming language for solv­
ing mathematical and engineering problems on digital computers. An attractive al­
ternative is MATLAB which facilitates program development with excellent error diagnostics and code tracing capabilities. Matrices are handled efficiently with many intrinsic functions performing familiar linear algebra tasks. Advanced software fea­
tures such as dynamic memory allocation and interactive error tracing reduce the time to get solutions. The versatile but simple graphics commands in MATLAB also allow easy preparation of publication quality graphs and surface plots for technical papers and books. The authors have found that MATLAB programs are often signi- fantly shorter than corresponding FORTRAN versions. Consequently, more time is available for the primary purpose of computing, namely, to better understand physi­
cal system behavior.
The mathematical foundation needed to grasp most topics presented here is cov­
ered in an undergraduate engineering curriculum. This should include a grounding in calculus, differential equations, and knowledge of a procedure oriented programming language like FORTRAN. An additional course on advanced engineering mathemat­
ics covering linear algebra, matrix differential equations, and eigenfunction solutions of partial differential equations will also be valuable. The MATLAB programs were written primarily to serve as instructional examples in classes traditionally referred to as advanced engineering mathematics and applied numerical methods. The greatest benefit to the reader will probably be derived through study of the programs relat­
ing mainly to physics and engineering applications. Furthermore, we believe that several of the MATLAB functions are useful as general utilities. Typical examples include routines for spline interpolation, differentiation, and integration; area and inertial moments for general plane shapes; and volume and inertial properties of ar­
bitrary polyhedra. We have also included examples demonstrating natural frequency analysis and wave propagation in strings and membranes.
MATLAB is now employed in more than two thousand universities and the user community throughout the world numbers in the thousands. Continued growth will be fueled by decreasing hardware costs and more people familiar with advanced an­
alytical methods. The authors hope that our problem solutions will motivate analysts already comfortable with languages like FORTRAN to learn MATLAB. The rewards of such efforts can be considerable.
1.2 MATLAB Commands and Related Reference Materials
MATLAB has a rich command vocabulary covering most mathematical topics en­
countered in applications. The current section presents instructions on: a) how to learn MATLAB commands, b) how to examine and understand MATLAB’s lucidly written and easily accessible “demo” programs, and c) how to expand the command language by writing new functions and programs. A comprehensive online help sys­
tem is included and provides lengthy documentation of all the operators and com­
mands. Additional capabilities are provided by auxiliary toolboxes. The reader is encouraged to study the command summary to get a feeling for the language struc­
ture and to have an awareness of powerful operations such as null,orth,eig, and fft.
The manual for The Student Edition of MATLAB should be read thoroughly and kept handy for reference. Other references [47, 97, 103] also provide valuable sup­
plementary information. This book extends the standard MATLAB documentation to include additional examples which we believe are complementary to more basic instructional materials.
Learning to use help, type, dbtype, demo, and diary is important to understand­
ing MATLAB. help function_name (such as help plot) lists available documentation on a command or function generically called “function name.” MATLAB responds by printing introductory comments in the relevant function (comments are printed until the first blank line or first MATLAB command after the function heading is encountered). This feature allows users to create online help for their own functions by simply inserting appropriate comments at the top of the function. The instruction type function_name lists the entire source code for any function where source code is available (the code for intrinsic functions stored in compiled binary for computa­
tional efficiency cannot be listed). Consider the following list of typical examples
Command help help help demos type linspace
type plot intro
type intro
graf2d graf3d help diary
diary filename
d e mo
R e s u l t i n g Ac t i o n
d i s c u s s e s u s e o f t h e h e l p c o mma n d l i s t s n a me s o f va r i o u s d e mo p r o g r a ms l i s t s t h e s o u r c e c o d e f o r t h e f u n c t i o n wh i c h ge n e r a t e s a v e c ­
t o r o f e q u i d i s t a n t d a t a va l u e s
o ut p u t s a me s s a g e i n d i c a t i n g t h a t p l o t i s a b u i l t - i n f u n c t i o n e x e c u t e s t h e s o u r c e c o d e i n a f u n c t i o n n a me d i n t r o wh i c h i l l u s t r a t e s v a r i o u s MATLAB f u nc t i o ns. l i s t s t h e s o u r c e c o d e f o r t h e i n t r o d e mo p r o gr a m. By s t u d y ­
i n g t h i s e x a mp l e, r e a d e r s c a n q u i c k l y l e a r n ma n y MATLAB c o mma n d s
d e mo n s t r a t e s X- Y g r a p h i n g d e mo n s t r a t e s X- Y- Z g r a p h i n g
p r o v i d e s i n s t r u c t i o n s o n ho w r e s u l t s a p p e a r i n g o n t h e c o m­
ma n d s c r e e n c a n b e s a ve d i n t o a f i l e f o r l a t e r p r i n t i n g, e d i t ­
i n g, o r me r g i n g wi t h o t h e r t e x t
i n s t r u c t s MATLAB t o r e c o r d, i nt o a f i l e c a l l e d fil Jiame, all text appearing on the command screen until the user types diary off. The diary command is especially useful for making copies of library programs such as zerodemo initiates access to a lengthy set of programs demonstrating the functionality of MATLAB. It is also helpful to source list some of these programs such as: zerodemo, fitdemo, quaddemo, odedemo, ode45, fftdemo, and truss
1.3 Example Problem on Financial Analysis
Let us next analyze a problem showing several language constructs of MATLAB programming. Most of this book is devoted to solving initial value and boundary value problems for physical systems. For sake of variety we study briefly an elemen­
tary example useful in business, namely, asset growth resulting from compounded investment return.
The differential equation
Q'(t) = RQ(t) + S exp(At)
describes growth of investment capital earning a rate of investment return R and augmented by a saving rate S exp(At). The general solution of this first order linear equation is
Q(t) = exp(Rt)
τ
Q ( 0 ) + y S exp((A — R)t )dt
A realistic formulation should employ inflation adjusted capital defined by
q(t) = Q(t) exp(—It)
where I denotes the annual inflation rate. Then a suitable model describing capital accumulation over a saving interval of 11 years, followed by a payout period of 12 years, is characterized as
q'(t) = rq(t) + [s(t < ti) — pexp( —ati)(t > ti)] exp(at), q(0) = q0.
Th e q u a n t i t y (t < t 1) equals one for t < t 1 and is zero otherwise. This equation also uses inflation adjusted parameters r = R — I and a = A — I. The parameter s quantifies the initial saving rate and p is the payout rate starting at t = 11.
It is plausible to question whether continuous compounding is a reasonable alter­
native to a discrete model employing assumptions such as quarterly or yearly com­
pounding. It turns out that results obtained, for example, using discrete monthly compounding over several years differ little from those produced with the continuous model. Since long term rates of investment return and inflation are usually estimated rather than known exactly, the simplified formulas for continuous compounding il­
lustrate reasonably well the benefits of long term investment growth. Integrating the differential equation for the continuous compounding model gives
q(t) = q0 exp(rt) + s[h(t) — (t > t 1) exp(at 1)h(t — t 1)] — p (t > t 1) h(t — t 1)
wh e r e h(t) = [exp(rt) — exp(at)]/(r — a). The limiting case for r = a is also dealt with appropriately in the program below. At time T 2 = t 1 + t 2 the final capital
q2 = q(T2 ) is
s
q2 = qo exp(rT2) H [exp(rii) - exp(ati)] exp(rt2)
r — a
p
---------- [exp(rt2) — exp(at2)].
r —a
Therefore, for known r,a,t 1,t 2, the four quantities q2,q0,s,p are linearly related and any particular one of these values can be found in terms of the other three. For instance, when q0 = q2 = 0, the saving factor s needed to provide a desired payout factor p can be computed from the useful equation
s = p[\ — exp((a — r)t 2)]/[exp(^'t1) — exp(at1)]
A MATLAB program using the above equations was written to compute and plot q(t) for general combinations of the nine parameters R,A,I,t 1,t 2,q0,s,p,q2. The program allows data to be passed through the call list of function finance, or the interactive input is activated when no call list data is passed. Finance calls function inputv to read data and the function savespnd to evaluate q(t). First we will show some numerical results and then discuss selected parts of the code. Consider a case where someone initially starting with $10,000 of capital expects to save for 40 years
and subsequently draw $50,000 annually from savings for 20 years, at which time the remaining capital is to be $100,000. Assume that the investment rate before in­
flation is R = 8 while the inflation rate is I = 4. During the 60 year period, annual savings, as well as the pension payout amount, are to be increased to match inflation, so that A = 4. The necessary value of s and a plot of the inflation adjusted assets as a function of time are to be determined. The program output shows that when the unknown value of s was input as nan (meaning Not-a-Number in IEEE arithmetic), a corrected value of $6417 was computed. This says that, with the assumed rate of in­
vestment return, saving at an initial rate of $6417 per year and continually increasing that amount to match inflation will suffice to provide the desired inflation adjusted payout. Furthermore, the inflation adjusted financial capital accumulated at the end of 40 years is $733,272. The related graph of q(t) duplicates the data listed on the text screen. The reader may find it interesting to repeat the illustrative calculation assuming R = 11, in which case the saving coefficient is greatly reduced to only $1060.
1.4 Computer Code and Results
A computer code which analyzes the above equations and presents both numerical and graphical results appears next. First we show the program output, and then discuss particular aspects of the program.
1.4.1 Computer Output
>> f i n a n c e;
ANALYSIS OF THE SAVE-SPEND PROBLEM BY SOLVING q'( t ) = r * q ( t ) + [ s * ( t < = t 1 ) - p * ( t > t 1 ) * e x p ( - a * t 1 ) ] * e x p ( a * t ) where r =R- I, a=A- I, and q( 0) =q0
To l i s t p a r a me t e r d e f i n i t i o n s e n t e r y o t h e r w i s e e n t e r n ? y INPUT QUANTITIES:
R - a n n u a l p e r c e n t e a r n i n g s on a s s e t s
I - a n n u a l p e r c e n t i n f l a t i o n r a t e
A - a n n u a l p e r c e n t i n c r e a s e i n s a v i n g s
t o o f f s e t i n f l a t i o n r,a - i n f l a t i o n a d j u s t e d v a l u e s o f R and I
t 1 - s a v i n g p e r i o d ( y e a r s ), 0<t <t 1
t 2 - p a y o u t p e r i o d ( y e a r s ), t 1 < t < ( t 1 + t 2 )
s - s a v i n g r a t e a t t =0, ($K). S a v i n g i s
expressed as s*exp(a*t), 0<t<t1 p - p a y o u t r a t e a t t = t 1, ($K). P ayout i s
expressed as
-p*exp(a*(t-t1)), t1<t<(t1+t2) q0 - i n i t i a l s a v i n g s a t t =0, ($K)
q2 - f i n a l s a v i n g s a t t =T2=t 1+t 2, ($K)
OUTPUT QUANTI TI ES:
q - v e c t o r of i n f l a t i o n a d j u s t e d s a v i n g s v a l u e s f o r 0 <= t <= ( t 1+t 2)
t - v e c t o r of t i me s ( y e a r s ) c o r r e s p o n d i n g t o t h e component s of q q1 - v a l u e o f s a v i n g s a t t = t 1, when t h e s a v i n g p e r i o d ends
Press return to continue
I n p u t R,A,I ( t r y 1 1,4,4 ) ? 8,4,4 I n p u t t 1,t 2 ( t r y 40,20) ? 40,20
I n p u t q 0,s,p,q 2 ( t r y 2 0,5,n a n,4 0 ) ? 2 0,n a n,5 0,1 0 0
PROGRAM RESULTS t 1 t 2 R A I
40.000 20.000 8.000 4.000 4.
q0 q1 q2 s p
20.000 733.272 100.000 6.417 50.
000
0 0 0
>>
TOTAL SAVINGS IN $K
1.4.2 Discussion of the MATLAB Code
Let us examine the following program listing. The line numbers, which are not part of the actual code, are helpful for discussing particular parts of the program. A numbered listing can be obtained with the MATLAB command dbtype.
Line Comments
1-2 Three dot s... are used to continue function finance to handle the
long argument list. The output list duplicates some input items to handle cases involving interactive input.
3-16 Comment lines always begin with the % symbol. At the inter­
active command level in MATLAB, typing help followed by a function name will print documentation in the first unbroken se­
quence of comments in a function or script file.
20-25 The output heading is printed. Note that q”(t) is used to print q’(t)
because special characters such as ’ or % must be repeated.
29-50 Intrinsic function char is used to store descriptions of program
variable in a character matrix.
59 Function nargin checks whether the number of input variables is
zero. If so, data values are read interactively.
68-69 Function inputv reads several variables on the same line.
70-78 While 1,...,end code sequence loops repeatedly to check data in­
put. Break exits to line 80 if data are OK.
85-97 Set multiplier constants to solve for one unknown variable among
q0, s, p, q2.
99-105 Determine time vectors to evaluate the solution. Cases where tl
or t2 are zero require special treatment.
108-112 Intrinsic function isnan is used to identify the variable which was
input as nan.
115-116 User defined function savespnd is used to evaluate q(t) andq(t1).
119-127 Program results are printed with a chosen format. The statement
b=inline(’blanks(j)’,’j ’) just shortens the name for intrinsic func­
tion blanks.
130-139 Draw the graph along with a title and axis labels.
141-153 Create a label containing data values. Position it on the graph.
154 Turn the grid off and bring the graph to the foreground.
158-176 Function savespnd evaluates q(t). The formula for r=a results
from the limiting form of q(t) as parameter a tends to r.
180-213 Function inputv generalizes the intrinsic function input to read
several variables on the same line. Inputv is used often through­
out this text.
1.4.3 Code for Financial Problem Program finance
functi on [ q,t,R,A,I,t 1,t 2,s,p,q 0,q 1,q 2 ] = f i n a n c e..
( R,A,I,t 1,t 2,s,p,q 0,q 2 ) % [ q,t,R,A,I,t 1,t 2,s,p,q 0,q 1,q 2 ] = f i n a n c e...
% ( R,A,I,t 1,t 2,s,p,q 0,q 2 )
%....................................................................................................................
%
% T h i s f u n c t i o n s o l v e s t h e SAVE-SPEND PROBLEM % where f u n d s e a r n i n g i n t e r e s t a r e a c c u m u l a t e d % d u r i n g one p e r i o d and p a i d o u t i n a s u b s e q u e n t % p e r i o d. The v a l u e o f a s s e t s i s a d j u s t e d t o % a c c o u n t f o r i n f l a t i o n. T h i s p r o b l e m i s % g o v e r n e d by t h e d i f f e r e n t i a l e q u a t i o n % q'( t ) = r * q ( t ) + [ s * ( t < = t 1 )...
% - p * ( t > t 1 ) * e x p ( - a * t 1 ) ] * e x p ( a * t ) where
% r = R - I, a=A-I and t h e r e ma i n i n g p a r a m e t e r s % a r e d e f i n e d bel ow
% U s e r m f u n c t i o n s r e q u i r e d: i n p u t v, s a v e s p n d d i s p (' '), d i s p ( [' ',...
'ANALYSIS OF THE SAVE-SPEND PROBLEM BY SOLVING']) d i s p (...
['q''( t ) = r * q ( t ) + [ s * ( t < = t 1 ) - p * ( t > t 1 ) *',... 'e x p ( - a * t 1 ) ] * e x p ( a * t )'] ), d i s p (...
'wh e r e r = R - I, a =A- I, and q ( 0 ) = q 0'), d i s p (' ')
% C r e a t e a c h a r a c t e r v a r i a b l e c o n t a i n i n g % d e f i n i t i o n s o f i n p u t and o u t p u t q u a n t i t i e s e x p l a i n = c h a r ('I NP UT QUANTI TI ES:',...
R - a n n u a l p e r c e n t e a r n i n g s on a s s e t s',...
I - a n n u a l p e r c e n t i n f l a t i o n r a t e',...
A - a n n u a l p e r c e n t i n c r e a s e i n s a v i n g s',...
t o o f f s e t i n f l a t i o n',... r,a - i n f l a t i o n a d j u s t e d v a l u e s of R and I',... t 1 - s a v i n g p e r i o d ( y e a r s ), 0 < t < t 1',... t 2 - p a y o u t p e r i o d ( y e a r s ), t 1 < t < ( t 1 + t 2 )',... s - s a v i n g r a t e a t t = 0, ( $K). S a v i n g i s',...
e x p r e s s e d a s s * e x p ( a * t ), 0 < t < t 1',... p - p a y o u t r a t e a t t = t 1, ( $K). P a y o u t i s',... e x p r e s s e d a s',...
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:
74
75
76
77:
78
79
80:
81:
82
83:
84
85
' - p*e xp( a*( t - t 1) ), t 1 < t < ( t 1 + t 2 )',...
'q0 - i n i t i a l s a v i n g s a t t = 0, ( $ K )',...
'q 2 - f i n a l s a v i n g s a t t = T 2 = t 1 + t 2, ( $ K )',' ',...
'OUTPUT QUANTI TI ES:',...
'q - v e c t o r of i n f l a t i o n a d j u s t e d s a v i n g s',...
' v a l u e s f o r 0 <= t <= ( t 1 + t 2 )',...
't - v e c t o r of t i me s ( y e a r s ) c o r r e s p o n d i n g',...
' t o t h e components o f q',...
'q 1 - v a l u e o f s a v i n g s a t t = t 1, when t h e',...
' s a v i n g p e r i o d e n d s',' ');
% NOTE: WHEN R,I,A,T 1,T 2 ARE KNOWN,THEN FIXING % ANY THREE OF THE VALUES q 0,s,p,q 2 DETERMINES % THE UNKNOWN VALUE WHICH SHOULD BE GIVEN AS % n a n IN THE DATA INPUT.
% R e a d d a t a i n t e r a c t i v e l y when i n p u t d a t a i s n o t % p a s s e d t h r o u g h t h e c a l l l i s t i f n a r g i n = = 0
di sp('To l i s t p a r a m e t e r d e f i n i t i o n s e n t e r y') q u e r r y = i n p u t ('o t h e r w i s e e n t e r n ? ','s'); i f q u e r r y = ='Y' | q u e r r y = ='y'
d i s p ( e x p l a i n ); d i s p ('P r e s s r e t u r n t o c o n t i n u e')
p a u s e, d i s p (' ')
e n d
% R e a d m u l t i p l e v a r i a b l e s on t h e same l i n e
[ R,A,I ] = i n p u t v ('I n p u t R,A,I ( t r y 1 1,4,4 ) ? '); [ t 1,t 2 ] = i n p u t v ('I n p u t t 1,t 2 ( t r y 4 0,2 0 ) ? '); wh i l e 1
[ q 0,s,p,q 2 ] = i n p u t v (...
'I n p u t q 0,s,p,q 2 ( t r y 2 0,5,n a n,4 0 ) ? ');
i f s u m ( i s n a n ( [ q 0,s,p,q 2 ] ) ) = = 1, b r e a k; end f p r i n t f ( ['\n D A T A ERROR. ONE AND ONLY ',...
'ONE VALUE AMONG\n','THE PARAMETERS ',... 'q 0,s,p,q 2 CAN EQUAL n a n \n\n'] )
end
end
n t =1 0 1; T2 =t 1 +t 2; r = ( R - I )/1 0 0; a = ( A - I )/1 0 0; c 0 =e x p ( r * T2 );
% q 0,s,p,q 2 a r e r e l a t e d by q2=c0*q0+c1*s +c2*p % Check s p e c i a l c a s e where t 1 o r t 2 a r e z e r o i f t1==0
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
d i s p (' '), d i s p ('s i s s e t to zero when t 1 = 0') s =0; c1=0; e l s e
c 1 = s a v e s p n d ( T 2,t 1,0,R,A,I,1,0 );
end
i f t 2==0
d i s p (' '), d i s p ('p i s s e t t o z e r o when t 2 = 0') p=0; c2=0; e l s e
c 2 = s a v e s p n d ( T 2,t 1,0,R,A,I,0,1 ); end
i f t1==0 | t 2==0
t = l i n s p a c e ( 0,T 2,n t )';
e l s e
n 1 = m a x ( 2,f i x ( t 1/T 2 * n t ) ); n 2 = ma x ( 2,n t - n 1 ) - 1; t = [ t 1/n 1 * ( 0:n 1 ),t 1 + t 2/n 2 * ( 1:n 2 ) ]';
end
% S o l v e f o r t h e unknown p a r a m e t e r i f i s n a n ( q 0 ), q 0 = ( q 2 - s * c 1 - p * c 2 )/c 0 e l s e i f i s n a n ( s ), s = ( q 2 - q 0 * c 0 - p * c 2 )/c 1 e l s e i f i s n a n ( p ), p = ( q 2 - q 0 * c 0 - s * c 1 )/c 2 e l s e, q2=q0*c0+s *c1+p*c2;
e n d
% C o m p u t e r e s u l t s f o r q ( t )
q = s a v e s p n d ( t,t 1,q 0,R,A,I,s,p );
q 1 = s a v e s p n d ( t 1,t 1,q 0,R,A,I,s,p );
% P r i n t f o r m a t t e d r e s u l t s
b = i n l i n e ('b l a n k s ( j )','j'); B=b( 3); d ='% 8.3 f'; u = [ d,B,d,B,d,B,d,B,d,'\n']; d i s p (' ') di s p( [ b( 19),'PROGRAM RESULTS']) d i s p ( [' t 1 t 2 R',...
' A I'] )
f p r i n t f ( u,t 1,t 2,R,A,I ), d i s p (' ') d i s p ( [' q0 q1 q 2',...
' s p'] )
f p r i n t f ( u,q 0,q 1,q 2,s,p ), d i s p (' '), p a u s e ( 1 )
% Show r e s u l t s g r a p h i c a l l y p l o t ( t,q,'k')
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
title(['INFLATION ADJUSTED SAVINGS WHEN ',...
'S = ',n u m 2 s t r ( s ),' AND P = ',n u m 2 s t r ( p ) ] ); t i t l =...
['TOTAL SAVINGS WHEN T1 = ',n u m 2 s t r ( t 1 ),...
', T2 = ',n u m 2 s t r ( t 2 ),', s = ',n u m 2 s t r ( s ),... ', p = ',n u m 2 s t r ( p ) ]; t i t l e ( t i t l )
x l a b e l ('T I ME IN YEARS') y l a b e l ('TOTAL SAVINGS IN $K')
% C h a r a c t e r l a b e l showing d a t a p a r a m e t e r s l a b e l = c h a r (... s p r i n t f ('R = % 8.3 f',R ),... s p r i n t f ('I = % 8.3 f',I ),... s p r i n t f ('A = % 8.3 f',A ),... s p r i n t f ('q 0 = % 8.3 f',q 0 ),... s p r i n t f ('q 1 = % 8.3 f',q 1 ),... s p r i n t f ('q 2 = % 8.3 f',q 2 ) ); w=a xi s; ymi n=w( 3); dy =w( 4 ) - w( 3 ); xmi n=w( 1); dx =w( 2 ) - w( 1 ); y t o p=ymi n+.8*dy; Dy=.065*dy; x l f t = x mi n + 0.0 4 * d x; t e x t ( x l f t,y t o p,l a b e l ) g r i d o f f, s h g
%=============================================
functi on q=savespnd(t,t 1,q0,R,A,I,s,p)
%
% q=savespnd(t,t 1,q0,R,A,I,s,p)
%....................................................................................................................
% This function determines q( t ) s a t i s f y i n g % q'( t ) =r *q+[ s *( t < =t 1) - p*( t >t 1) *.. .
% exp(-a*t 1)]*exp(a*t ), with q(0)=q0,
% r=(R-I)/100; a=(A-I)/100
r=(R-I)/100; a=(A-I)/100; c=r-a; T=t-t1; i f r~=a
q=q 0 * e xp( r *t ) +s/c*( exp( r *t ) - exp( a *t ) )... -(p+s*exp(a*t1))/c*(T>0).* (... exp(r*T)-exp(a*T)); el s e % l i mi t i n g c a s e a s a=>r
q=q0*exp(r*t)+s*t.*exp(r*t) ...
-(p+s*exp(r*t1)).*T.*(T>0).*exp(r*T);
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
end
%==========================================
functi on varargout=inputv(prompt)
%
% [a1,a2,...,a_nargout ]=i nput v(prompt )
%............................................................................................................
%
% This function r e a d s s e v e r a l v a l u e s on one % l i n e. The i t e m s s h o u l d be s e p a r a t e d by % commas o r b l a n k s.
%
% p r o m p t - A s t r i n g p r e c e d i n g t h e
% d a t a e n t r y. I t i s s e t
% t o ' ? ' i f no v a l u e o f
% prompt i s g i v e n.
% a 1,a 2,...,a _ n a r g o u t - The o u t p u t v a r i a b l e s % t h a t a r e c r e a t e d. I f
% n o t enough d a t a v a l u e s
% a r e g i v e n f o l l o w i n g t h e
% p r o mp t, t h e r e m a i n i n g
% u n d e f i n e d v a l u e s a r e
% s e t e q u a l t o NaN
%
% A t y p i c a l f u n c t i o n c a l l i s:
% [ A,B,C,D ] = i n p u t v ('E n t e r v a l u e s of A,B,C,D: ') %
% ---------------------------------------------------------------------------------------
i f n a r g i n = = 0, p r o mp t =' ? end u = i n p u t ( p r o m p t,'s'); v = e v a l ( ['[',u,']'] ); n i = l e n g t h ( v ); n o = n a r g o u t; v a r a r g o u t = c e l l ( 1,n o ); k = m i n ( n i,n o ); f o r j = 1:k, v a r a r g o u t { j } = v ( j ); end i f no>ni
f o r j = n i + 1:n o, v a r a r g o u t { j } = n a n; end end
Chapiter 2
Elementary Aspects of MATLAB Graphics
2.1 Introduction
MATLAB’s capabilities for plotting curves and surfaces are versatile and easy to understand. In fact, the effort required to learn MATLAB would be rewarding even if it were only used to construct plots, save graphic images, and output publication quality graphs on a laser printer. Numerous help features and well-written demo pro­
grams are included with MATLAB. By executing the demo programs and studying the relevant code, users can quickly understand the techniques necessary to imple­
ment graphics within their programs. This chapter discusses a few of the graphics commands. These commands are useful in many applications and do not require extensive time to master. This next section provides a quick overview of the ba­
sics of using MATLAB’s graphics. The subsequent sections in this chapter present several additional examples (summarized in the table below) involving interesting applications which use these graphics primitives.
Example
Purpose
Polynomial Inter­
polation
2-D graphics and polynomial interpolation functions
Conformal
Mapping
2-D graphics and some aspects of complex numbers
Pendulum Motion
2-D graphics animation and ODE solution
Linear Vibration Model
Animated spring-mass response
String Vibration
2-D and 3-D graphics for a function of form
y(x,t)
Space Curve Ge­
ometry
3-D graphics for a space curve
Intersecting Sur­
faces
3-D graphics and combined surface plots
2.2 Overview of Graphics
The following commands should be executed since they will accelerate the under­
standing of graphics functions, and others, included within MATLAB.
help help
discusses use of help command.
help
lists categories of help.
help general
lists various utility commands.
help more
describes how to control output paging.
help diary
describes how to save console output to a file.
help plotxy
describes 2D plot functions.
help plotxyz
describes 3D plot functions.
help graphics
describes more general graphics features.
help demos
lists names of various demo programs.
intro
executes the intro program showing MATLAB commands including fundamental graphics capa­
bilities.
help funfun
describes several numerical analysis programs contained in MATLAB.
type humps
lists a function employed in several of the MAT­
LAB demos.
fplotdemo
executes program fplotdemo which plots the function named humps.
help peaks
describes a function peaks used to illustrate sur­
face plots.
peaks
executes the function peaks to produce an inter­
esting surface plot.
spline2d
executes a demo program to draw a curve through data input interactively.
The example programs can be studied interactively using the type command to list programs of interest. Library programs can also be inspected and printed using the MATLAB editor, but care should be taken not to accidentally overwrite the original library files with changes. Furthermore, text output in the command window can be captured in several ways. Some of these are: (1) Use the mouse to highlight material of interest. Then use the ”Print Selected” on the file menu to send output to the printer; (2) Use CTRL-C to copy outlined text to the clipboard. Then open a new file and use CTRL-V to paste the text into the new file; and (3) Use a diary command such as diary mysave.doc to begin printing subsequent command window output into the chosen file. This printing can be turned off using diary off. Then the file can be edited, modified, or combined with other text using standard editor commands.
More advanced features of MATLAB graphics, including handle graphics, control of shading and light sources, creation of movies, etc., exceed the scope of the present text. Instead we concentrate on using the basic commands listed below and on pro­
ducing simple animations. The advanced graphics can be mastered by studying the
MATLAB manuals and relevant demo programs. The principal graphing commands discussed here are
Command
Purpose
plot
draw two-dimensional graphs
xlabel, ylabel,
define axis labels
zlabel
title
define graph title
axis
set various axis parameters (min, max, etc.)
legend
show labels for plot lines
shg
bring graphics window to foreground
text
place text at selected locations
grid
turns grid lines on or off
mesh
draw surface using colored lines
surf
draw surface using colored patches
hold
fix the graph limits between successive plots
view
change surface viewing position
drawnow
empty graphics buffer immediately
zoom
magnify graph or surface plot
elf
clear graphics window
contour
draw contour plot
ginput
read coordinates interactively
All of these commands, along with numerous others, are extensively documented by the help facilities in MATLAB. The user can get an introduction to these capabilities by typing “help plot” and by running the demo programs. The accompanying code for the demo program should be examined since it provides worthwhile insight into how MATLAB graphics is used.
2.3 Example Comparing Polynomial and Spline Interpolation
Many familiar mathematical functions such as arctan(x), exp(x), sin(x), etc. can be represented well near x = 0 by Taylor series expansions. If a series expansion converges rapidly, taking a few terms in the series may produce good polynomial ap­
proximations. Assuming such a procedure is plausible, one approach to polynomial approximation is to take some data points, say (x i ,yi ), 1 < i < n and determine the polynomial of degree n — 1 passing through those points. It appears reasonable that using evenly spaced data is appropriate and that increasing the number of polyno­
mial terms should improve the accuracy of the approximating function. However, it
has actually been shown that a polynomial through points on a function y(x), where the x values are evenly spaced, often gives approximations which are not smooth between the data points and tend to oscillate at the ends of the interpolating interval [20]. Attempting to reduce the oscillation by increasing the polynomial order makes matters worse. Surprisingly, a special set of unevenly spaced points bunching data near the interval ends according to
Xj = (a + b)/2 + (a — b)/2cos[7r(j — 1/2)/n], 1 < j < n
f o r t h e i nt e r v a l a < x < b turns out to be preferable. This formula defines what are called the Chebyshev points optimally chosen in the sense described by Conte and de Boor [20].
The program below employs MATLAB functions polyfit, polyval, and spline to produce interpolated approximations to the known function 1/( 1+ x 2). The example illustrates how strongly the spacing of the data points for polynomial interpolation can influence results, and also shows that a spline interpolation can be a better choice than high order polynomials. A least square fit polynomial of degree n through data points defined by vectors (xd, yd) is given by
p(x) = polyval(polyfit(xd,yd, n),x).
Wh e n t h e p o l y n o mi a l o r d e r i s o n e l e s s t h a n t h e n u mb e r o f d a t a p o i n t s, t h e p o l y n o ­
mi a l p a s s e s t h r o u g h t h e d a t a p o i n t s e xa c t l y, b u t i t ma y s t i l l p r o d u c e u n s a t i s f a c t o r y i n t e r p o l a t i o n b e c a u s e o f l a r g e o s c i l l a t i o n s b e t we e n t h e d a t a p o i n t s. A p r e f e r a b l e a p ­
p r o x i ma t i o n i s o f t e n p r o v i d e d b y f u n c t i o n s p l i n e g i v i n g a p i e c e wi s e c u b i c c u r v e wi t h c o n t i n u o u s f i r s t a n d s e c o n d de r i va t i v e s. Th e p r o g r a m p a s s e s p o l y n o mi a l s o f d e g r e e t e n t h r o u g h a s e t o f e v e n l y s p a c e d p o i n t s a n d a s e t o f Ch e b y s h e v p o i n t s l y i n g i n t h e r a n g e —4 < x < 4. A spline curve passed through the equidistant points is constructed in addition to a least square polynomial fit employing 501 points. Two graphs are created which show results for x > 0. Only results for positive x were plotted to provide more contrast between different interpolation results.
Figure 2.1
plots the exact function, the spline curve, and the polynomial through the equidistant data. The polynomial is clearly an unsatisfactory approximation, whereas the spline appears to deviate imperceptibly from the exact function. By using the interactive zoom feature in MATLAB graphics, parts of the graph can be magnified so the dif­
ference between the spline and exact results is clearly visible.
Figure 2.2 compares the exact function with a polynomial employing the Chebyshev points. This result is much better than what is produced with equidistant data. An approximation gener­
ated from a least square fit polynomial and 501 data points is also shown. This curve fits the exact function unpredictably and significantly misses the desired values at x = 0 and x = ±4. While general conclusions about interpolation should not be drawn from this simple example, it certainly implies that high order polynomial in­
terpolation over a large range of the independent variable should be used cautiously.
The graphics functions used in the program include plot, title, xlabel, ylabel, and legend. Some other features of the program are summarized in the table preceding the code listing.
function values
SPLINE CURVE AND POLYNOMIAL USING EVEN SPACING
x axis
Figure 2.1: Spline and Polynomial Interpolation Using Equidistant Points
function values
LEAST SQUARE POLY. AND POLY. USING CHEBYSHEV POINTS
x axis
Figure 2.2: Interpolation Using Chebyshev Points and 501 Least Square
Points
Line
Operation
12,17,21
27
27,28,34-37
38
45,57
52,64
several inline functions are defined
function linspace generates vector of equidistant points
inline functions called
intrinsic spline function is used
graph legends created
graph images saved to files
Program polyplot
i: f u n c t i o n p o l y p l o t 2: % Exampl e: p o l y p l o t
4: % Th i s p r o g r a m i l l u s t r a t e s p o l y n o m i a l and 5: % s p l i n e i n t e r p o l a t i o n m et hods a p p l i e d t o 6: % a p p r o x i m a t e t h e f u n c t i o n 1/( 1 + x ~ 2 ).
7: %
8: % U s e r i n l i n e f u n c t i o n s u s e d:
9: % c bp, Yl s q, y e x a c t
1 0:
i i: % F u n c t i o n f o r Chebyshev d a t a p o i n t s
i 2: c b p = i n l i n e ( ['( a + b )/2 + ( a - b )/2 * c o s ( p i/n *',...
i s: '( 1/2:n ) )'],'a','b','n');
1 4:
i 5: % P o l y n o m i a l o f d e g r e e n t o l e a s t s q u a r e f i t i 6: % d a t a p o i n t s i n v e c t o r s x d,y d i 7: Y l s q = i n l i n e ('p o l y v a l ( p o l y f i t ( x d,y d,n ),x )',... i 8: 'x d','y d','n','x');
i 9:
2 0: % F u n c t i o n t o be a p p r o x i ma t e d by p o l y n o mi a l s 2 i: y e x a c t = i n l i n e ('1./( 1 + a b s ( x ) .~ p )','p','x');
2 2:
2 3: % S e t d a t a p a r a m e t e r s. F u n c t i o n s l i n s p a c e and 24: % cbp g e n e r a t e d a t a w i t h e v e n and Chebyshev 25: % s p a c i n g
2 6: n=10; nd=n+1; a =- 4; b=4; p=2;
2 7: x e v e n = l i n s p a c e ( a,b,n d ); y e v e n = y e x a c t ( p,x e v e n ); 2 8: x c b p = c b p ( a,b,n d ); y c b p = y e x a c t ( p,x c b p );
2 9:
3 0: n l s q = 5 0 1; % Number o f l e a s t s q u a r e p o i n t s 3 i: x l s q = l i n s p a c e ( a,b,n l s q ); y l s q = y e x a c t ( p,x l s q );
3 2:
3 3: % C o m p u t e i n t e r p o l a t e d f u n c t i o n s f o r p l o t t i n g
34: x p l t = l i n s p a c e ( 0,b,1 2 1 ); y p l t = y e x a c t ( p,x p l t ); 3 5: y y e v e n = Y l s q ( x e v e n,y e v e n,n,x p l t );
3 6: y y c b p = Y l s q ( x c b p,y c b p,n,x p l t );
3 7: y y l s q = Y l s q ( x l s q,y l s q,n,x p l t );
3 8: y y s p l n = s p l i n e ( x e v e n,y e v e n,x p l t );
3 9:
4 0: % P l o t r e s u l t s
4 i: j = 6:n d; % P l o t o n l y d a t a p o i n t s f o r x>=0 42: p l o t ( x p l t,y p l t,'-',x p l t,y y e v e n,' —',...
4 3: x p l t,y y s p l n,'.',x e v e n ( j ),y e v e n ( j ),...
4 4: 's','l i n e w i d t h',2 )
4 5: l e g e n d ('E x a c t F u n c t i o n',...
4 6: 'P o l y. f o r Even S p a c i n g',...
4 7: 'S p l i n e C u r v e',...
4 8: 'I n t e r p o l a t i o n P o i n t s',2 )
4 9: t i t l e ( ['S P L I N E CURVE AND POLYNOMIAL ',...
5 0: 'USING EVEN SPACING'])
5 i: x l a b e l ('x a x i s'), y l a b e l ('f u n c t i o n v a l u e s') 5 2: % p r i n t ( g c f,'- d e p s','s p l p o f i t')
5 3: s h g, p a u s e
54: p l o t ( x p l t,y p l t,'-',x p l t,y y c b p, ' —',...
5 5: x p l t,y y l s q,'.',x c b p ( j ),y c b p ( j ) ,'s',...
5 6: 'l i n e w i d t h',2 )
5 7: l e g e n d ('E x a c t F u n c t i o n',...
5 8: 'P o l y. f o r Chebyshev P o i n t s',...
5 9: 'L e a s t S q u a r e P o l y. F i t',...
6 0: 'I n t e r p o l a t i o n P o i n t s',1 )
6 i: t i t l e ( ['L E A S T SQUARE POLY. AND POLY. ',...
6 2: 'USING CHEBYSHEV POI NTS'] )
6 3: x l a b e l ('x a x i s'), y l a b e l ('f u n c t i o n v a l u e s') 64: % p r i n t ( g c f,'- d e p s','l s q c h f i t')
6 5: s h g, d i s p (' '), d i s p ('A l l Do ne')
2.4 Conformal Mapping Example
Thi s exampl e i nvol ves anal yt i c funct i ons and conf or mal mappi ng. The compl ex f unct i on w(z) which maps \z\< 1 onto the interior of a square of side length 2 can be written in power series form as
w(z) = £ bkz4k+1 k=0
where _
“(-i)fca)s
bk
k!(4k + 1)
- Σ bk = 1
k=0
and c is a scaling coefficient chosen to make z = 1 map to w = 1 (see reference [75]). Truncating the series after some finite number of terms, say m, produces an approximate square with rounded corners. Increasing m reduces the corner round­
ing but convergence is rather slow so that using even a thousand terms still gives perceptible inaccuracy. The purpose of the present exercise is to show how a polar coordinate region characterized by
z = reιθ , r 1 < r < r2 , θ1 < θ < θ2
t r a n s f o r ms a n d t o e x h i b i t a n u n d i s t o r t e d p l o t o f t h e r e g i o n p r o d u c e d i n t h e w- p l a n e. Th e e x e r c i s e a l s o e mp h a s i z e s t h e u t i l i t y o f MATLAB f o r h a n d l i n g c o mp l e x a r i t h ­
me t i c a n d c o mp l e x f u n c t i o n s. Th e p r o g r a m ha s a s h or t d r i v e r s q u a r r u n a n d a f u n c ­
t i o n s q u a r m a p wh i c h c o mp u t e s p o i n t s i n t h e w region and coefficients in the series expansion. Salient features of the program are summarized in the table below.
Results produced when 0.5 < r < 1 and 0 < θ < 2 π by a twenty-term series appear in
Figure 2.3.
The reader may find it interesting to run the program using sev­
eral hundred terms and take 0 < θ < π/2. The corner rounding remains noticeable even when m = 1000 is used. Later in this book we will visit the mapping problem again to show that a better approximation is obtainable using rational functions.
Routine
Line
Operation
squarrun
squarmap
cubrange
20-41
45
49
31-33
43-45
48-51
57-73
functions input, disp, fprintf, and read are
used to input data interactively. Several dif­
ferent methods of printing were used for pur­
poses of illustration rather than necessity. function squarmap generates results. function genprint is a system dependent rou­
tine which is used to create plot files for later printing.
functions linspace and ones are used to gen­
erate points in the z-plane. series coefficients are computed using cumprod and the mapping is evaluated using polyval with a matrix argument. scale limits are calculated to allow an undis­
torted plot of the geometry. Use is made of MATLAB functions real and imag. loops are executed to plot the circumferential lines first and the radial lines second. function which determines limits for a square or cube shaped region.
y axis
Mapping of a Square Using a 20-Term Polynomial
MATLAB Example Program squarrun
functi on s q u a r r u n % Exampl e: s q u a r r u n
%................................................
%
% D r i v e r pr o g r a m t o p l o t t h e mapping o f a % c i r c u l a r d i s k o n t o t h e i n t e r i o r o f a s q u a r e % by t h e S c h w a r z - C h r i s t o f f e l t r a n s f o r m a t i o n.
%
% U s e r m f u n c t i o n s r e q u i r e d:
% s q u a r m a p, i n p u t v, c u b r a n g e
% I l l u s t r a t e u s e of t h e f u n c t i o n s i n p u t and % i n p u t v t o i n t e r a c t i v e l y r e a d one o r s e v e r a l % d a t a i t e ms on t h e same l i n e
fpr i nt f ('\nCONFORMAL MAPPING OF A SQUARE ') f p r i n t f ('B Y USE OF A\n') f pr i nt f ('TRUNCATED SCHWARZ-CHRISTOFFEL ') f p r i n t f ('S E R I E S\n\n')
f p r i n t f ('I n p u t t h e number o f s e r i e s ') f p r i n t f ('t e r m s u s e d ') m = i n p u t ('( t r y 2 0 )? ');
% I l l u s t r a t e u s e of t h e f u n c t i o n d i s p d i s p ('')
s t r = ['\n I n p u t t h e i n n e r r a d i u s, o u t e r ' ... 'r a d i u s and number o f i n c r e me n t s ' ... '\n ( t r y .5,1,8 )\n']; f p r i n t f ( s t r );
% Use f u n c t i o n i n p u t v t o i n p u t s e v e r a l v a r i a b l e s [ r 1,r 2,n r ] = i n p u t v;
% Use f u n c t i o n f p r i n t f t o p r i n t mor e % c o mp l i c a t e d h e a d i n g
s t r = ['\n I n p u t the s t a r t i n g value of ' ...
't h e t a, the f i n a l value of t h e t a \n' ... 'and t h e number o f t h e t a i n c r e me n t s ' ... '( t h e a n g l e s a r e i n d e g r e e s ) ' ...
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
74
75
76
77
78
79
80
81
82
83
84
85
'\n ( t r y 0,360,120)\n']; f p r i n t f ( s t r ); [ t 1,t 2,nt ] =i nput v;
% Call function squarmap t o make t h e p l o t h o l d o f f; c l f;
[ w,b ] = s q u a r m a p ( m,r 1,r 2,n r,t 1,t 2,n t + 1 );
% S a v e t h e p l o t % p r i n t - d e p s s q u a r p l t
d i s p (' '); d i s p ('A l l Do n e');
%== ========================== ==================
f u n c t i o n [ w,b ] = s q u a r m a p ( m,r 1,r 2,n r,t 1,t 2,n t )
%
% [ w,b ] = s q u a r m a p ( m,r 1,r 2,n r,t 1,t 2,n t )
%.............................................................................................
% Th i s f u n c t i o n e v a l u a t e s t h e c o n f o r ma l mapping % p r o d u c e d by t h e S c h w a r z - C h r i s t o f f e l % t r a n s f o r m a t i o n w( z) mapping a b s ( z ) < = 1 i n s i d e % a s q u a r e h a v i n g a s i d e l e n g t h of t w o. The % t r a n s f o r m a t i o n i s a p p r o x i m a t e d i n s e r i e s f or m % whi c h c o n v e r g e s v e r y s l o wl y n e a r t h e c o r n e r s.
%
% m - n u m b e r o f s e r i e s t e r ms u s e d
% r 1,r 2,n r - a b s ( z ) v a r i e s f r om r 1 t o r 2 i n
% n r s t e p s
% t 1,t 2,n t - a r g ( z ) v a r i e s f r om t 1 t o t 2 i n % n t s t e p s ( t 1 and t 2 a r e m e a s u r e d
% i n d e g r e e s )
% w - p o i n t s a p p r o x i ma t i n g t h e s q u a r e
% b - c o e f f i c i e n t s i n t h e t r u n c a t e d
% s e r i e s e x p a n s i o n whi c h h a s t h e
% f or m
%
% w ( z ) = s u m ( { j = 1:m },b ( j ) * z * ( 4 * j - 3 ) )
%
% U s e r m f u n c t i o n s c a l l e d: c u b r a n g e
%-----------------------------------------------------------------------------------------
% Ge n e r a t e p o l a r c o o r d i n a t e g r i d p o i n t s f o r t h e % map. F u n c t i o n l i n s p a c e g e n e r a t e s v e c t o r s % w i t h e q u a l l y s p a c e d compone nt s. r = l i n s p a c e ( r 1,r 2,n r )';
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
t = p i/1 8 0 * l i n s p a c e ( t 1,t 2,n t ); z = ( r * o n e s ( 1,n t ) ).* ( o n e s ( n r,1 ) * e x p ( i * t ) );
% Use high point r e s o l u t i o n f or the % outer contour
t out er =pi/180*l i ns pa ce( t 1,t 2,10*nt );
zouter=r2*exp(i*touter);
% Compute t h e s e r i e s c o e f f i c i e n t s and
% e v a l u a t e t h e s e r i e s
k=1:m- 1;
b = c u m p r o d ( [ 1,- ( k -.7 5 ).* ( k -.5 )./( k.* ( k +.2 5 ) ) ] ); b = b/s u m( b ); w = z.* p o l y v a l ( b ( m:- 1:1 ),z.~ 4 ); w o u t e r = z o u t e r.* p o l y v a l ( b ( m:- 1:1 ),z o u t e r.~ 4 );
% De t e r mi n e s q u a r e window l i m i t s f o r p l o t t i n g
u u = r e a l ( [ w (:);w o u t e r (:) ] );
v v = i m a g ( [ w (:);w o u t e r (:) ] );
r n g = c u b r a n g e ( [ u u,v v ],1.1 );
a x i s ('s q u a r e'); a x i s ( r n g ); h o l d on
% P l o t o r t h o g o n a l g r i d l i n e s whi ch r e p r e s e n t % t h e mapping o f c i r c l e s and r a d i a l l i n e s x = r e a l ( w ); y=i mag( w); x o = r e a l ( w o u t e r ); y o =i ma g ( wo u t e r ); p l o t ( x,y,'- k',x ( 1:e n d - 1,:)',y ( 1:e n d - 1,:)',... '- k',x o,y o,'- k')
% Add a t i t l e and a x i s l a b e l s t i t l e ( ['M a p p i n g o f a S q u a r e Us i n g a ', ...
n u m 2 s t r ( m ),'- t e r m P o l y n o m i a l'] ) x l a b e l ('x a x i s'); y l a b e l ('y a x i s') f i g u r e ( g c f ); h o l d o f f;
%== ========================== ==================
f u n c t i o n r a n g e = c u b r a n g e ( x y z,o v r s i z )
%
% r a n g e = c u b r a n g e ( x y z,o v r s i z )
%..................................................................
% Th i s f u n c t i o n d e t e r mi n e s l i m i t s f o r a s q u a r e % o r cube s h a p e d r e g i o n f o r p l o t t i n g d a t a v a l u e s % i n t h e columns o f a r r a y xyz t o an u n d i s t o r t e d % s c a l e %
131: %
1 3 2: %
1 3 3: %
1 3 4: %
1 3 5: %
1 3 6: %
1 3 7: %
1 3 8: %
1 3 9: %
1 4 0: %
1 4 1: %
1 4 2: %
1 4 3: %
1 4 4: %
1 4 5: %
1 4 6: %
1 4 7: %
1 4 8:
1 4 9: i f n a r g i n = = 1, o v r s i z = 1; end
1 5 0: pmi n=mi n( xyz ); pmax=max( xyz); pm=( pmi n+pmax)/2; 151: p d =ma x ( o v r s i z/2 * ( p ma x - p mi n ) );
1 5 2: i f l e n g t h ( p mi n ) = = 2
1 5 3: r a n g e = p m ( [ 1,1,2,2 ] ) + p d * [ - 1,1,- 1,1 ];
1 5 4: e l s e
1 5 5: r a nge =pm( [ 1 1 2 2 3 3 ] ) + p d * [ - 1,1,- 1,1,- 1,1 ];
1 5 6: e n d 1 5 7:
1 5 8: %== ========================== ==================
1 5 9:
1 6 0: % f u n c t i o n v a r a r g o u t = i n p u t v ( p r o m p t )
1 6 1: % See Appendix B
2.5 Nonlinear Motion of a Damped Pendulum
Motion of a simple pendulum is one of the most familiar dynamics examples stud­
ied in physics. The governing equation of motion can be satisfactorily linearized for small oscillations about the vertical equilibrium position, whereas nonlinear effects become important for large deflections. For small deflections, the analysis leads to a constant coefficient linear differential equation. Solving the general case requires elliptic functions seldom encountered in routine engineering practice. Nevertheless, the pendulum equation can be handled very well for general cases by numerical in­
tegration.
xyz - a m a t r i x of t h e f or m [ x,y ] o r [ x,y,z ] wher e x,y,z a r e v e c t o r s of c o o r d i n a t e p o i n t s
o v r s i z - a s c a l e f a c t o r f o r i n c r e a s i n g t h e
w i n d o w s i z e. Th i s p a r a m e t e r i s s e t t o one i f o n l y one i n p u t i s g i v e n.
r a n g e - a v e c t o r u s e d by f u n c t i o n a x i s t o s e t window l i m i t s t o p l o t x,y,z p o i n t s u n d i s t o r t e d. Th i s v e c t o r h a s t h e f or m [ xmi n,xmax,ymi n,ymax] when xyz h a s o n l y t wo columns o r t h e f or m [ xmi n,xma x,ymi n,yma x,z mi n,z ma x] when xyz h a s t h r e e col umns.
U s e r m f u n c t i o n s c a l l e d: none
Suppose a bar of negligible weight is hinged at one end and has a particle of mass m attached to the other end. The bar has length l and the deflection from the vertical static equilibrium position is called θ. Assuming that the applied forces consist of the particle weight and a viscous drag force proportional to the particle velocity, the equation of motion is found to be
θ"(τ) + -θ'{ί) + ?s i n( 0) = O m l
wh e r e r i s t i me, c i s a v i s c o u s d a mp i n g c o e f f i c i e n t, a n d g is the gravity constant. Introducing dimensionless time, t, such that r = \f l f g t gives
θ "(ί) + 2ςθ '(t) + sin^) = 0
where ς = y/T/gc/( 2m) is called the damping factor. When Θ is small enough
for sin^) to be approximated well by θ , then a constant coefficient linear equation
solvable by elementary means is obtained. In the general situation, a solution can still be obtained numerically without resorting to higher transcendental functions. If we use ς = 0.10 for illustrative purposes, and let
* = m; θ '(t)]
t h e n t h e o r i g i n a l d i f f e r e n t i a l e q u a t i o n e x p r e s s e d i n f i r s t o r d e r ma t r i x f o r m i s
*'(t) = [z(2); —0.2z(2) — sin(z(1)].
An inline function suitable for use by the ode45 integrator in MATLAB is simply zdot=inline(‘[z(2); -0.2*z(2)-sin(z(1))] ’,’t’,’z’).
A program was written to integrate the pendulum equation when the angular ve­
locity ω0 for θ = 0 is specified. For the undamped case, it is not hard to show that a starting angular velocity exceeding 2 is sufficient to push the pendulum over the top, but the pendulum will fall back for values smaller than two. For the amount of vis­
cous damping chosen here, a value of about ωo = 2.42 barely pushes the pendulum over the top, whereas the top is not reached for ω0 = 2.41. These cases vividly illus­
trate that, for a nonlinear system, small changes in initial conditions can sometimes produce very large changes in the response of the system.
In the computer program that follows, a driver function runpen controls input, calls the differential equation solver ode45, as well as a function animpen which plots θ versus t, and performs animation by drawing successive positions of the pen­
dulum. Because the animation routine is very simple and requires little knowledge of MATLAB graphics, the images and the titles flicker somewhat. This becomes particularly evident unless the graph axes are left off. A better routine using more detailed graphics commands to eliminate the flicker problem is presented in Article
2.7 on wave motion in a string. The current program permits interactive input repeat­
edly specifying the initial angular velocity, or two illustrative data cases can be run by executing the command runpen(1). The differential equation for the problem is defined as function zdot on lines 26 and 27. This equation is integrated numerically
PUSHED OVER THE TOP FOR W0=2.42
time
Figure 2.4: Angular Deflection versus Time for Pendulum Pushed Over the
Top
by calls to function ode45 on lines 59, 75, and 80. Integration tolerance values were chosen at line 30, and a time span for the simulation is defined interactively at lines 46 and 47. Function penanim(t,th,titl,tim) plots theta versus time and animates the system response by computing the range of (x,y) values, fixing the window size to prevent distortion, and sequentially plotting positions of the pendulum to show the motion history. The output results produced by runpen(1) are shown below for reference.
PUSHED OVER THE TOP FOR W0=2.42
angular deflection (degrees)
ALMOST OVER THE TOP FOR W0=2.41
time
Figure 2.6: Angular Displacement versus Time for Pendulum Almost Pushed
Over the Top
ALMOST OVER THE TOP FOR W0=2.41
Figure 2.7: Partial Motion Trace for Pendulum Almost Pushed Over the Top
Program pendulum
functi on pendulum(rundemo)
% pendulum(rundemo)
% This example a n a l y z e s damped o s c i l l a t i o n s of % a s i mp l e pendulum and a n i m a t e s t h e mo t i o n.
% The g o v e r n i n g s e c o n d o r d e r d i f f e r e n t i a l % e q u a t i o n i s %
% t h e t a"( t ) + 0.2 * t h e t a'( t ) + s i n ( t h e t a ) = 0
% Type pendulum wi t h no a r g u m e n t f o r i n t e r - % a c t i v e i n p u t. Type p e n d u l u m( l ) t o r u n t wo % example p r o b l e m s
% The e q u a t i o n of mo t i o n c a n be w r i t t e n a s % t wo f i r s t o r d e r e q u a t i o n s:
% t h e t a'( t ) = w; w'( t ) = -.2 * w - s i n ( t h e t a )
% L e t t i n g z = [ t h e t a; w], t h e n % z'( t ) = [ z ( 2 ); - 0.2 * z ( 2 ) - s i n ( z ( 1 ) ) ]
d i s p (' ')
d i s p (' DAMPED PENDULUM MOTION DESCRIBED BY') d i s p (' t h e t a"( t ) + 0.2 * t h e t a''( t ) + s i n ( t h e t a ) = 0')
% C r e a t e an i n l i n e f u n c t i o n d e f i n i n g t h e % d i f f e r e n t i a l e q u a t i o n i n m a t r i x f or m z d o t = i n l i n e (...
'[ z ( 2 );- 0.2 * z ( 2 ) - s i n ( z ( 1 ) ) ]','t','z');
% S e t o d e 4 5 i n t e g r a t i o n t o l e r a n c e s o p s = o d e s e t ('r e l t o l',1 e - 5,'a b s t o l',l e - 5 );
% I n t e r a c t i v e l y i n p u t a n g u l a r v e l o c i t y r e p e a t e d l y i f n a r g i n ==0
wh i l e 1, c l o s e, d i s p (' ')
d i s p ('S e l e c t t h e a n g u l a r v e l o c i t y a t t h e l o w e s t') d i s p ('p o i n t. V a l u e s o f 2.4 2 o r g r e a t e r p u s h t h e') d i s p (...
't h e pendulum o v e r t h e t o p. I n p u t z e r o t o s t o p.') w0 = i n p u t ('w0 = ? > ');
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
74
75
76
77
78
79
80
81
82
83
84
85
86
i f isempty(w0) | w0==0
d i s p (' '), d i s p ('A l l Done'), d i s p (' '), r e t ur n end
d i s p (' ')
t = i n p u t ( ['I n p u t a vector of time values ',...
'( T r y 0:.1:3 0 ) > ? '] );
d i s p (' ')
t i t l = i n p u t ('I n p u t a t i t l e f o r t h e g r a p h s : ','s'); d i s p (' '), d i s p (...
'I n p u t 1 t o l e a v e i mages o f a l l p o s i t i o n s s hown') t r a c = i n p u t (...
'i n t h e a n i ma t i o n, o t h e r w i s e i n p u t 0 > ? ');
% S p e c i f y t h e i n i t i a l c o n d i t i o n s and s o l v e t h e % d i f f e r e n t i a l e q u a t i o n u s i n g ode45 t h e t a 0 = 0; z 0 = [ t h e t a 0;w 0 ]; [ t,t h ] = o d e 4 5 ( z d o t,t,z 0,o p s );
% Ani mat e t h e mo t i o n a n i m p e n ( t,t h (:,1 ),t i t l,.0 5,t r a c ) end
% Run t wo t y p i c a l d a t a c a s e s e l s e
% Choose t i me l i m i t s f o r t h e s o l u t i o n tmax=30; n=351; t = l i n s p a c e ( 0,t m a x,n );
d i s p (' ')
d i s p ('P r e s s r e t u r n t o s e e t wo e x a m p l e s'), p a u s e
w0=2.42; W0=num2str(w0); [ t,t h] =ode45( zdot,t,[ 0;w0],ops ); titl=['PUSHED OVER THE TOP FOR W0 = ',W0]; a n i m p e n ( t,t h (:,1 ), t i t l,.0 5 ), p a u s e ( 2 )
w0=2.41; W0=num2st r ( w0);
[ t,t h ] = o d e 4 5 ( z d o t,t,[ 0;w 0 ],o p s );
t i t l =['NEARLY PUSHED OVER THE TOP FOR W0 = ',W0];
a n i m p e n ( t,t h (:,1 ),t i t l,.0 5 )
c l o s e, d i s p (' '), d i s p ('A l l D o n e'), d i s p (' ') end
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
%
functi on a n i m p e n ( t,t h,t i t l,t i m,t r a c )
%
% a n i m p e n ( t,t h,t i t l,t i m,t r a c )
%..................................................................
% This function p l o t s t h e t a versus t and a n i m a t e s % t h e pendulum mo t i o n
%
% t - t i me v e c t o r f o r t h e s o l u t i o n
% t h - a n g u l a r d e f l e c t i o n v a l u e s d e f i n i n g t h e
% p e n d u l u m p o s i t i o n s
% t i t l - a t i t l e shown on t h e g r a p h s % t i m - a t i me d e l a y b e t we e n s u c c e s s i v e s t e p s of % t h e a n i ma t i o n. Th i s i s u s e d t o s l ow down
% t h e a n i ma t i o n on f a s t c o mp u t e r s
% t r a c - 1 i f s u c c e s s i v e p o s i t i o n s p l o t t e d i n t h e % a n i ma t i o n a r e r e t a i n e d on t h e s c r e e n, 0
% i f e a c h image i s e r a s e d a f t e r i t i s
% d r a w n
i f n a r g i n < 5, t r a c = 0; end; i f n a r g i n < 4, t i m=.0 5; end; i f n a r g i n < 3, t i t l =''; end
% P l o t t h e a n g u l a r d e f l e c t i o n p l o t ( t,1 8 0/p i * t h (:,1 ),'k'), x l a b e l ('t i m e') y l a b e l ('a n g u l a r d e f l e c t i o n ( d e g r e e s )'), t i t l e ( t i t l ) g r i d on, s h g, d i s p (' ')
d i s p ('P r e s s r e t u r n t o s e e t h e a n i m a t i o n'), p a u s e % p r i n t - d e p s p e n a n g l e
nt =l engt h( t h); z=zeros( nt,1); x = [ z,s i n ( t h ) ]; y = [ z,- c o s ( t h ) ]; hold of f, close i f t r a c
a x i s ( [ - 1,1,- 1,1 ] ), axis square, axis of f, hold on
end
f or j=1:nt
X=x( j,:); Y=y( j,:);
p l o t ( X,Y,'k -',X ( 2 ),Y ( 2 ),'k o','m a r k e r s i z e',12) i f ~trac
a x i s ( [ - 1,1,- 1,1 ] ), axis square, axis off end
t i t l e ( t i t l ), drawnow, shg i f tim>0, pause(tim), end
132: end
133: % i f t r a c = = 1, p r i n t - d e p s p e n t r a c e, end 134: p a u s e ( 1 ),h o l d o f f
2.6 A Linear Vibration Model
I mpor t ant aspect s of l i near vi br at i on t heory ar e i l l ust r at ed by t he one- di mensi onal mot i on of a mass subj ect ed t o an el ast i c r est or i ng f or ce, a vi scous dampi ng for ce propor t i onal t o t he vel oci t y, and a har moni cal l y var yi ng for ci ng funct i on. The r el at ed di ff erent i al equat i on is
m x' (t) + cx ( t ) + k x(t) = f i cos(w t) + f 2 sin(wi) = real((/i — i f 2 ) exp(iwi))
wi t h i ni t i al condi t i ons of x(0) = x 0 and x'(0) = v0. The general solution is the sum of a particular solution to account for the forcing function, and a homogeneous solution corresponding to a zero right hand side. The initial conditions are applied to the sum of the two solution components. The particular solution is given by
X (t) = real(F exp(iwt))
wi t h
F = (fi — i f2 )/( k — mω‘2 + i cω).
Th e i n i t i a l c o n d i t i o n s g i v e n b y t hi s p a r t i c u l a r s o l u t i o n a r e
X
(0) = real(
F
)
and
X'(0) = real(i ω F).
Th e c h a r a c t e r i s t i c e q u a t i o n f o r t h e h o mo g e n e o u s e q u a t i o n i s
m s 2 + cs + k = 0
which has roots
si = (—c +r )/( 2m), s2 = (—c — r)/(2m), r = \/ c2 — Am k.
Th e n t h e h o mo g e n e o u s s o l u t i o n h a s t h e f o r m
u(t) = d(1) exp(sit) + d(2) exp(s2t)
where
d = f1! 1; si, s2 ] \ [xo — X (0)5 vo — X/(0)] and the complete solution is
x(t) = u(t) + X (t).
A couple of special cases arise. The first corresponds to zero damping and a forcing function matching the undamped natural frequency, i.e.,
c = 0, ω = \f kf ni.
Thi s c a s e c a n b e a vo i d e d b y i n c l u d i n g a t i n y a mo u n t o f d a mp i n g t o ma k e c = 2%/mfc/lO6. The second case happens when the characteristic roots are equal. This is remedied by perturbing the value of c to (1 + 10 - 6) times c. Such small changes in a system model where realistic physical parameters are only known approximately will not affect the final results significantly.
In practice, enough damping often exists in the system to make the homogeneous solution components decay rapidly so the total solution approaches the particular solution with the displacement having the same frequency as the forcing function but out of phase with that force. To illustrate this effect, a program was written to solve the given differential equation, plot x(t), and show an animation for a block connected to a wall with a spring and sliding on a surface with viscous damping resistance. Applying the oscillating force of varying magnitude on the block helps illustrate how the homogeneous solution dies out and the displacement settles into a constant phase shift relative to the driving force.
The following program either reads data interactively or runs a default data exam­
ple. The solution procedure described above is implemented in function smdsolve. For arbitrary values of the system parameters, x(t) is plotted and a simple animation scheme is used to plot the block, a spring, and the applied force throughout the time history.
Figure 2.8 shows x(t) for the default data case. The input data values for this case use
[m, c, k, f i, f 2, w, xo, vo, t max, nt] < = > [1, 3, 1, 1, 0, 2, 0, 2, 30, 250].
Note that near t = 11 , the transient and forced solution components interact so that the block almost pauses momentarily. However, the solution then quickly approaches the steady state.
Figure 2.9 shows the final position of the mass and the applied force at the end of the chosen motion cycle.
displacement
FORCED RESPONSE OF A DAMPED HARMONIC OSCILLATOR
time
Figure 2.8: Plot of x(t) for a Linear Harmonic Oscillator
FORCED MOTION WITH DAMPING
Figure 2.9: Block Sliding On a Plane with Viscous Damping
Program smdplot
functi on [ t,X,m,c,k,f1,f2,w,x0,v0]= smdplot(example)
%
% [t,X,m,c,k,f1,f2,w,x0,v0]= smdplot(example)
%............................................................................................................
% This function p l o t s the response and a n i m a t e s t h e % mo t i o n o f a damped l i n e a r h a r mo n i c o s c i l l a t o r % c h a r a c t e r i z e d by t h e d i f f e r e n t i a l e q u a t i o n % m* x''+ c * x'+ k * x = f 1 * c o s ( w * t ) + f 2 * s i n ( w * t )
% w i t h i n i t i a l c o n d i t i o n s x ( 0 ) = x 0, x'( 0 ) = v 0.
% The a n i ma t i o n d e p i c t s f o r c e d mo t i o n of a b l o c k % a t t a c h e d t o a w a l l by a s p r i n g. The b l o c k % s l i d e s on a h o r i z o n t a l p l a n e whi c h p r o v i d e s % v i s c o u s damping.
% example - Omit t h i s p a r a m e t e r f o r i n t e r a c t i v e i n p u t. % Use s m d p l o t ( l ) t o r u n a s a m p l e p r o b l e m.
% t,X - t i me v e c t o r and d i s p l a c e me n t r e s p o n s e
% m,c,k - ma s s, damping c o e f f i c i e n t,
% s p r i n g s t i f f n e s s c o n s t a n t
% f 1,f 2,w - f o r c e components and f o r c i n g f r e q u e n c y
% x 0,v 0 - i n i t i a l p o s i t i o n and v e l o c i t y
%
% Us e r m f u n c t i o n s c a l l e d: s p r i n g s m d s o lv e i n p u t v % -------------------------------------------------------------------------------------------
p l t s a v e = 0; d i s p (' '), d i s p (...
' SOLUTION OF '), d i s p (...
'M*X" + C*X'' + K*X = F1*COS(W*T) + F2*SI N( W*T)') d i s p (...
' WITH ANIMATION OF THE RESPONSE')
d i s p (' ')
% E x a m p l e d a t a u s e d when n a r g i n > 0 i f n a r g i n > 0
m=1; c =.3; k=1; f 1=1; f 2=0; w=2; x0=0; v0=2; t max=25; n t =250; e l s e % I n t e r a c t i v e d a t a i n p u t [ m,c,k ] = i n p u t v (...
'I n p u t m, c, k ( t r y 1, .3, 1) >> ? ');
[ f 1,f 2,w ] = i n p u t v (...
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
74
75
76
77
78
79
80
81
82
83
84
85
86
'Input f1, f2, w (t r y 1, 0, 2) >> ? ');
[ x0,v0]=i nput v(...
'Input x0, v0 ( t ry 0, 2) >> ? ');
[ t max,nt] =i nputv(...
'Input tmax, nt ( t r y 30, 250) >> ? ');
end
t =l i nspace( 0,t max,nt ); X=smdsolve(m,c,k,f1,f2,w,x0,v0,t);
% Plot the displacement versus time p l o t ( t,X,'k'), x l a b e l ('t i m e') y l a b e l ('d i s p l a c e m e n t'), t i t l e (...
'FORCED RESPONSE OF A DAMPED HARMONIC OSCILLATOR') g r i d on, s h g, d i s p (' ')
i f p l t s a v e, p r i n t - d e p s s md p l o t x v s t; end d i s p ('P r e s s r e t u r n f o r r e s p o n s e a n i m a t i o n') p a u s e
% Add a b l o c k and a s p r i n g t o t h e d i s p l a c e me n t xmx=max( a bs ( X) ); X=X/1.1/xmx; x b = [ 0,0,1,1,0,0 ]/2; y b = [ 0,- 1,- 1,1,1,0 ]/2;
% Ma ke a n a r r o w t i p d =.0 8; h =.0 5;
x t i p = [ 0,- d,- d,0 ]; y t i p = [ 0,0,0,h,- h,0 ];
% Add a s p r i n g and a b l o c k t o t h e r e s p o n s e [ x s,y s ] = s p r i n g; n m=l e n g t h ( X); n s = l e n g t h ( x s ); n b = l e n g t h ( x b ); x = z e r o s ( n m,n s + n b );y = [ y s,y b ]; f o r j =1:nm, x ( j,:) = [ - 1 + ( 1 + X ( j ) ) * x s,X ( j ) + x b ];e n d x mi n = mi n ( x (:) ); x ma x =ma x ( x (:) ); d=xmax-xmin; xmax=xmi n+1.1*d; r = [ x m i n,x m a x,- 2,2 ]; r x = r ( [ 1 1 2 ] ); r y = [.5,-.5,-.5 ]; c l o s e;
% P l o t t h e mo t i o n f o r j =1:nm
% C o m p u t e a n d s c a l e t h e a p p l i e d f o r c e f = f 1 * c o s ( w * t ( j ) ) + f 2 * s i n ( w * t ( j ) ); f =.5 * f; f a = a b s ( f ); s f = s i g n ( f ); x j = x ( j,:); x ma xj =ma x( xj ); i f s f >0
x f o r c = x m a x j + [ 0,f a,f a + x t i p ];
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
el se
xfor c=xmaxj +[f a,0,-xt i p];
end
% Plot the spring, block, and force % p l o t ( x j,y,r x,r y,'k',x f o r c,y t i p,'r') % p l o t ( x j,y,'k -',r x,r y,'k -',x f o r c,y t i p,'k -') p l o t ( x j,y,'k -',x f o r c,y t i p,'k -',...
r x,r y,'k -','l i n e w i d t h',1 ) title('FORCED MOTION WITH DAMPING') xlabel('FORCED MOTION WITH DAMPING') a x i s ( r ), a x i s ('o f f'), drawnow f i g u r e ( g c f ), p a u s e (.0 5 )
end
i f p l t s a v e, p r i n t - d e p s s md p l o t a n i m; end
d i s p (' '), d i s p ('A l l Done')
%=============== =====================
f u n c t i o n [ x,y ] = s p r i n g ( l e n,h t )
% Th i s f u n c t i o n g e n e r a t e s a s e t of p o i n t s % d e f i n i n g a s p r i n g
i f n a r g i n = = 0, l e n = 1; h t =.1 2 5; end x = [ 0,.5,l i n s p a c e ( 1,1 1,1 0 ),1 1.5,1 2 ] ; y = [ o n e s ( 1,5 );- o n e s ( 1,5 ) ]; y = [ 0;0;y (:);0;0 ]'; y = h t/2/ma x ( y ) * y; x = l e n/ma x ( x ) * x;
%=============== =====================
f u n c t i o n [ x,v ] = s m d s o l v e ( m,c,k,f 1,f 2,w,x 0,v 0,t )
%
% [ x,v ] = s m d s o l v e ( m,c,k,f 1,f 2,w,x 0,v 0,t )
%.............................................................................................
% Th i s f u n c t i o n s o l v e s t h e d i f f e r e n t i a l e q u a t i o n % m * x''( t ) + c * x'( t ) + k * x ( t ) = f 1 * c o s ( w * t ) + f 2 * s i n ( w * t )
% w i t h x ( 0 ) =x 0 and x'( 0 ) = v 0 %
% m,c,k - ma s s, damping and s t i f f n e s s c o e f f i c i e n t s % f 1,f 2 - m a g n i t u d e s o f c o s i n e and s i n e t e r ms i n
% t h e f o r c i n g f u n c t i o n
% w - f r e q u e n c y of t h e f o r c i n g f u n c t i o n
% t - v e c t o r of t i me s t o e v a l u a t e t h e s o l u t i o n
% x,v - computed p o s i t i o n and v e l o c i t y v e c t o r s
133: c c r i t = 2 * s q r t ( m * k ); wn = s q r t ( k/m);
1 3 4:
1 3 5: % I f t h e s y s t e m i s undamped and r e s o n a n c e w i l l
1 3 6: % o c c u r, add a l i t t l e damping
137: i f c==0 & w==wn; c = c c r i t/1 e 6; end;
1 3 8:
1 3 9: % I f damping i s c r i t i c a l, modi f y t h e damping 140: % v e r y s l i g h t l y t o a v o i d r e p e a t e d r o o t s 141: i f c = = c c r i t; c = c * ( 1 + 1 e - 6 ); end
1 4 2:
1 4 3: % F o r c e d r e s p o n s e s o l u t i o n 144: a = ( f 1 - i * f 2 )/( k - m* w~ 2 + i * c * w) ;
1 4 5: X 0 = r e a l ( a ); V0 = r e a l ( i * w* a );
1 4 6: X = r e a l ( a * e x p ( i * w * t ) ); V = r e a l ( i * w * a * e x p ( i * w * t ) );
1 4 7:
1 4 8: % H o m o g e n e o u s s o l u t i o n 149: r = s q r t ( c ~ 2 - 4 * m* k );
1 5 0: s 1 = ( - c + r )/( 2 * m ); s 2 = ( - c - r )/( 2 * m );
1 5 1: p = [ 1,1;s 1,s 2 ]\[ x 0 - X 0;v 0 - V 0 ] ;
1 5 2:
1 5 3: % T o t a l s o l u t i o n s a t i s f y i n g t h e i n i t i a l c o n d i t i o n s 154: x = X + r e a l ( p ( 1 ) * e x p ( s 1 * t ) + p ( 2 ) * e x p ( s 2 * t ) );
1 5 5: v = V + r e a l ( p ( 1 ) * s 1 * e x p ( s 1 * t ) + p ( 2 ) * s 2 * e x p ( s 2 * t ) ) ;
156:
157: %====================================
158:
159: % f u n c t i o n [ a 1,a 2,...,a _ n a r g o u t ] = i n p u t v ( p r o m p t )
1 6 0: % See Appendix B
132:
2.7 Example of Waves in an Elastic String
One-dimensional wave propagation is illustrated well by the response of a tightly stretched string of finite length released from rest with given initial deflection. The transverse deflection y(x, t) satisfies the wave equation
a yxx = ytt
and the general solution for an infinite length string, released from rest, is given by
y(x, t) = [F (x — at) + F( x + at)]/2
wher e F(x) is the initial deflection for —to < x < to. The physical interpretation for this equation is that the initial deflection splits in two parts translating at speed a,with one part moving to the right and the other moving to the left. The translating
wave solution can be adapted to handle a string of finite length l by requiring
y(0,t) = y(l,t) = 0.
Th e s e e n d c o n d i t i o n s, a l o n g wi t h i n i t i a l de f l e c t i o n f (x) ( defining F (x) between 0 and l ), are sufficient to continue the solution outside the original interval. We write the initial condition for the finite length string as
y(x, 0) = f (x), 0 < x < l.
To s a t i s f y t h e e n d c o n d i t i o n s, F(x) must be an odd-valued function of period 2l. Introducing a function g(x) such that
g(x) = f (x), 0 < x < l
a n d
g(x) = —f (2l — x), l < x < 2l
l e a d s t o
F(x) = sign(x)g(rem(abs(x), 2l))
wher e t he desi r ed per i odi ci t y i s achi eved usi ng t he MATLAB r emai nder funct i on, r e m. Thi s same pr obl em can al so be sol ved usi ng a Four i er si ne seri es (see chapt er 9). For t he pr esent we concent r at e on t he sol ut i on j us t obt ai ned.
A pr ogr am was wr i t t en t o i mpl ement t he t ransl at i ng wave sol ut i on when f (x) is a piecewise linear function computed using interp1. The system behavior can be examined from three different aspects. 1) The solution y(x, t) for a range of x and t values describes a surface. 2) The deflection curve at a particular time 10 is expressed as y( x,t 0), 0 < x < l. 3) The motion history at a particular point x 0 is y( x0,t), t > 0. The nature of F(x) implies that the motion has a period of 2l/a. Waves striking the boundary are reflected in inverted form so that for any time y( x,t + l/a) = —y(x, t ). The character of the motion is typified by the default data case the program uses to define a triangular initial deflection pattern where
a =1, l = 1, xd = [0, 0.33, 0.5, 0.67, 1], yd = [0, 0, —1, 0, 0].
The program reads the wave speed, the string length, and data points specifying the initial deflection. The solution is evaluated for a range of x, t values. The function plot3 was used to create
Figure 2.10,
which is a three-dimensional plot of traces of the string deflection for a sequence of times. Figure 2.11 shows the string position at t = 0.33.
Figure 2.12 plots the deflection history at position x = 0.25. Finally, a function to animate the solution over two motion cycles illustrates how the initial deflection splits, translates, and reflects from the boundaries. In an attempt to illus­
trate successive positions assumed in the animation, traces of the motion for a brief period are shown in
Figure 2.13
TRANSLATING WAVE OVER HALF A PERIOD
Figure 2.10: String Position as a Function of Position and Time
DEFLECTION WHEN T = 0.33333
x axis
Figure 2.11: String Deflection when t = 0.33
DEFLECTION HISTORY AT X = 0.25
time
Figure 2.12: Motion at Quarterpoint of the String
MOTION TRACE OVER ONE EIGHTH OF A PERIOD
Figure 2.13: Motion Trace Over a Short Time Interval
MATLAB Example Program strngrun
functi on strngrun(rundemo)
%
% strngrun(rundemo)
%........................................
% This function i l l u s t r a t e s propagation o f % waves i n a t i g h t l y s t r e t c h e d s t r i n g h a v i n g % g i v e n i n i t i a l d e f l e c t i o n. C a l l i n g s t r n g r u n % w i t h no i n p u t ar g u me n t c a u s e s d a t a t o be % r e a d i n t e r a c t i v e l y. Ot h e r wi s e, s t r n g r u n ( l )
% e x e c u t e s a sam p l e d a t a c a s e.
%
% Us e r m f u n c t i o n s c a l l e d: s t r n g wa v a n i m a t e p l t s a v = 0; % f l a g t o s a v e o r n o t s a v e g r a p h s d i s p (' ')
di sp('WAVE PROPAGATION IN A STRI NG'), d i s p (' ') i f n a r g i n = =0 % I n p u t d a t a i n t e r a c t i v e l y
[ a,l e n ] = i n p u t v ( ['I n p u t wave s p e e d ( a ) and ',... 's t r i n g l e n g t h ( l e n ) > ? '] ); d i s p (' ')
d i s p ( ['E n t e r t h e number o f i n t e r i o r ',...
'd a t a p o i n t s ( t h e f i x e d'] ) d i s p ( ['e n d p o i n t c o o r d i n a t e s a r e ',...
'a d d e d a u t o m a t i c a l l y )'] ) n = i n p u t ('? '); i f i s e m p t y ( n ), r e t u r n, e n d x d = z e r o s ( n + 2,1 ); x d ( n + 2 ) = l e n; y d = z e r o s ( n + 2,1 ); d i s p (' ') d i s p ( ['T h e s t r i n g s t r e t c h e s b e t w e e n ',...
'f i x e d e n d p o i n t s a t'] ) d i s p ( ['x = 0 a n d x =',n u m 2 s t r ( l e n ),'.'] ),d i s p (' ') d i s p ( ['E n t e r ',n u m 2 s t r ( n ),...
' s e t s o f x,y t o s p e c i f y i n t e r i o r'] ) d i s p ( ['i n i t i a l d e f l e c t i o n s ',...
'( o n e p a i r p e r l i n e )'] ) f o r j = 2:n + 1,[ x d ( j ),y d ( j ) ] = i n p u t v; e n d; d i s p (' ')
d i s p ('I n p u t tmax and t h e number o f t i me s t e p s') [ t m a x,n t ] = i n p u t v ('( T r y l e n/a and 40) > ? '); d i s p (' ')
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
74
75
76
77
78
79
80
81
82
83
84
85
di s p('Spec i f y po s i t i o n x=x0 whe r e t h e t i m e') x 0 = i n p u t (...
'h i s t o r y i s t o be e v a l u a t e d ( t r y l e n/4 ) > ? '); d i s p (' ')
d i s p ('S p e c i f y t i me t = t 0 when t h e d e f l e c t i o n') t 0 = i n p u t ('c u r v e i s t o be p l o t t e d > ? '); d i s p (' ')
t i t l = i n p u t ('I n p u t a g r a p h t i t l e > ? ','s');
e l s e % Example f o r t r i a n g u l a r i n i t i a l d e f l e c t i o n a=1; l e n =1; t ma x = l e n/a; n t =4 0; x d = [ 0,.3 3,.5,.6 7,1 ] * l e n; y d = [ 0,0,- 1,0,0 ];
% D i f f e r e n t example f o r a t r u n c a t e d s i n e c u r v e % x d = l i n s p a c e ( 0,l e n,3 5 1 ); y d = s i n ( 3 * p i/l e n * x d );
% k = f i n d ( y d < = 0 ); x d =x d ( k ); y d =y d ( k );
x 0 = 0.2 5 * l e n; t 0 = 0.3 3 * l e n/a; t i t l ='TRANSLATING WAVE OVER HALF A PERIOD'; end
nx=80; x = 0:l e n/n x:l e n; t = 0:t m a x/n t:t m a x;
h = ma x ( a b s ( y d ) ); x p l o t = l i n s p a c e ( 0,l e n,2 0 1 ); t p l o t = l i n s p a c e ( 0,m a x ( t ),2 5 1 )';
[ Y,X,T ] = s t r n g w a v ( x d,y d,x,t,l e n,a ); p l o t 3 ( X',T',Y','k'); x l a b e l ('x a x i s') y l a b e l ('t i m e'), z l a b e l ('y ( x,t )'), t i t l e ( t i t l ) i f p l t s a v, p r i n t ( g c f,'- d e p s','s t r n g p l o t 3'); end drawnow, s h g, d i s p (' ')
d i s p ('P r e s s r e t u r n t o s e e t h e d e f l e c t i o n') d i s p ( ['w h e n t = ',n u m 2 s t r ( t 0 ) ] ), p a u s e
[ y t 0,x x,t t ] = s t r n g w a v ( x d,y d,x p l o t,t 0,l e n,a ); close; p l o t ( x x (:),y t 0 (:),'k') x l a b e l ('x a x i s'), y l a b e l ('y ( x,t 0 )') title(['DEFLECTION WHEN T = ',n u m 2 s t r ( t 0 ) ] ) a x i s ( [ m i n ( x x ),m a x ( x x ),- h,h ] )
i f p l t s a v, p r i n t ( g c f,'- d e p s','s t r n g y x t 0'); end drawnow, s hg
d i s p (' ')
d i s p ('P r e s s r e t u r n t o s e e t h e d e f l e c t i o n h i s t o r y')
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
d i s p ( ['a t x = ',num2st r (x0)]), p a u s e
px0=strngwav(xd,pd,x0,tplot ,l e n,a ) ; p l o t ( t p l o t,y x 0,'k') x l a b e l ('t i m e'), p l a b e l ('p ( x 0,t )') t i t l e (...
['DEFLECTION HISTORY AT X = ',n u m 2 s t r ( x 0 ) ] ) a x i s ( [ 0,m a x ( t ),- h,h ] )
i f p l t s a v, p r i n t ( g c f,'- d e p s','s t r n g y x 0 t'); end drawnow, s hg
d i s p (' ')
d i s p ('P r e s s r e t u r n t o s e e t h e a n i m a t i o n') d i s p ('o v e r t wo p e r i o d s of m o t i o n'), p a u s e x = l i n s p a c e ( 0,l e n,1 0 1 ); t = l i n s p a c e ( 0,4 * l e n/a,1 2 1 ); [ Y,X,T ] = s t r n g w a v ( x d,p d,x,t,l e n,a ); t i t l ='MOTI ON OVER TWO PERIODS'; a n i m a t e ( X ( 1,:),Y',t i t l,.1 ), p a u s e ( 2 )
i f p l t s a v, p r i n t ( g c f,'- d e p s','s t r n g a n i m'); end
d i s p (' '), d i s p ('A l l Done')
%== ========================== ===================
f u n c t i o n [ Y,X,T ] = s t r n g w a v ( x d,p d,x,t,l e n,a )
%
% [ Y,X,T ] = s t r n g w a v ( x d,p d,x,t,l e n,a )
%..................................................................................
% Th i s f u n c t i o n computes t h e dpnamic r e s p o n s e of % a t i g h t l p s t r e t c h e d s t r i n g r e l e a s e d f r o m r e s t % w i t h a p i e c e w i s e l i n e a r i n i t i a l d e f l e c t i o n. The % s t r i n g e n d s a r e f i x e d.
%
% x d,p d - d a t a v e c t o r s d e f i n i n g t h e i n i t i a l % d e f l e c t i o n a s a p i e c e w i s e l i n e a r
% f u n c t i o n. xd v a l u e s s h o u l d be i n c r e a s i n g
% and l i e b e t we e n 0 and l e n
% x,t - p o s i t i o n and t i me v e c t o r s f o r whi ch t h e
% s o l u t i o n i s e v a l u a t e d
% l e n,a - s t r i n g l e n g t h and wave s p e e d
i f n a r g i n < 6, a=1; end; i f n a r g i n <5, l e n = 1; end x d = x d (:); p d = p d (:); p =2 * l e n;
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
% If end values are not zero, add these points i f xd(end)~=len, xd=[xd;len]; pd=[pd;0]; end i f xd(1)~=0, xd=[0;xd]; pd=[0;pd]; end nd=length(xd);
% Eliminate anp repeated absci ssa v a l u e s k = f i n d ( d i f f ( x d ) = = 0 ); t i n p = l e n/1 e 6; i f l e n g t h ( k ) > 0, x d ( k ) = x d ( k ) + t i n p; end
% E x t e n d t h e d a t a d e f i n i t i o n f o r l e n < x < 2 * l e n x d = [ x d;p - x d ( n d - 1:- 1:1 ) ]; p d = [ p d;- p d ( n d - 1:- 1:1 ) ]; [ X,T ] = m e s h g r i d ( x,t ); xp=X+a*T; xm=X-a*T; s h a p e = s i z e ( x p ); x p = x p (:); xm=xm(:);
% C o m p u t e t h e g e n e r a l s o l u t i o n f o r a p i e c e w i s e % l i n e a r i n i t i a l d e f l e c t i o n
Y = ( s i g n ( x p ).* i n t e r p 1 ( x d,p d,r e m ( a b s ( x p ),p ),... 'l i n e a r','e x t r a p') + s i g n ( x m ).* i n t e r p 1 ( x d,p d,... r e m ( a b s ( x m ),p ),'l i n e a r','e x t r a p') )/2; Y= r e s h a p e ( Y,s h a p e );
%== ========================== ===================
f u n c t i o n a n i m a t e ( x,p,t i t l,t i m,t r a c e )
%
% a l i m a t e ( x,p,t i t l,t i m,t r a c e )
%.....................................................................
% Th i s f u n c t i o n p e r f o r ms a n i m a t i o n of a 2D c u r v e % x,p - a r r a p s w i t h columns c o n t a i n i n g c u r v e p o s i t i o n s % f o r s u c c e s s i v e t i m e s. x c a n a l s o be a s i n g l e
% v e c t o r i f x v a l u e s do n o t c h a n g e. The a n i ma t i o n
% i s done bp p l o t t i n g ( x (:,j ),p (:,j ) ) f o r
% j = 1:s i z e ( p,2 ).
% t i t l - t i t l e f o r t h e g r a p h
% t i m - t h e t i me i n s e c o n d s b e t we e n s u c c e s s i v e p l o t s
i f n a r g i n < 5, t r a c e = 0; e l s e, t r a c e = 1; end; i f n a r g i n < 4, t i m=.0 5; end
i f n a r g i n < 3, t r a c =''; e nd; [ n p,n t ] = s i z e ( p ); i f m i n ( s i z e ( x ) ) = = 1, j = o n e s ( 1,n t ); x = x (:); e l s e, j = 1:n t; e nd; a x =ne wpl ot; i f t r a c e, XOR='none'; e l s e, XOR='xor'; end r = [ m i n ( x (:) ),m a x ( x (:) ),m i n ( p (:) ),m a x ( p (:) ) ]; % a x i s ('e q u a l') % Needed f o r an u n d i s t o r t e d p l o t a x i s ( r ), % a x i s ('o f f')
1 7 6: c u r v e = l i n e ('c o l o r','k','l i n e s t p l e','-',...
1 7 7: 'e r a s e',X O R, 'x d a t a',[ ],'p d a t a',[ ] );
1 7 8: x l a b e l ('x a x i s'), p l a b e l ('p a x i s'), t i t l e ( t i t l ) 179: f o r k = 1:n t
1 8 0: s e t ( c u r v e,'x d a t a',x (:,j ( k ) ) ,'p d a t a' ,p (: ,k ) )
1 8 1: i f t i m>0, p a u s e ( t i m ), e nd, dr awnow, s h g
1 8 2: end
183:
184: %==============================================
185:
1 8 6: % f u n c t i o n v a r a r g o u t = i n p u t v ( p r o m p t )
1 8 7: % S e e A p p e n d i x B
2.8 Properties of Curves and Surfaces
In t hi s sect i on some pr oper t i es of space cur ves and surf aces ar e st udi ed. Exam­
pl es i l l ust r at i ng t he graphi cs capabi l i t i es of MATLAB t o descr i be t hree-di mensi onal geomet r i es ar e gi ven. Reader s shoul d al so st udy t he demo exampl es and i nt r i nsi c document at i on on funct i ons such as pl ot 3, s ur f, and me s h t o appr eci at e t he weal t h of pl ot t i ng opt i ons avai l abl e.
2.8.1 Curve Properti es
A space cur ve is a one- di mensi onal regi on r epr esent abl e i n par amet r i c f or m as
R(t) = i x(t) + j y(t) + k z(t) , a <t <b
wher e I, j, k are Cartesian base vectors, and t is a scalar parameter such as arc length
s or time. At each point on the curve, differential properties naturally lead to a triad
of orthonormal base vectors T, N, and B called the tangent, the principal normal, and the binormal. The normal vector points toward the center of curvature and the binormal is defined by T x N to complete the triad. Coordinate planes associated with the triad are the normal plane containing N and B, the tangent plane containing T and B, and the osculating plane containing T and N. Two other scalar properties of interest are the curvature κ (the reciprocal of the curvature radius) and the torsion τ, which quantifies the rate at which the triad twists about the direction of T as a generic point moves along the curve. When a curve is parameterized in terms of arc length s, the five quantities just mentioned are related by the Frenet formulas [91] which are
dT d B dN
—— = kN , —— = - r N , —— = —nT + t B.
ds ds ds
Since most curves are not easily parameterized in terms of arc length, more conve­
nient formulas are needed for computing T, N, B, κ, and τ. All the desired quanti­
ties can be found in terms of R'(t ), R''(t), and R'''(t). Among the five properties,
only torsion, τ, depends on R'''(t). The pertinent formulas are
and
R'{t) - _ R'(t) x R"{t)
\R'(t)\ ’ ~~ \R'( t ) x R"( t )|
|R'{t) x R"{t )|
* | Λ'(*)Ι3
B · ^"'( t )
N = B x T
| R'( t ) x R'(t)|' When the independent variable t means time we get
dR ds dR V = velocity = —— = —— — dt dt ds
v T
wher e v is the magnitude of velocity called speed. Differentiating again leads to
dV dv - 2 ~
—— = acceleration = — Τ + κι^Ν
dt dt
so the acceleration involves a tangential component with magnitude equal to the time rate of change of speed, and a normal component of magnitude κ ν 2 directed toward the center of curvature. The torsion is only encountered when the time derivative of acceleration is considered. This is seldom of interest in Newtonian mechanics.
A function crvprp3d was written to evaluate T, N, B, κ, and τ in terms of R'(t ), R''(t), and R''' (t). Another function aspiral applies crvprp3d to the curve de­
scribed by
R(t) = [(To + kt)cos(t); (ro + kt)sin(t); ht]
wher e t is the polar coordinate angle for cylindrical coordinates.
Figure 2.14 depicts results generated from the default data set where
ro = 2 π , k = 1 , h = 2 , 2 π < t < 8 π,
with 101 data points being used. A cross section normal to the surface would produce a right angle describing the directions of the normal and binormal at a typical point. The spiral itself passes along the apex of the right angle. This surface illustrates how the intrinsic triad of base vectors changes position and direction as a point moves along the curve.
An additional function crvprpsp was written to test how well cubic spline in­
terpolation approximates curve properties for the spiral. MATLAB provides func­
tion spline to connect data points by a piecewise cubic interpolation curve having continuous first and second derivatives [27]. This function utilizes other intrinsic functions1 such as unmkpp, mkpp, and ppval. Although basic MATLAB does not
1These functions are included with MATLAB and are a subset of the more comprehensive Spline Toolbox also available from The MathWorks.
Spiral Showing Osculating and Rectifying Planes
Figure 2.14: Spiral Showing Osculating and Rectifying Planes
include functions for spline differentiation, this can be remedied by the short func­
tion splined which computes first and second derivatives of the interpolation curve defined by function spline. In our example using spline interpolation, approxima­
tion of τ was not obtained because a cubic spline only has its first two derivatives continuous. Approximations for R'"( t )
could have been generated by interpolat­
ing the computed values of R'( t )
and differentiating the results twice. That idea was not explored. To assess the accuracy of the spline interpolation, values for norm(B — and |(k — kappr„
)/k\
were obtained at 101 sample points along
the curve. Results depicted in
Figure 2.15 show errors in the third decimal place except near the ends of the interpolation interval where a “not a knot” boundary condition is employed [27].
error measure
Error Plot
point index
Figure 2.15: Error Plot
Program Output and Code Program splinerr
i: f u n c t i o n s p l i n e r r 2: % Example: s p l i n e r r
3: %...........................................................................
4: %
5: % T h i s p r o g r a m c a l c u l a t e s t h e b i n o r m a l and 6: % c u r v a t u r e e r r o r f o r a s p i r a l s p a c e c u r v e.
7: %
8: % U s er m f u n c t i o n s c a l l e d:
9: % a s p i r a l, c r v p r p s p c r v p r p 3 d c u b r a n g e s p l i n e d
10: %-----------------------------------------------------------------------------------------------------------------------------------------------------
11:
i 2: c l e a r; h o l d o f f; c l f; i 3: [ R,T,N,B,K A P ] = a s p i r a l; m = s i z e ( R,2 ); i 4: [ r,t,n,b,k ] = c r v p r p s p ( R,m ); i 5: d i s p (' '); d i s p (...
i 6: 'P r e s s [ E n t e r ] t o show e r r o r c u r v e s'); p a u s e i 7: e r r v = s q r t ( s u m ( ( B - b ).~ 2 ) ); i 8: e r r k = a b s ( ( K A P - k )./K A P ); h o l d o f f; c l f; i 9: s e m i l o g y ( 1:m,e r r v,'k -',1:m,e r r k,'k —') ;
2 0: x l a b e l ('p o i n t i n d e x'); y l a b e l ('e r r o r m e a s u r e'); 2 i: t i t l e ('E r r o r P l o t');
2 2: l e g e n d ('B i n o r m a l e r r o r','C u r v a t u r e e r r o r',3 );
23: f i g u r e ( g c f ); d i s p (' ')
24: d i s p ('P r e s s [ E n t e r ] t o f i n i s h'); p a u s e 25: d i s p (' '), d i s p ('A l l d o n e'), d i s p (' ')
26:
27: % ========================= = === === ===== === === ===
28:
29: f u n c t i o n [ R,T,N,B,k a p,t a u,a r c l e n ] = ...
30: a s p i r a l ( r 0,k,h,t )
3 i: %
3 2: % [ R,T,N,B,k a p,t a u,a r c l e n ] = a s p i r a l ( r 0,k,h,t )
33: %
34: %
35: % T h i s f u n c t i o n computes g e o m e t r i c a l p r o p e r t i e s 36: % o f a s p i r a l c u r v e h a v i n g t h e p a r a m e t r i c 37: % e q u a t i o n
38: %
3 9: % R = [ ( r 0 + k * t ) * c o s ( t );( r 0 + k * t ) * s i n ( t );h * t ]
40: %
4 i
42
43:
44
45
46
47
48
49
50:
5 i:
52
53:
54:
55
56
57:
58:
59
60:
6 i:
62
63:
64:
65
66
67:
68:
69
70:
7 i
72
73:
74:
75
76
77
78:
79
80:
8 i
82
83:
84
85
% A f i g u r e showi ng t h e c u r v e a l o n g w i t h t h e % o s c u l a t i n g p l a n e and t h e r e c t i f y i n g p l a n e % a t e a c h p o i n t i s a l s o drawn.
%
% r 0,k,h - p a r a m e t e r s whi ch d e f i n e t h e s p i r a l
% t - a v e c t o r o f p a r a m e t e r v a l u e s a t
% whi ch t h e c u r v e i s e v a l u a t e d fr o m
% t h e p a r a m e t r i c f o r m.
%
% R - m a t r i x w i t h columns c o n t a i n i n g
% p o s i t i o n v e c t o r s f o r p o i n t s on t h e
% c u r v e
% T,N,B - m a t r i c e s w i t h columns c o n t a i n i n g t h e % t a n g e n t,n o r m a l,a n d b i n o r m a l v e c t o r s
% kap - v e c t o r o f c u r v a t u r e v a l u e s
% t a u - v e c t o r o f t o r s i o n v a l u e s
% a r c l e n - v a l u e o f a r c l e n g t h a p p r o x i m a t e d a s % t h e sum o f c h o r d v a l u e s b e t w e e n
% s u c c e s s i v e p o i n t s
%
% U s er m f u n c t i o n s c a l l e d:
% c r v p r p 3 d, c u b r a n g e
%-----------------------------------------------------------------------------------------
i f n a r g i n = = 0
k=1; h=2; r 0 = 2 * p i; t = l i n s p a c e ( 2 * p i,8 * p i,1 0 1 ); end
% E v a l u a t e R, R'( t ), R''( t ) and R'''( t ) f o r % t h e s p i r a l
t = t (:)'; s = s i n ( t ); c = c o s ( t ); k c =k*c; k s = k * s; r k = r 0 + k * t; r k s = r k.* s; r k c = r k.* c; n = l e n g t h ( t ); R = [ r k c;r k s;h * t ]; R 1 = [ k c - r k s;k s + r k c;h * o n e s ( 1,n ) ]; R 2 = [ - 2 * k s - r k c;2 * k c - r k s;z e r o s ( 1,n ) ]; R 3 = [ - 3 * k c + r k s;- 3 * k s - r k c;z e r o s ( 1,n ) ];
% O b t a i n g e o m e t r i c a l p r o p e r t i e s [ T,N,B,k a p,t a u ] = c r v p r p 3 d ( R 1,R 2,R 3 ); a r c l e n = s u m ( s q r t ( s u m ( ( R (:,2:n ) - R (:,1:n - 1 ) ).~ 2 ) ) );
% G e n e r a t e p o i n t s on t h e o s c u l a t i n g p l a n e and % t h e r e c t i f y i n g p l a n e a l o n g t h e c u r v e. w = a r c l e n/1 0 0; Rn=R+w*N; Rb=R+w*B; X = [ R n ( 1,:);R ( 1,:);R b ( 1,:) ]; Y = [ R n ( 2,:);R ( 2,:);R b ( 2,:) ];
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
Z = [ R n ( 3,:);R ( 3,:);R b ( 3,:) ];
% Draw t h e s u r f a c e
v = c u b r a n g e ( [ X (:),Y (:),Z (:) ] ); h o l d o f f; c l f; c l o s e; s u r f ( X,Y,Z ); a x i s ( v ); x l a b e l ('x a x i s'); y l a b e l ('y a x i s'); z l a b e l ('z a x i s'); t i t l e ( ['S p i r a l Showing O s c u l a t i n g and ', ...
'R e c t i f y i n g P l a n e s'] ); g r i d on; drawnow; f i g u r e ( g c f );
%==============================================
f u n c t i o n [ T,N,B,k a p,t a u ] = c r v p r p 3 d ( R 1,R 2,R 3 )
%
% [ T,N,B,k a p,t a u ] = c r v p r p 3 d ( R 1,R 2,R 3 )
%.......................................................................................
%
% T h i s f u n c t i o n computes t h e p r i m a r y % d i f f e r e n t i a l p r o p e r t i e s o f a t h r e e - d i m e n s i o n a l % c u r v e p a r a m e t e r i z e d i n t h e f o r m R ( t ) where t % c a n be a r c l e n g t h o r any o t h e r c o n v e n i e n t % p a r a m e t e r s u c h a s t i m e.
%
% R1 - t h e m a t r i x w i t h columns c o n t a i n i n g R'( t )
% R2 - t h e m a t r i x w i t h columns c o n t a i n i n g R''( t )
% R3 - t h e m a t r i x w i t h columns c o n t a i n i n g % R'''( t ). T h i s m a t r i x i s o n l y n e e d e d
% when t o r s i o n i s t o be computed.
%
% T - m a t r i x w i t h columns c o n t a i n i n g t h e % u n i t t a n g e n t
% N - m a t r i x w i t h columns c o n t a i n i n g t h e % p r i n c i p a l n o r m a l v e c t o r
% B - m a t r i x w i t h columns c o n t a i n i n g t h e % b i n o r m a l
% kap - v e c t o r o f c u r v a t u r e v a l u e s % t a u - v e c t o r o f t o r s i o n v a l u e s. T h i s e q u a l s % [] when R3 i s n o t g i v e n
%
% U s er m f u n c t i o n s c a l l e d: none
%-----------------------------------------------------------------------------------------
n r 1 = s q r t ( d o t ( R 1,R 1 ) ); T = R 1./n r 1 ( o n e s ( 3,1 ),:); R 1 2 = c r o s s ( R 1,R 2 ); n r 1 2 = s q r t ( d o t ( R 1 2,R 1 2 ) ); B = R 1 2./n r 1 2 ( o n e s ( 3,1 ),:); N = c r o s s ( B,T );
131
132
133
134
135 i 3 6: i 3 7 i 3 8: i 3 9: i 4 0: i 4 i: i 4 2: i 4 3: i 4 4: i 4 5: i 4 6: i 4 7 i 4 8: i 4 9: i 5 0: i 5 i: i 5 2: i 5 3: i 5 4: i 5 5: i 5 6: i 5 7: i 5 8: i 5 9: i 6 0: i 6 i: i 6 2: i 6 3: i 6 4: i 6 5: i 6 6: i 6 7: i 6 8: i 6 9: i 7 0: i 7 i: i 7 2: i 7 3: i 7 4: i 7 5:
k a p = n r 1 2./n r 1.~ 3;
% Compute t h e t o r s i o n o n l y when R'''( t ) i s g i v e n i f n a r g i n = = 3, t a u = d o t ( B,R 3 )./n r 1 2; e l s e, t a u = [ ]; end
%==============================================
f u n c t i o n [ R,T,N,B,k a p p a ] = c r v p r p s p ( R d,n )
%
% [ R,T,N,B,k a p p a ] = c r v p r p s p ( R d,n )
%.............................................................................
%
% T h i s f u n c t i o n computes s p l i n e i n t e r p o l a t e d % v a l u e s f o r c o o r d i n a t e s, b a s e v e c t o r s and % c u r v a t u r e o b t a i n e d by p a s s i n g a s p l i n e c u r v e % t h r o u g h d a t a v a l u e s g i v e n i n Rd.
%
% Rd - a m a t r i x c o n t a i n i n g x,y and z v a l u e s
% i n rows 1, 2 and 3.
% n - t h e number o f p o i n t s a t whi ch
% p r o p e r t i e s a r e t o be e v a l u a t e d a l o n g
% t h e c u r v e
%
% R - a 3 by n m a t r i x w i t h columns
% c o n t a i n i n g c o o r d i n a t e s o f i n t e r p o l a t e d
% p o i n t s on t h e c u r v e
% T,N,B - m a t r i c e s o f d i m e n s i o n 3 by n w i t h % columns c o n t a i n i n g components o f t h e
% u n i t t a n g e n t, u n i t n o r m a l, and u n i t
% b i n o r m a l v e c t o r s
% k a p p a - a v e c t o r o f c u r v a t u r e v a l u e s %
% U s er m f u n c t i o n s c a l l e d:
% s p l i n e d, c r v p r p 3 d
%-----------------------------------------------------------------------------------------
% C r e a t e a s p l i n e c u r v e t h r o u g h t h e d a t a p o i n t s, % and e v a l u a t e t h e d e r i v a t i v e s o f R. n d = s i z e ( R d,2 ); t d = 0:n d - 1; t = l i n s p a c e ( 0,n d - 1,n ); u d = R d ( 1,:) + i * R d ( 2,:); u = s p l i n e ( t d,u d,t ); u 1 = s p l i n e d ( t d,u d,t ); u 2 = s p l i n e d ( t d,u d,t,2 ); u d 3 = R d ( 3,:); z = s p l i n e ( t d,u d 3,t ); z 1 = s p l i n e d ( t d,u d 3,t ); z 2 = s p l i n e d ( t d,u d 3,t,2 ); R = [ r e a l ( u );i m a g ( u );z ]; R 1 = [ r e a l ( u 1 );i m a g ( u 1 );z 1 ];
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
R 2 = [ r e a l ( u 2 );i m a g ( u 2 );z 2 ];
% Get c u r v e p r o p e r t i e s f r o m c r v p r p 3 d [ T,N,B,k a p p a ] = c r v p r p 3 d ( R 1,R 2 );
%=============================================
f u n c t i o n v a l = s p l i n e d ( x d,y d,x,i f 2 )
%
% v a l = s p l i n e d ( x d,y d,x,i f 2 )
%.............................................................
%
% T h i s f u n c t i o n e v a l u a t e s t h e f i r s t o r s e c o n d % d e r i v a t i v e o f t h e p i e c e w i s e c u b i c % i n t e r p o l a t i o n c u r v e d e f i n e d by t h e i n t r i n s i c % f u n c t i o n s p l i n e p r o v i d e d i n MATLAB.If f e w e r % t h a n f o u r d a t a p o i n t s a r e i n p u t, t h e n s i m p l e % p o l y n o m i a l i n t e r p o l a t i o n i s employed %
% x d,y d - d a t a v e c t o r s d e t e r m i n i n g t h e s p l i n e
% c u r v e p r o d u c e d by f u n c t i o n s p l i n e
% x - v e c t o r o f v a l u e s where t h e f i r s t o r % t h e s e c o n d d e r i v a t i v e a r e d e s i r e d
% i f 2 - a p a r a m e t e r whi ch i s i n p u t o n l y i f % y''( x ) i s r e q u i r e d. O t h e r w i s e, y'( x )
% i s r e t u r n e d.
%
% v a l - t h e f i r s t o r s e c o n d d e r i v a t i v e v a l u e s
% f o r t h e s p l i n e
%
% U s er m f u n c t i o n s c a l l e d: none
n = l e n g t h ( x d ); [ b,c ] = u n m k p p ( s p l i n e ( x d,y d ) ); i f n>3 % Use a c u b i c s p l i n e
i f n a r g i n = = 3, c = [ 3 * c (:,1 ),2 * c (:,2 ),c (:,3 ) ]; e l s e, c = [ 6 * c (:,1 ),2 * c (:,2 ) ]; end v a l = p p v a l ( m k p p ( b,c ),x ); e l s e % Use a s i m p l e p o l y n o m i a l
c = p o l y d e r ( p o l y f i t ( x d (:),y d (:),n - 1 ) ); i f n a r g i n = = 4, c = p o l y d e r ( c ); end v a l = p o l y v a l ( c,x ); end
%
221: % f u n c t i o n r a n g e = c u b r a n g e ( x y z,o v r s i z )
222: % See Appe ndix B
2.8.2 Surface Properties
Surfaces are two-dimensional regions described parametrically as
R(u, v) = ix(u, v) + j u( u, v) + kz(u, v)
wher e 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 fixed while u varies generates a curve in the surface called a u coordinate line. A tangent vector to the u-line is given by
dR „dx „dy - dz
9u = = it - +3 t~ + k —.
du du du du
Si mi l ar l y, hol di ng u fixed and varying v produces a v-line with tangent vector
dR „ dx „dy - dz 9v l· h
dv dv dv dv
Consider the following cross product.
gu x gv dudv = n dS.
In this equation n is the unit surface normal and dS is the area of a parallelogram shaped surface element having sides defined by gu du and gv dv.
The i nt r i nsi c funct i ons sur f ( X,Y,Z) and mesh(X,Y,Z) depi ct surfaces by showi ng a gr i d net wor k and r el at ed surf ace pat ches char act er i zed when par amet er s u and v are varied over constant limits. Thus, values
(ut, v3) , 1 < i < n , 1 < j < m
l ead t o mat ri ces
X = [x(ul, v)\ , Y = [y(ul, v3)\ , Z = [z(ul, 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 — § <#< §, —π < φ < π. The surface equation evidently satisfies the familiar equation
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 - π < θ < π , - π < φ < π.
Thi s t ype of equat i on is us ed bel ow i n an exampl e i nvol vi ng sever al bodi es. Let us al so pr oduce a surf ace coveri ng t he ends and si de of a coni cal fr ust um (a cone wi t h t he t op cut off). The f r ust um has base radi us r b, top radius rt, 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
rs = + (rb - rt )2 .
Let us take 0 < s < (rb + rs + rt ) 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 < rb
, , (n - n) ( s - rb) h ( s - rb)
r(s) = rb H-------------------------, s = , rb < s < (rb + rs)
rs rs
r(s) = rb + rs + rt - r , z = h , (rb + rs) < s < (rb + rs + rt ) .
The function frus produces a grid of points on the surface in terms of r b, rt, 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 finding a data range to include all points and then plotting each surface in succession using the h o l d 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 = i x + j y + kz
Spike and Intersecting Toruses
undergoes a coordinate change which moves the initial coordinate origin to (X o,Yo,Z o) and moves the base vectors I, j, k into ei, e2, e3. Then the endpoint of r passes to
R = IX + j Y + k Z = Ro + e ix + e2y + e3z
where
Ro = iXo + jYo + kZo .
Let us specify the directions of the new base vectors by employing the columns of a matrix V where we take
_ y (:,l )
3 nor m[ Vr(:, 1) ] '
I f V (:, 2) exists we take V (:, 1) x V (:, 2) and unitize this vector to produce e2. The triad is completed by taking e 1 = e2 x e3. 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.
z axis
SEVERAL SURFACES COMBINED
Figure 2.17: Surface With Six Legs
z axis
ROTATED AND TRANSLATED ELLIPSOID
Figure 2.18: Rotated and Translated Ellipsoid Surfaces
2.8.3 Program Output and Code Function srfex
i: f u n c t i o n [ x 1,y 1,x 2,y 2,x 3,y 3,x f,y f,z f ] = ...
2: s r f e x ( d a,n a,d f,n f )
3: % [ x 1,y 1,x 2,y 2,x 3,y 3,x f,y f,z f ] = ...
4: % s r f e x ( d a,n a,d f,n f )
5: %....................................................................................................................
6: %
7: % T h i s g r a p h i c s example draws t h r e e t o r u s e s 8: % i n t e r s e c t i n g a s p i k e.
9: %
i o: % U s er m f u n c t i o n s c a l l e d: f r u s, s u r f m a n y
11:
i 2: i f n a r g i n = = 0
i 3: d a = [ 4.0,.4 5 ]; n a = [ 4 2,1 5 ];
i 4: d f = [ 2.2,0,1 5 ]; n f = [ 4 3,4 ];
i 5: end
i6:
i 7: % C r e a t e a t o r u s w i t h p o l y g o n a l c r o s s s e c t i o n.
i 8: % D a t a f o r t h e t o r u s i s s t o r e d i n d a and n a
i9:
2 0: r 0 = d a ( 1 ); r 1 = d a ( 2 ); n f a c e s = n a ( 1 ); n l a t = n a ( 2 );
2 i: t = l i n s p a c e ( 0,2 * p i,n l a t )';
2 2: x z = [ r 0 + r 1 * c o s ( t ),r 1 * s i n ( t ) ] ;
23: z 1 = x z (:,2 ); z 1 = z 1 (:,o n e s ( 1,n f a c e s + 1 ) );
24: t h = l i n s p a c e ( 0,2 * p i,n f a c e s + 1 );
25: x 1 = x z (:,1 ) * c o s ( t h ); y 1 = x z (:,1 ) * s i n ( t h );
2 6: y2=x1; z2=y1; x2=z1; y3=x2; z3=y2; x3=z2;
27:
2 8: % C r e a t e a f r u s t u m o f a p y r a m i d. D a t a f o r t h e 29: % f r u s t u m i s s t o r e d i n d f and n f 30: r b = d f ( 1 ); r t = d f ( 2 ); h = d f ( 3 );
3 i: [ x f,y f,z f ] = f r u s ( r b,r t,h,n f ); z f = z f -.3 5 * h;
32:
3 3: % P l o t f o u r f i g u r e s combined t o g e t h e r 34: h o l d o f f; c l f; c l o s e;
35: s u r f m a n y ( x 1,y 1,z 1,x 2,y 2,z 2,x 3,y 3,z 3,x f,y f,z f )
36: x l a b e l ('x a x i s'); y l a b e l ('y a x i s');
3 7: z l a b e l ('z a x i s');
38: t i t l e ('S p i k e and I n t e r s e c t i n g T o r u s e s');
39: a x i s e q u a l; a x i s ('o f f');
40: c o l o r m a p ( [ 1 1 1 ] ); f i g u r e ( g c f ); h o l d o f f;
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
74
75
76
77
78
79
80
81
82
83
84
85
% p r i n t - d e p s s r f e x %=============================================
f u n c t i o n [ X,Y,Z ] = f r u s ( r b,r t,h,n,n o p l o t )
%
% [ X,Y,Z ] = f r u s ( r b,r t,h,n,n o p l o t )
%.............................................................................
%
% T h i s f u n c t i o n computes p o i n t s on t h e s u r f a c e % o f a c o n i c a l f r u s t u m whi ch h a s i t s a x i s a l o n g % t h e z a x i s.
%
% r b,r t,h - t h e b a s e r a d i u s,t o p r a d i u s and
% h e i g h t
% n - v e c t o r o f two i n t e g e r s d e f i n i n g t h e
% a x i a l and c i r c u m f e r e n t i a l g r i d
% i n c r e m e n t s on t h e s u r f a c e
% n o p l o t - p a r a m e t e r i n p u t when no p l o t i s % d e s i r e d
%
% X,Y,Z - p o i n t s on t h e s u r f a c e %
% U s e r m f u n c t i o n s c a l l e d: none
i f n a r g i n = = 0
r b = 2; r t = 1; h=3; n = [ 2 3, 3 5 ]; end
t h = l i n s p a c e ( 0,2 * p i,n ( 2 ) + 1 )'- p i/n ( 2 );
s l = s q r t ( h ~ 2 + ( r b - r t ) ~ 2 ); s = s l + r b + r t;
m = c e i l ( n ( 1 )/s * [ r b,s l,r t ] );
r b o t = l i n s p a c e ( 0,r b,m ( 1 ) );
r s i d e = l i n s p a c e ( r b,r t,m ( 2 ) );
r t o p = l i n s p a c e ( r t,0,m ( 3 ) );
r = [ r b o t,r s i d e ( 2:e n d ),r t o p ( 2:e n d ) ];
h b o t = z e r o s ( 1,m ( 1 ) );
h s i d e = l i n s p a c e ( 0,h,m ( 2 ) );
h t o p = h * o n e s ( 1,m ( 3 ) );
H = [ h b o t,h s i d e ( 2:e n d ),h t o p ( 2:e n d ) ];
Z = r e p m a t ( H,n ( 2 ) + 1,1 );
x y = e x p ( i * t h ) * r; X = r e a l ( x y ); Y= imag( xy); i f n a r g i n < 5
s u r f ( X,Y,Z ); t i t l e ('F r u s t u m'); x l a b e l ('x a x i s') y l a b e l ('y a x i s'), z l a b e l ('z a x i s')
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
g r i d o n, c o l o r m a p ( [ 1 1 1 ] ); f i g u r e ( g c f ); end
%===========================================
f u n c t i o n s u r f m a n y ( v a r a r g i n )
% f u n c t i o n s u r f m a n y ( x 1,y 1,z 1,x 2,y 2,z 2,...
% x 3,y 3,z 3,..,x n,y n,z n )
% T h i s f u n c t i o n p l o t s any number o f s u r f a c e s % on t h e same s e t o f a x e s w i t h o u t s h a p e % d i s t o r t i o n. When no i n p u t i s g i v e n t h e n a % s i x - l e g g e d s o l i d composed o f s p h e r e s and % c y l i n d e r s i s shown.
%
% U s er m f u n c t i o n s c a l l e d: none %-----------------------------------------------------------------------------------
i f n a r g i n = = 0
% D e f a u l t d a t a f o r a s i x - l e g g e d s o l i d n=10; r s =.2 5; d=7; r s = 2; r c =.7 5; [ x s,y s,z s ] = s p h e r e; [ x c,y c,z c ] = c y l i n d e r; x s = r s * x s; y s = r s * y s; z s = r s * z s; x c = r c * x c; y c = r c * y c; z c = 2 * d * z c - d; x 1 = x s; y 1 = y s; z 1 = z s; x 2=zs+ d; y2 = y s; z2 = x s; x 3 = z s - d; y3 = y s; z3 = x s; x 4 = x s; y 4 = z s - d; z4 = y s; x 5 = x s; y5= zs+ d; z5 = y s; x 6 = x s; y 6 = y s; z 6= z s+d; x 7 = x s; y 7 = y s; z 7 = z s - d; x8=xc; y8=yc; z 8 = z c; x 9 = z c; y9=xc; z9=yc; x 10=yc; y 1 0=zc; z10=xc; v a r a r g i n = { x 1,y 1,z 1,x 2,y 2,z 2,x 3,y 3,z 3,... x 4,y 4,z 4,x 5,y 5,z 5,x 6,y 6,z 6,x 7,y 7,z 7,... x 8,y 8,z 8,x 9,y 9,z 9,x 1 0,y 1 0,z 1 0 }; end
% F i n d t h e d a t a r a n g e
n = l e n g t h ( v a r a r g i n );
r = r e a l m a x * [ 1,- 1,1,- 1,1,- 1 ];
s = i n l i n e ('m i n ( [ a;b ] )','a','b');
b = i n l i n e ('m a x ( [ a;b ] )','a','b');
f o r k = 1:3:n
1 3 1: x = v a r a r g i n { k }; y = v a r a r g i n { k + 1 };
132: z = v a r a r g i n { k + 2 };
133: x = x (:); y = y (:); z = z (:);
134: r ( 1 ) = s ( r ( l ),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: % P l o t e a c h s u r f a c e 140: h o l d o f f, n e w p l o t 141: f o r k = 1:3:n
142: x = v a r a r g i n { k }; y = v a r a r g i n { k + 1 };
143: z = v a r a r g i n { k + 2 };
144: s u r f ( x,y,z ); a x i s ( r ), h o l d on
145: end 146:
147: % S e t a x e s and d i s p l a y t h e combined p l o t
148: a x i s e q u a l, a x i s ( r ), g r i d on
149: x l a b e l ('x a x i s'), y l a b e l ('y a x i s')
150: z l a b e l ('z a x i s')
151: t i t l e ('S E V E R A L SURFACES COMBINED')
152: % c o l o r m a p ( [ 1 2 7/2 5 5 1 2 1 2/2 5 5 ] ); % a q u a m a r i n e 153: c o l o r m a p ( [ 1 1 1 ] );, f i g u r e ( g c f ), h o l d o f f Function rgdbodmo
f u n c t i o n [ X,Y,Z ] = r g d b o d m o ( x,y,z,v,R 0 )
%
% [ X,Y,Z ] = r g d b o d m o ( x,y,z,v,R 0 )
%........................................................................
%
% T h i s f u n c t i o n t r a n s f o r m s c o o r d i n a t e s x,y,z t o % new c o o r d i n a t e s X,Y,Z by r o t a t i n g and % t r a n s l a t i n g t h e r e f e r e n c e f r a m e s. When no % i n p u t i s g i v e n, an example i n v o l v i n g an % e l l i p s o i d i s r u n.
%
% x,y,z - i n i t i a l c o o r d i n a t e m a t r i c e s r e f e r r e d % t o b a s e v e c t o r s [ 1;0;0 ], [ 0;1;0 ] and
% [ 0;0;1 ]. Columns o f v a r e u s e d t o
% c r e a t e new b a s i s v e c t o r s i,j,k s u c h
% t h a t a t y p i c a l p o i n t [ a;b;c ] i s
% t r a n s f o r m e d i n t o [A;B;C] a c c o r d i n g
% t o t h e e q u a t i o n
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
% [ A;B;C ] = R 0 (:) + [ i,j,k ] * [ a;b;c ]
% v - a m a t r i x h a v i n g t h r e e rows and e i t h e r
% one o r two columns u s e d t o c o n s t r u c t
% t h e new b a s i s [ i,j,k ] a c c o r d i n g t o
% met hods employed f u n c t i o n r o t a t r a n
% R0 - a v e c t o r whi ch t r a n s l a t e s t h e r o t a t e d
% c o o r d i n a t e s when R0 i s i n p u t.
% O t h e r w i s e no t r a n s l a t i o n i s i m p o s ed.
%
% X,Y,Z - m a t r i c e s c o n t a i n i n g t h e t r a n s f o r m e d % c o o r d i n a t e s
%
% U s er m f u n c t i o n s c a l l e d: e l i p s o i d, r o t a t r a n
i f n a r g i n = = 0
[ x,y,z ] = e l i p s o i d ( 1,1,2,[ 1 7,3 3 ],0 );R 0 = [ 3;4;5 ];
v = [ [ 1;1;1 ],[ 1;1;0 ] ];
end
[ n,m ] = s i z e ( x ); X Y Z = [ x (:),y (:),z (:) ] * r o t a t r a n ( v )'; X=XYZ(:,1); Y=XYZ(:,2); Z=XYZ(:,3); i f ~ i s e m p t y ( R 0 )
X=X+R0(1); Y=Y+R0(2); Z=Z+R0(3); end
X = r e s h a p e ( X,n,m ); Y = r e s h a p e ( Y,n,m );
Z = r e s h a p e ( Z,n,m );
i f n a r g i n = = 0
c l o s e; s u r f ( X,Y,Z ), a x i s e q u a l, g r i d on t i tl e ('R O T A T E D AND TRANSLATED ELLIPSOID') x l a b e l ('x a x i s'), y l a b e l ('y a x i s') z l a b e l ('z a x i s'),c o l o r m a p ( [ 1 1 1 ] ); s h g end
%==============================================
f u n c t i o n [ x,y,z ] = e l i p s o i d ( a,b,c,n,n o p l o t )
%
% [ x,y,z ] = e l i p s o i d ( a,b,c,n,n o p l o t )
%...............................................................................
% T h i s f u n c t i o n p l o t s an e l l i p s o i d h a v i n g s e m i - % d i a m e t e r s a,b,c
% a,b,c - s e m i d i a m e t e r s o f t h e e l l i p s o i d d e f i n e d
% by ( x/a ) ~ 2 + ( y/b ) ~ 2 + ( z/c ) ~ 2 = 1
% n - v e c t o r [ n t h,n p h ] g i v i n g t h e number o f
% t h e t a v a l u e s and p h i v a l u e s u s e d t o p l o t
% t h e s u r f a c e
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
% n o p l o t - o m i t t h i s p a r a m e t e r i f no p l o t i s d e s i r e d % x,y,z - m a t r i c e s o f p o i n t s on t h e s u r f a c e %
% U s er m f u n c t i o n s c a l l e d: none %-----------------------------------------------------------------------------------------
i f n a r g i n = = 0, a=2; b = 1.5; c=1; n = [ 1 7,3 3 ]; end n t h = n ( 1 ); n p h = n ( 2 );
t h = l i n s p a c e ( - p i/2,p i/2,n t h )'; p h = l i n s p a c e ( - p i,p i,n p h ); x = a * c o s ( t h ) * c o s ( p h ); y = b * c o s ( t h ) * s i n ( p h ); z = c * s i n ( t h ) * o n e s ( s i z e ( p h ) ); i f n a r g i n < 5
s u r f ( x,y,z ); a x i s e q u a l t i t l e ('E L L I P S O I D'), x l a b e l ('x a x i s') y l a b e l ('y a x i s'), z l a b e l ('z a x i s') c o l o r m a p ( [ 1 1 1 ] ); g r i d o n, f i g u r e ( g c f )
end
%==============================================
f u n c t i o n m a t = r o t a t r a n ( v )
%
% m a t = r o t a t r a n ( v )
%......................................
% T h i s f u n c t i o n c r e a t e s a r o t a t i o n m a t r i x b a s e d % on t h e columns o f v.
%
% v - a m a t r i x h a v i n g t h r e e rows and e i t h e r % one o r two columns whi ch a r e u s e d t o
% c r e a t e an o r t h o n o r m a l t r i a d [ i,j,k ]
% r e t u r n e d i n t h e columns o f m a t. The
% t h i r d b a s e v e c t o r k i s d e f i n e d a s
% v (:,1 )/n o r m ( v (:,1 ) ). I f v h a s two
% columns t h e n, v (:,1 ) and v (:,2 ) d e f i n e
% t h e xz p l a n e w i t h t h e d i r e c t i o n o f j
% d e f i n e d by c r o s s ( v (:,1 ),v (:2 ) ). I f o n l y
% v (:,1 ) i s i n p u t, t h e n v (:,2 ) i s s e t
% t o [ 1;0;0 ].
%
% mat - t h e m a t r i x h a v i n g columns c o n t a i n i n g % t h e b a s i s v e c t o r s [ i,j,k ]
%
% U s er m f u n c t i o n s c a l l e d: none %---------------------------------------------------------
109
110 111 112
113
114
115
116
k = v (:,1 )/n o r m ( v (:,1 ) );
i f s i z e ( v,2 ) = = 2, p = v (:,2 ); e l s e, p = [ 1;0;0 ]; end j = c r o s s ( k,p ); n j = n o r m ( j ); i f nj ~=0
j = j/n j; m a t = [ c r o s s ( j,k ),j,k ]; e l s e
m a t = [ [ 0;1;0 ],c r o s s ( k,[ 0;1;0 ] ),k ];
end
Chapiter 3
Summary of Concepts from Linear Algebra
3.1 Introduction
This chapter briefly reviews important concepts of linear algebra. We assume the reader already has some experience working with matrices, and linear algebra ap­
plied to solving simultaneous equations and eigenvalue problems. MATLAB has ex­
cellent capabilities to perform matrix operations using the fastest and most accurate algorithms currently available. The books by Strang [96] and Golub and Van Loan [47] give comprehensive treatments of matrix theory and of algorithm developments accounting for effects of finite precision arithmetic. One beautiful aspect of matrix theory is that fairly difficult proofs often lead to remarkably simple results valuable to users not necessarily familiar with all of the theoretical developments. For in­
stance, the property that every real symmetric matrix of order n has real eigenvalues and a set of n orthonormal eigenvectors can be understood and used by someone unfamiliar with the proof. The current chapter summarizes a number of fundamen­
tal matrix properties and some of the related MATLAB functions. The intrinsic matrix functions use highly efficient algorithms originally from the LINPACK and EISPACK libraries which have now been superceded by LAPACK. [34, 42, 89]. Dr. Cleve Moler, the Chairman and Chief Scientist at The MathWorks, contributed to development of these systems. He also wrote the first version of MATLAB. Readers should simultaneously study the current chapter and the MATLAB demo program on linear algebra.
3.2 Vectors, Norms, Linear Independence, and Rank
Consider an n by m matrix
A = [atJ] , 1 < i < n , 1 < j < m,
havi ng real or compl ex el ement s. The shape of a mat r i x is comput ed by si ze( A) whi ch r et ur ns a vect or cont ai ni ng n and m. The matrix obtained by conjugating the matrix elements and interchanging columns and rows is called the transpose.
Transposition is accomplished with a ' operator, so that
^.transpose = A'.
Transposi t i on wi t hout conj ugat i on of t he el ement s can be per f or med as A.' or as conj(A'). Of course, whenever A is real, A' is simply the traditional transpose.
The structure of a matrix A is characterized by the matrix rank and sets of basis vectors spanning four fundamental subspaces. The rank r is the maximum number of linearly independent rows or columns in the matrix. We discuss these spaces in the context of real matrices. The basic subspaces are:
1. The column space containing all vectors representable as a linear combination of the columns of A. The column space is also referred to as the range or the span.
2. The null space consisting of all vectors perpendicular to every row of A.
3. The row space consisting of all vectors which are linear combinations of the rows of A.
4. The left null space consisting of all vectors perpendicular to every column of A.
MATLAB has intrinsic functions to compute rank and subspace bases
• matrix _rank = ranki l j
• columnjspace = orth(A)
• nulLspace = null (A)
• row .space = orth(A/)/
• left_nullj3pace = null(A/)/
The basis vectors produced by null and orth are orthonormal. They are generated using the singular value decomposition algorithm [47]. The MATLAB function to perform this type of computation is named svd.
3.3 Systems of Linear Equations, Consistency, and Least Squares Approximation
Let us discuss the problem of solving systems of simultaneous equations. Repre­
senting a vector B as a linear combination of the columns of A requires determina­
tion of a vector X to satisfy
m
AX = B ^ ] T A(:,j) x(j) = B
3=1
where the f t h column of A is scaled by the f t h component of X to form the lin­
ear combination. The desired representation is possible if and only if B lies in the column space of A. This implies the consistency requirement that A and [A, B] must have the same rank. Even when a system is consistent, the solution will not be unique unless all columns of A are independent. When matrix A, with n rows and m columns, has rank r less than m, the general solution of A X = B is expressible as any particular solution plus an arbitrary linear combination of m — r vectors form­
ing a basis for the null space. MATLAB gives the solution vector as X = A\B. When r is less than m, MATLAB produces a least squares solution having as many components as possible set equal to zero.
In instances where the system is inconsistent, regardless of how X is chosen, the error vector defined by
E = AX — B
can never be zero. An approximate solution can be obtained by making E normal to the columns of A. We get
A'AX = A'B
which is known as the system of normal equations. They are also referred to as least squares error equations. It is not difficult to show that the same equations result by requiring E to have minimum length. The normal equations are always consistent and are uniquely solvable when rank(A) = m. A comprehensive discussion of least squares approximation and methods for solving overdetermined systems is presented by Lawson and Hanson [62]. It is instructive to examine the results obtained from the normal equations when A is square and nonsingular. The least squares solution would give
X = (A1 A) - 1 A'B = A - 1(A')- 1A'B = A - 1 B.
Ther ef or e, t he l east squar es sol ut i on si mpl y reduces t o t he exact sol ut i on of A X = B for a consistent system. MATLAB handles both consistent and inconsistent systems as X = A\B. However, it is only sensible to use the least squares solution of an inconsistent system when A X produces an acceptable approximation to B. This implies
norm(AX — B) < tol * norm(B)
where tol is suitably small.
A simple but important application of overdetermined systems arises in curve fit­
ting. An equation of the form
m
y(x) = Σ f 3( x ) c 3
3=1
involving known functions f 3 (x), such as x3 - 1 for polynomials, must approximately match data values ( Xt, Y,), 1 < i < n, with n > m. We simply write an overdeter­
mined system
n
Y f 3 (Xi)c 3 Y , 1 < I < n
3=1
and obtain the least squares solution. The approximation is acceptable if the error components
m
e = Σ f (χ ι)°3 - Y
3=i
ar e smal l enough and t he funct i on y(x) is also acceptably smooth between the data points.
Let us illustrate how well MATLAB handles simultaneous equations by construct­
ing the steady-state solution of the matrix differential equation
MX + CX + Kx = Fi cos(wt) + F2 sin(wt)
where M, C, and K are constant matrices and Fi and F2 are constant vectors. The steady-state solution has the form
x = X i cos(wt) + X 2 sin(wt)
where X i and X 2 are chosen so that the differential equation is satisfied. Evidently
X = - u X i sin(wt) + wX2 cos(wt)
and
X = - ω 2χ.
Subst i t ut i ng t he assumed f or m i nt o t he di ff erent i al equat i on and compar i ng si ne and cosi ne t erms on bot h si des yi el ds
( K - ε 2Μ ) Xi + wCX2 = Fi,
- w C X i + ( K - ε 2Μ ) X2 = F2.
The equi val ent par t i t i oned mat r i x is
( Κ - ω 2Μ)
ujC '
l~Xil
[ i l l
-LOC
(K - uj2M)
x 2
f 2
A simple MATLAB function to produce X i and X 2 when Μ, C, K, Fi, F2, and ε are known is
f u n c t i o n [ x 1,x 2,x m a x ] = f o r c r e s p ( m,c,k,f 1,f 2,w ) kwm=k-(w*w)*m; wc=w*c;
x = [ k w m,w c;- w c,k w m ]\[ f 1;f 2 ]; n = l e n g t h ( f 1 ); x 1 = x ( 1:n ); x 2 = x ( n + 1:2 * n ); x m a x = s q r t ( x 1.* x 1 + x 2.* x 2 );
The vector, xmax, defined in the last line of the function above, has components specifying the maximum amplitude of each component of the steady-state solution.
The main computation in this function occurs in the third line, where matrix concate­
nation is employed to form a system of 2n equations with x being the concatenation of X 1 and X2. The fourth line uses vector indexing to extract X 1 and X 2 from x. The notational simplicity of MATLAB is elegantly illustrated by these features: a) any required temporary storage is assigned and released dynamically, b) no looping operations are needed, c) matrix concatenation and inversion are accomplished with intrinsic functions using matrices and vectors as sub-elements of other matrices, and d) extraction of sub-vectors is accomplished by use of vector indices. The impor­
tant differential equation just discussed will be studied further in Article 3.5.3 where eigenvalues and complex arithmetic are used to obtain a general solution satisfying arbitrary initial conditions.
3.4 Applications of Least Squares Approximation
The idea of solving an inconsistent system of equations in the least squares sense, so that some required condition is approximately satisfied, has numerous applica­
tions. Typically, we are dealing with a large number of equations (several hundred is common) involving a smaller number of parameters used to closely fit some con­
straint. Linear boundary value problems often require the solution of a differential equation applicable in the interior of a region while the function values are known on the boundary. This type of problem can sometimes be handled by using a series of functions which satisfy the differential equation exactly. Weighting the component solutions to approximately match the remaining boundary condition may lead to use­
ful results. Below, we examine three instances where least squares approximation is helpful.
3.4.1 A Membrane Deflection Problem
Let us illustrate how least squares approximation can be used to compute the trans­
verse deflection of a membrane subjected to uniform pressure. The transverse de­
flection u for a membrane which has zero deflection on a boundary L satisfies the differential equation
82u 82u . .
a? + w = ~'1' ο·'»""*1·
where γ is a physical constant. Properties of harmonic functions [18] imply that the differential equation is satisfied by a series of the form
u = γ
- w
2 n 4 + Σ >
3=1
r e a l ( z3 1)
Membrane Deflection
Figure 3.1: Surface Plot of Membrane
where z = x + iy and constants c3 are chosen to make the boundary deflection as small as possible, in the least squares sense. As a specific example, we analyze a membrane consisting of a rectangular part on the left joined with a semicircular part on the right. The surface plot in Figure 3.1 and the contour plot in
Figure 3.2 were produced by the function membran listed below. This function generates boundary data, solves for the series coefficients, and constructs plots depicting the deflection pattern. The results obtained using a twenty-term series satisfy the boundary condi­
tions quite well.
y axis
x axis
Figure 3.2: Membrane Surface Contour Lines
MATLAB Example Function membran
i: f u n c t i o n [ d f l,c o f ] = m e m b r a n ( h,n p,n s,n x,n y )
2: % [ d f l,c o f ] = m e m b r a n ( h,n p,n s,n x,n y )
3: %
4: % T h i s f u n c t i o n computes t h e t r a n s v e r s e 5: % d e f l e c t i o n o f a u n i f o r m l y t e n s i o n e d membrane 6: % w h i c h i s s u b j e c t e d t o u n i f o r m p r e s s u r e. The 7: % membrane s h a p e i s a r e c t a n g l e o f w i d t h h and 8: % h e i g h t two j o i n e d w i t h a s e m i c i r c l e o f 9: % d i a m e t e r two.
10: %
i i: % Example u s e: m e m b r a n ( 0.7 5,1 0 0,5 0,4 0,4 0 );
12: %
i 3: % h - t h e w i d t h o f t h e r e c t a n g u l a r p a r t
i 4: % np - t h e number o f l e a s t s q u a r e p o i n t s
i 5: % u s e d t o m at ch t h e b o u n d a r y
i 6: % c o n d i t i o n s i n t h e l e a s t s q u a r e
i 7: % s e n s e i s a b o u t 3.5 * n p
i 8: % n s - t h e number o f t e r m s u s e d i n t h e
i 9: % a p p r o x i m a t i n g s e r i e s t o e v a l u a t e
2 0: % d e f l e c t i o n s. The s e r i e s h a s t h e
2 i: % fo r m
22: %
23: % d f l = a b s ( z ) ~ 2/4 +
24: % s u m ( { j = 1:n s },c o f ( j ) *
25: % r e a l ( z ~ ( j - 1 ) ) )
26: %
27: % n x,n y - t h e number o f x p o i n t s and y p o i n t s
2 8: % u s e d t o compute d e f l e c t i o n v a l u e s
29: % on a r e c t a n g u l a r g r i d
30: % d f l - computed a r r a y o f d e f l e c t i o n v a l u e s
3 i: % c o f - c o e f f i c i e n t s i n t h e s e r i e s
32: % a p p r o x i m a t i o n
33: %
34: % U s er m f u n c t i o n s c a l l e d: none
35:
36: i f n a r g i n = = 0
37: h =.7 5; np=100; n s = 5 0; nx=40; ny=40;
38: end
39:
40: % G e n e r a t e b o u n d a r y p o i n t s f o r l e a s t s q u a r e
4 i
42
43
44
45
46
47
48
49
50:
5 i
52:
53
54:
55:
56:
57
58
59
60:
6 i
62:
63
64:
65:
66:
67
68
69
70:
7 i
72:
73
74:
75:
76:
77
78
79
% a p p r o x i m a t i o n
z = [ e x p ( i * l i n s p a c e ( 0,p i/2,r o u n d ( 1.5 * n p ) ) ),... l i n s p a c e ( i,- h + i,n p ),... l i n s p a c e ( - h + i,- h,r o u n d ( n p/2 ) ) ]; z = z (:); x b = r e a l ( z ); x b = [ x b;x b ( e n d:- 1:1 ) ]; y b = i m a g ( z ); y b = [ y b;- y b ( e n d:- 1:1 ) ]; n b = l e n g t h ( x b );
% Form t h e l e a s t s q u a r e e q u a t i o n s and s o l v e
% f o r s e r i e s c o e f f i c i e n t s
a = o n e s ( l e n g t h ( z ),n s );
f o r j = 2:n s, a (:,j ) = a (:,j - 1 ).* z; end
c o f = r e a l ( a )\( z.* c o n j ( z ) )/4;
% G e n e r a t e a r e c t a n g u l a r g r i d f o r e v a l u a t i o n % o f d e f l e c t i o n s
x v = l i n s p a c e ( - h,1,n x ); y v = l i n s p a c e ( - 1,1,n y ); [ x,y ] = m e s h g r i d ( x v,y v ); z = x + i * y;
% E v a l u a t e t h e d e f l e c t i o n s e r i e s on t h e g r i d d f l = - z.* c o n j ( z )/4 + ...
r e a l ( p o l y v a l ( c o f ( n s:- 1:1 ),z ) );
% S e t v a l u e s o u t s i d e t h e p h y s i c a l r e g i o n of % i n t e r e s t t o z e r o
d f l = r e a l ( d f l ).* ( 1 - ( ( a b s ( z ) > = 1 ) & ( r e a l ( z ) > = 0 ) ) );
% Make s u r f a c e and c o n t o u r p l o t s h o l d o f f; c l o s e; s u r f ( x,y,d f l ); x l a b e l ('x a x i s'); y l a b e l ('y a x i s'); z l a b e l ('d e f l e c t i o n'); v i e w ( - 1 0,3 0 ); t i t l e ('M e m b r a n e D e f l e c t i o n'); c o l o r m a p ( [ 1 1 1 ] ); s h g, d i s p (...
'P r e s s [ E n t e r ] t o show a c o n t o u r p l o t'), p a u s e % p r i n t - d e p s membdefl; c o n t o u r ( x,y,d f l,1 5,'k'); h o l d on p l o t ( x b,y b,'k -'); a x i s ('e q u a l'), h o l d o f f x l a b e l ('x a x i s'); y l a b e l ('y a x i s'); t i t l e ('M e m b r a n e S u r f a c e C o n t o u r L i n e s'), s h g % p r i n t - d e p s membcntr
3.4.2 Mixed Boundary Value Problem for a Function Harmonic Inside a Circular Disk
Problems where a partial differential equation is to be solved inside a region with certain conditions imposed on the boundary occur in many situations. Often the dif­
ferential equation is solvable exactly in a series form containing arbitrary linear com­
binations of known functions. An approximation procedure imposing the boundary conditions to compute the series coefficients produces a satisfactory solution if the desired boundary conditions are found to be well satisfied. Consider a mixed bound­
ary value problem in potential theory [73] pertaining to a circular disk of unit radius. We seek u(r, θ) where function values are specified on one part of the boundary
and normal derivative values are specified on the remaining part. The mathematical
formulation is
d2u 1 du 1 d2u
+ "7Γ + = Ο,Ο< γ < 1,Ο < 0 < 2 τγ,
dr2 r dr r 2 ()θ2
u( 1, θ) = f (θ) , —α < θ < a , du
— (1, Θ) = g(0) , a < θ < 2ττ — a. dr
The di ff erent i al equat i on has a seri es sol ut i on of t he f or m
tt
u(r, θ) = c0 + rn [cn οοϋ(ηθ) + dn 8Ϊπ(ηθ)]
n=1
where the boundary conditions require
tt
c0 + ^^j[cn οοβ(ηθ) + dn 8ΐπ(ηθ)] = f (θ) , —a < θ < a,
n
1
and
n[cn βοβ(ηθ) + dn 8ΐπ(ηθ)] = §(θ) , a < θ < 2π — a.
1
The ser i es coeffi ci ent s can be obt ai ned by l eas t squar es appr oxi mat i on. Let us ex­
pl or e t he ut i l i t y of t hi s appr oach by consi der i ng a par t i cul ar pr obl em for a fi el d whi ch is symmet r i c about t he x- axi s. We want t o sol ve
V 2u = 0 , r < 1,
u(1, θ) = cos(0) , \θ\ < π/2, du
— (1,0 ) = 0, π/2 < \θ\ < π.
This problem characterizes steady-state heat conduction in a cylinder with the left half insulated and the right half held at a known temperature. The appropriate series solution is
cnrn cos(^)
n=0
u
subject to
tt
cn cos(^) = cos^) for \θ\ < π/2,
n = 0
and
tt
ηcn cos ( ^ ) = 0 for π/2 < \θ\ < π.
n=0
We sol ve t he pr obl em by t r uncat i ng t he seri es af t er a hundr ed or so t erms and f or mi ng an over det er mi ned syst em der i ved by i mposi t i on of bot h boundar y condi t i ons. The success of t hi s pr ocedur e depends on t he ser i es convergi ng r api dl y enough so t hat a syst em of l east squares equat i ons havi ng r easonabl e or der and sat i sfact ory numeri cal condi t i on resul t s. It can be shown by compl ex var i abl e met hods (see Muskhel i shvi l i [73]) t hat t he exact sol ut i on of our pr obl em is gi ven by
u = real
z + z - 1 + (1 - ^_1)v/- 2 + 1 /2 , |^| < 1
where the square root is defined for a branch cut along the right half of the unit circle with the chosen branch being that which equals +1 at z = 0. Readers familiar with analytic function theory can verify that the boundary values of u yield
u(1, θ) = cos(0) , \θ\ < π/2,
u( 1, Θ) = cos(6) + sin(|0 |/2 )\/2 | cos(0)| , π/2 < \θ\ < π.
A least squares solution is presented in function mbvp. Results from a series of 100 terms are shown in
Figure 3.3
. The series solution is accurate within about one percent error except for points near θ = π/2. Although the results are not shown here, using 300 terms gives a solution error nowhere exceeding 4 percent. Hence the least squares series solution provides a reasonable method to handle the mixed boundary value problem.
function value and error
Mixed Boundary Value Problem Solution for 80 Terms
polar angle
Figure 3.3: Mixed Boundary Value Problem Solution
MATLAB Example Program mbvprun
i: f u n c t i o n m b v p r u n ( n s e r,n f,n g,n e v a l )
2: % Example: m b v p r u n ( n s e r,n f,n g,n e v a l )
3: %...........................................................................
4: % Mixed b o u n d a r y v a l u e p r o b l e m f o r a f u n c t i o n 5: % h a r m o n i c i n s i d e a c i r c l e.
6:
7: % U s er m f u n c t i o n s r e q u i r e d:
8: % mbvp
9:
i o: d i s p ('C a l c u l a t i n g');
i i:
i 2: % S e t d a t a f o r s e r i e s t e r m and b o u n d a r y i 3: % c o n d i t i o n p o i n t s i 4: i f n a r g i n = = 0
i 5: n s e r = 8 0; n f = 1 0 0; ng=100; n e v a l = 5 0 0;
i 6: end
i 7:
i 8: % Compute t h e s e r i e s c o e f f i c i e n t s
i 9: [ c o f,y ] = m b v p ('c o s',p i/2,n s e r,n f,n g,n e v a l );
20:
2 i: % E v a l u a t e t h e e x a c t s o l u t i o n f o r c o m p a r i s o n 2 2: t h p = l i n s p a c e ( 0,p i,n e v a l )';
23: y = c o s ( t h p * ( 0:n s e r - 1 ) ) * c o f;
24: y e = c o s ( t h p ) + s i n ( t h p/2 ).* ...
25: s q r t ( 2 * a b s ( c o s ( t h p ) ) ).* ( t h p > = p i/2 );
26:
27: % P l o t r e s u l t s showi ng t h e a c c u r a c y o f t h e 2 8: % l e a s t s q u a r e s o l u t i o n
29: t h p = t h p * 1 8 0/p i; p l o t ( t h p,y,'-',t h p,y - y e,'—'); 30: x l a b e l ('p o l a r a n g l e');
3 i: y l a b e l ('f u n c t i o n v a l u e and e r r o r')
3 2: t i t l e ( ['M i x e d Boundary V a lu e P r o b l e m ', ...
33: 'S o l u t i o n f o r ',i n t 2 s t r ( n s e r ),' T e r m s'] );
34: l e g e n d ('F u n c t i o n v a l u e','S o l u t i o n E r r o r');
35: f i g u r e ( g c f ); % p r i n t - d e p s mbvp
36:
37: %==============================================
38:
39: f u n c t i o n [ c o f,y ] = ...
40: m b v p ( f u n c,a l p,n s e r,n f,n g,n e v a l )
4 i
42
43:
44
45
46
47:
48
49
50:
5 i:
52
53:
54:
55
56
57:
58:
59:
60:
6 i:
62
63:
64:
65
66
67:
68:
69:
70:
7 i
72
73:
74
75
76
77:
78
79
80:
8 i
82
83:
84
85
[ c o f,y ] = m b v p ( f u n c,a l p,n s e r,n f,n g,n e v a l )
T h i s f u n c t i o n s o l v e s a p p r o x i m a t e l y a mixed b o u n d a r y v a l u e p r o b l e m f o r a f u n c t i o n which i s h a r m o n i c i n s i d e t h e u n i t d i s k, s y m m e t r i c a b o u t t h e x a x i s, and h a s b o u n d a r y c o n d i t i o n s i n v o l v i n g f u n c t i o n v a l u e s on one p a r t o f t h e b o u n d a r y and z e r o g r a d i e n t e l s e w h e r e.
f u n c - f u n c t i o n s p e c i f y i n g t h e f u n c t i o n
v a l u e b e t w e e n z e r o and a l p r a d i a n s
a l p - a n g l e b e t w e e n z e r o and p i which
s p e c i f i e s t h e p o i n t where b o u n d a r y c o n d i t i o n s ch a n g e fr o m f u n c t i o n v a l u e t o z e r o g r a d i e n t n s e r - number o f s e r i e s t e r m s u s e d
n f - number o f f u n c t i o n v a l u e s
s p e c i f i e d fr o m z e r o t o a l p ng - number o f p o i n t s f r o m a l p t o p i
where z e r o n o r m a l d e r i v a t i v e i s s p e c i f i e d
n e v a l - number o f b o u n d a r y p o i n t s where
t h e s o l u t i o n i s e v a l u a t e d c o f - c o e f f i c i e n t s i n t h e s e r i e s
s o l u t i o n
y - f u n c t i o n v a l u e s f o r t h e s o l u t i o n
% C r e a t e e v e n l y s p a c e d p o i n t s t o impose % b o u n d a r y c o n d i t i o n s t h 1 = l i n s p a c e ( 0,a l p,n f ); t h 2 = l i n s p a c e ( a l p,p i,n g + 1 ); t h 2 ( 1 ) = [ ];
% Form an o v e r d e t e r m i n e d s y s t e m b a s e d on t h e
% b o u n d a r y c o n d i t i o n s
y v = f e v a l ( f u n c,t h 1 );
c m a t = c o s ( [ t h 1 (:);t h 2 (:) ] * ( 0:n s e r - 1 ) );
[ n r,n c ] = s i z e ( c m a t );
c m a t ( n f + 1:n r,:) =...
( o n e s ( n g,1 ) * ( 0:n s e r - 1 ) ).* c m a t ( n f + 1:n r,:);
c o f = c m a t\[ y v (:);z e r o s ( n g,1 ) ];
86: % E v a l u a t e t h e s o l u t i o n on t h e b o u n d a r y 87: t h p = l i n s p a c e ( 0,p i,n e v a l )';
88: y = c o s ( t h p * ( 0:n s e r - 1 ) ) * c o f;
3.4.3 Using Rational Functions to Conformally Map a Circular Disk onto a Square
Another problem illustrating the value of least squares approximation arises in connection with an example discussed earlier in Section 2.4 where a slowly conver­
gent power series was used to map the interior of a circle onto the interior of a square [75]. It is sometimes possible for slowly convergent power series of the form
N
w = f (z) = Σ c3z3 > | z | < 1
3=0
to be replaceable by a rational function
n
Σ α3Ζ 3
3=0
W = m------'
1 + Σ b3z3
3=1
Of cour se, t he pol ynomi al i s si mpl y a speci al r at i onal funct i on f or m wi t h m = 0 and n = N. This rational function implies
n m
a3z3 — w b3z3 = w.
3=0 3=1
Coefficients a3
and b3
can be computed by forming least square equations based on boundary data. In some cases, the resulting equations are rank deficient and it is safer to solve a system of the form UY = V
as Y =
pinv(U) * V
rather than using Y = U
\V. The former solution uses the pseudo inverse function pinv which automatically sets to zero any solution components that are undetermined.
Two functions ratcof and raterp were written to compute rational function co­
efficients and to evaluate the rational function for general matrix arguments. These functions are useful to examine the conformal mapping of the circular disk l zl < 1 onto the square defined by | real(w)| < 1, | imag(w)| < 1. A polynomial approxi­
mation of the mapping function has the form
N
w/z = Σ c3(zi)3
3=0
where N must be quite large in order to avoid excessive corner rounding. If we evaluate w versus z on the boundary for large N (500 or more), and then develop
Rational Function Map Close t o a Cor n er
0.65 0.7 0.75 0.8 0.85 0.9 0.95 1
real axis
Figure 3.4: Rational Function Map Close to a Corner
a rational function fit with n = m = 1 0, a reasonably good representation of the square results without requiring a large number of series terms. The following pro­
gram illustrates the use of functions ratcof and raterp. It also includes a function sqmp to generate coefficients in the Schwarz-Christoffel series.(See Chapter 11 for further discussion.) Figure 3.4 shows the geometry mapping produced near a corner.
MATLAB Example Program makratsq
i: f u n c t i o n [ c t o p,c b o t ] = m a k r a t s q 2: % Example: [ c t o p,c b o t ] = m a k r a t s q
3: %................................................................................
4: % C r e a t e a r a t i o n a l f u n c t i o n map o f a u n i t d i s k 5: % o n t o a s q u a r e.
6: %
7: % U s er m f u n c t i o n s r e q u i r e d:
8: % sqmp, r a t c o f, r a t e r p
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
35
36
37
38
39
40:
41:
42
43
44
45
46
47
48
49
50:
51:
52
53:
54
d i s p (' ');
disp('RATIONAL FUNCTION MAPPING OF A CIRCULAR'); d i s p (' DISK ONTO A SQUARE'); d i s p (' ');
d i s p ('C a l c u l a t i n g'); d i s p (' ');
% G e n e r a t e b o u n d a r y p o i n t s g i v e n by t h e % S c h w a r z - C h r i s t o f f e l t r a n s f o r m a t i o n n s c = 5 0 1; np=401; n t o p = 1 0; n b o t = 1 0; z = e x p ( i * l i n s p a c e ( 0,p i/4,n p ) ); w = s q m p ( n s c,1,1,1,0,4 5,n p ); w = m e a n ( r e a l ( w ) ) + i * i m a g ( w ); z = [ z,c o n j ( z ) ]; w = [ w,c o n j ( w ) ];
% Compute t h e s e r i e s c o e f f i c i e n t s f o r a % r a t i o n a l f u n c t i o n f i t t o t h e b o u n d a r y d a t a [ c t o p,c b o t ] = r a t c o f ( z.~ 4,w./z,n t o p,n b o t ); c t o p = r e a l ( c t o p ); c b o t = r e a l ( c b o t );
% The above c a l c u l a t i o n s p r o d u c e t h e f o l l o w i n g % c o e f f i c i e n t s % [ t o p,b o t ] =
% 1.0 7 8 7 1.4 9 4 8
% 1.5 0 4 5 0.1 4 0 6
% 0.0 3 5 3 - 0.1 5 9 4
% - 0.1 4 5 8 0.1 7 5 1
% 0.1 9 1 0 - 0.1 5 1 3
% - 0.1 7 9 7 0.0 2 5 3
% 0.0 4 8 9 0.2 5 1 6
% 0.2 5 9 5 0.1 0 6 9
% 0.0 9 4 5 0.0 1 0 2
% 0.0 0 6 8 0.0 0 0 1
% G e n e r a t e a p o l a r c o o r d i n a t e g r i d t o d e s c r i b e % t h e mapping n e a r t h e c o r n e r o f t h e s q u a r e.
% Then e v a l u a t e t h e mapping f u n c t i o n. r 1 =.9 5; r 2 = 1; n r = 1 2; t 1 =.9 * p i/4; t 2 = 1.1 * p i/4; n t = 1 0 1; [ r,t h ] = m e s h g r i d ( l i n s p a c e ( r 1,r 2,n r ), ...
l i n s p a c e ( t 1,t 2,n t ) ); z = r.* e x p ( i * t h ); w = z.* r a t e r p ( c t o p,c b o t,z.~ 4 );
% P l o t t h e mapped g e o m e t r y c l o s e; u = r e a l ( w ); v=imag(w); p l o t ( u,v,'k',u',v','k'), a x i s e q u a l t i t l e ('R a t i o n a l F u n c t i o n Map C l o s e t o a C o r n e r');
55
56
57:
58
59
60:
61:
62
63:
64
65
66
67:
68
69
70:
71:
72
73
74
75
76
77
78
79
80:
81:
82
83
84
85
86
87
88
89
90:
91:
92
93:
94
95
96
97:
98
99
x l a b e l ('r e a l a x i s'); y l a b e l ('i m a g i n a r y a x i s'); f i g u r e ( g c f ); % p r i n t - d e p s r a t s q m a p
%=============================================
f u n c t i o n [ w,b ] = s q m p ( m,r 1,r 2,n r,t 1,t 2,n t )
% [ w,b ] = s q m p ( m,r 1,r 2,n r,t 1,t 2,n t )
T h i s f u n c t i o n e v a l u a t e s t h e c o n f o r m a l mapping p r o d u c e d by t h e S c h w a r z - C h r i s t o f f e l t r a n s f o r m a t i o n w(z) mapping a b s ( z ) < = 1 i n s i d e a s q u a r e h a v i n g a s i d e l e n g t h o f t w o. The t r a n s f o r m a t i o n i s a p p r o x i m a t e d i n s e r i e s fo r m whi ch c o n v e r g e s v e r y s l o w l y n e a r t h e c o r n e r s. T h i s f u n c t i o n i s t h e same a s squar map o f c h a p t e r 2 w i t h no p l o t t i n g.
m - number o f s e r i e s t e r m s u s e d
r 1,r 2,n r - a b s ( z ) v a r i e s fr o m r 1 t o r 2 i n
n r s t e p s
t 1,t 2,n t - a r g ( z ) v a r i e s fr o m t 1 t o t 2 i n n t s t e p s ( t 1 and t 2 a r e m e a s u r e d i n d e g r e e s ) w - p o i n t s a p p r o x i m a t i n g t h e s q u a r e
b - c o e f f i c i e n t s i n t h e t r u n c a t e d
s e r i e s e x p a n s i o n whi ch h a s t h e fo r m
w ( z ) = s u m ( { j = 1:m },b ( j ) * z * ( 4 * j - 3 ) ) U s er m f u n c t i o n s c a l l e d: n o n e.
% G e n e r a t e p o l a r c o o r d i n a t e g r i d p o i n t s f o r t h e % map. F u n c t i o n l i n s p a c e g e n e r a t e s v e c t o r s w i t h % e q u a l l y s p a c e d c o m p o n en t s. r = l i n s p a c e ( r 1,r 2,n r )'; t = p i/1 8 0 * l i n s p a c e ( t 1,t 2,n t ); z = ( r * o n e s ( 1,n t ) ).* ( o n e s ( n r,1 ) * e x p ( i * t ) );
% Compute t h e s e r i e s c o e f f i c i e n t s and e v a l u a t e
% t h e s e r i e s
k=1:m -1;
b = c u m p r o d ( [ 1,- ( k -.7 5 ).* ( k -.5 )./( k.* ( k +.2 5 ) ) ] );
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
b = b/s u m ( b ); w = z.* p o l y v a l ( b ( m:- 1:1 ),z.~ 4 ); %==============================================
f u n c t i o n [ a,b ] = r a t c o f ( x d a t a,y d a t a,n t o p,n b o t )
%
% [ a,b ] = r a t c o f ( x d a t a,y d a t a,n t o p,n b o t )
%..........................................................................................
%
% D e t e r m i n e a and b t o a p p r o x i m a t e y d a t a a s % a r a t i o n a l f u n c t i o n o f t h e v a r i a b l e x d a t a.
% The f u n c t i o n h a s t h e f or m:
%
% y ( x ) = sum(1=>ntop) ( a ( j ) * x ~ ( j - 1 ) ) /
% ( 1 + sum(1=>nbot) ( b ( j ) * x ~ ( j ) ) )
%
% x d a t a,y d a t a - i n p u t d a t a v e c t o r s ( r e a l o r % complex)
% n t o p,n b o t - number o f s e r i e s t e r m s u s e d i n
% t h e n u m e r a t o r and t h e
% d e n o m i n a t o r.
%
% U s er m f u n c t i o n s c a l l e d: none %-----------------------------------------------------------------------------------------
y d a t a = y d a t a (:); x d a t a = x d a t a (:);
m = l e n g t h ( y d a t a );
i f n a r g i n = = 3, n b o t = n t o p; en d;
x = o n e s ( m,n t o p + n b o t ); x (:,n t o p + 1 ) = - y d a t a.* x d a t a; f o r i = 2:n t o p, x (:,i ) = x d a t a.* x (:,i - 1 ); end f o r i = 2:n b o t
x (:,i + n t o p ) = x d a t a.* x (:,i + n t o p - 1 ); end
a b = p i n v ( x ) * y d a t a; % a b = x\y d a t a; a = a b ( 1:n t o p ); b = a b ( n t o p + 1:n t o p + n b o t );
%==============================================
f u n c t i o n y = r a t e r p ( a,b,x )
%
% y = r a t e r p ( a,b,x )
%......................................
% T h i s f u n c t i o n i n t e r p o l a t e s u s i n g c o e f f i c i e n t s % fr o m f u n c t i o n r a t c o f.
%
145: % a,b - p o l y n o m i a l c o e f f i c i e n t s f r o m f u n c t i o n
146: % r a t c o f
147: % x - a r g u me n t a t whi ch f u n c t i o n i s e v a l u a t e d
148: % y - computed r a t i o n a l f u n c t i o n v a l u e s
149: %
150: % U s er m f u n c t i o n s c a l l e d: n o n e.
151: %-----------------------------------------------------------------------------------------
152:
153: a = f l i p u d ( a (:) ); b = f l i p u d ( b (:) );
154: y = p o l y v a l ( a,x )./( 1 + x.* p o l y v a l ( b,x ) );
3.5 Eigenvalue Problems
3.5.1 Statement of the Problem
Another important linear algebra problem involves the computation of nonzero vectors X and numbers Λ such that
AX = ΛΧ
where A is a square matrix of order n having elements which may be real or com­
plex. The number Λ, which can also be real or complex, is called the eigenvalue corresponding to the eigenvector X. The eigenvalue equation implies
[ΙΛ — A]X = 0
so that Λ values must be selected to make ΙΛ — A singular. The polynomial
f (Λ) = άβψΛ —
A) = Λη + ο1Λη-1 + ... + cn
is cal l ed t he char act er i st i c equat i on and i t s root s ar e t he ei genval ues. I t can be f ac­
t or ed i nt o
f (Λ) = (Λ — Λι)(Λ — Λ2) · · · ( Λ — Λη).
The ei genval ues ar e general l y compl ex number s and some of t he root s may be r e ­
peat ed. In t he usual si t uat i on, di st i nct r oot s Λ1, · · ·, Λη yield n linearly independent eigenvectors obtained by solving
(A — Λ31 X = 0 , 1 < j < n.
The case i nvol vi ng r epeat ed ei genval ues is mor e compl i cat ed. Suppose a par t i cul ar ei genval ue such as Λ1 has multiplicity k. Then the general solution of
(A — Λ1Ι )X = 0
will yield as few as one, or as many as k, linearly independent vectors. If fewer than k independent eigenvectors are found for any root of multiplicity k, then matrix A is
called defective. Occurrence of a defective matrix is not typical. It usually implies special behavior of the related physical system. The combined set of eigenvectors can be written as
A[X 1, ··· ,Xn] = [XlΛl, · · · ,XnΛn] = [X1, · · · ,Xn] d i a g ^1, · · · ,Λη)
or
AU = U Λ
where U has the eigenvectors as columns and Λ is a diagonal matrix with eigenvalues on the diagonal. When the eigenvectors are independent, matrix U, known as the modal matrix, is nonsingular. This allows A to be expressed as
A = UΛU-1
which is convenient for various computational purposes. With repeated eigenvalues, the modal matrix is sometimes singular and the last form of decomposition fails. However, the eigenvectors are always independent when the eigenvalues are distinct. For the important special case of a symmetric matrix, a linearly independent set of eigenvectors always exists, even when some eigenvalues are repeated.
A matrix A is symmetric if A = A' where A' is obtained by interchanging columns and rows, and conjugating all elements. Symmetric matrices always have real eigenvalues and a linearly independent set of eigenvectors which can be or­
thonormalized. The eigenvectors X 3 and X k for any two unequal eigenvalues auto­
matically satisfy an orthogonality condition
X'X k =0 ,j = k.
Eigenvectors for the same repeated eigenvalue are not automatically orthogonal. Nevertheless, they can be replaced by an equivalent orthogonal set by applying a process called Gram-Schmidt orthogonalization [47]. In cases we care about here, the symmetric matrix A always has real elements. Therefore the eigenvalues are real with eigenvectors satisfying X'X 0 = 6%0, where 6l0 is the Kronecker delta symbol. The orthogonality condition is equivalent to the statement that U 'U = I, so a real symmetric matrix can be expressed as
A = UΛU'
It is important in MATLAB that the symmetry condition A' = A be satisfied per­
fectly. This implies a zero value for max(max(abs(A-A’ ))). Sometimes, results that would be symmetric if roundoff error did not occur may produce unsymmetric re­
sults contrary to expectation. For example, A = B C B' should be symmetric if C is symmetric. Replacing A by (A + A')/2 finally will assure perfect symmetry. The MATLAB function eig computes eigenvalues and eigenvectors. When a matrix is symmetric, eig generates real eigenvalues and orthonormalized eigenvectors.
An important property of symmetric matrices and the related orthonormal eigen­
vector set occurs in connection with quadratic forms expressed as
F (Y) = Y 'AY
where Y is an arbitrary real vector and A is real symmetric. The function F ( Y ) is a one-by-one matrix; hence, it is a scalar function. The algebraic sign of the form for arbitrary nonzero choices of Y is important in physical applications. Let us use the eigenvector decomposition of A to write
F = Y 'U ΛU'Y = (U 'Y)' Λ ^ Ύ ).
Taking X = U'Y and Y = UX gives
F = X ΛX = Λ1Χ1 + Λ2 x ‘22 + Λ3 Χ2 + ... + ΛηXn.
Thi s di agonal f or m makes t he al gebr ai c char act er of F evident. If all Λ * are positive, then F is evidently positive whenever X has at least one nonzero component. Then the quadratic form is called positive definite. If the eigenvalues are all positive or zero, the form is called positive semidefinite since the form cannot assume a negative value but can equal zero without having X = 0. When both negative and positive eigenvalues occur, the form can change sign and is termed indefinite. When the eigenvalues are all negative, the form is classified as negative definite. Perhaps the most important of these properties is that a necessary and sufficient condition for the form to be positive definite is that all eigenvalues of A be positive.
An important generalization of the standard eigenvalue problem has the form
AX = ΛBX
for arbitrary A and nonsingular B. If B is well conditioned, then it is computation­
ally attractive to simply solve
B-1AX = ΛX.
In general, it is safer, but much more time consuming, to call eig as [EIGVECS,EIGVALS]=eig(A,B)
This returns the eigenvectors as columns of EIGVECS and also gives a diagonal matrix EIGVALS containing the eigenvalues.
3.5.2 Application to Solution of Matrix Differential Equations
One of the most familiar applications of eigenvalues concerns the solution of the linear, constant-coefficient matrix differential equation
B Y'(t) = AY(t) , Y (0)= Yo.
Component solutions can be written as
Y(t) = Xext , Y' (t) = ΛXext
where X and Λ are constant. Substitution into the differential equation gives
(A — ΛB)Xeλt = 0.
Since ext cannot vanish we need
AX = ΛBX.
After the eigenvalues and eigenvectors have been computed, a general solution is constructed as a linear combination of component solutions
3.5.3 The Structural Dynamics Equation
Eigenvalues are also useful to solve the important second order matrix differential equation for which a particular solution was constructed earlier using real arithmetic. We will now use complex arithmetic and the versatile matrix notation provided in MATLAB. Structural mechanics applications often lead to the second order matrix differential equation
where M, C, K are constant matrices of order n, and F 1, F2 are constant vectors of length n, and ω is the forcing function frequency. Initial conditions of the form
also apply. Solving this initial value problem involves combining a particular so­
lution and a homogeneous solution. The solution we present below applies subject to the restriction that 1) the eigenvalues of the homogeneous equation should be nonzero and 2) if matrix C is zero, then ίω must not coincide with an eigenvalue of the homogeneous differential equation. The particular solution is
where we must assume that the implied matrix inversion exists. The particular solu­
tion satisfies initial conditions
η
3=1
The constants c3 are obtained by imposing the initial condition
Y (0) = [X1,X 2,...,Xn]c. Assuming that the eigenvectors are linearly independent we get
c =X1,...,Xn]-1Yo.
MX(t) + CX(t) + KX(t) = F1 cos^t) + F2 sin^t)
X (0) = Xo, X(0)= Vo
Xp(t) = real(a eiut), a = [K — M ω2 + ί^ω] \ [F1 — iF2].
X p(0) = real(a), Xp(0) = Γ^!(ίαω).
The particular solution plus the homogeneous solution, X h(t), must satisfy the gen­
eral initial conditions. Let us introduce
Z(t) = [Xh(t); X h(t)]
which obeys the homogeneous first order equation
Z(t) = AZ(t) , A = [eye(n,n), zeros(n, n ); —M \ [K, C] ]
and can be determined using the eigenvectors and eigenvalues of A. Denoting the matrix of eigenvectors as U and the column of eigenvalues as Λ, we find that
Z(t) = U diag(D) exp(i Λ t)
where
D = U \ [Xo — X P(0); Vo — Xp(0)]
to satisfy the initial conditions. With t taken as a row of time values, the homoge­
neous solution is obtained as the first n rows of Z, and the total solution is just
X (t) = Xp(t) + Xh (t).
A pr ogr am was wr i t t en t o sol ve t he st ruct ural dynami cs equat i on. Er r or checks are made f or t he except i onal cases ment i oned above. I f t he s yst em is undamped ( C = 0) and ίω matches an eigenvalue of A, then program execution terminates. Occurrence of zero or repeated eigenvalues is also avoided. The program consists of a driver named strdyneq which reads data from a function provided by the user. An example function named threemass is included as a model for data preparation. Function fhrcmk constructs the general solution of the equation. Results of the computation can be plotted one component at a time. In addition to plotting, the program outputs the eigenvalues, a matrix of solution components, and vectors showing the lower and upper limits of motion for each degree for freedom in the system. Function strdyneq calls fhrmck at lines 25 and 34. The name of a function defining the input data is requested. Users can employ function threemass to test the program. Threemass models a configuration of three identical masses sliding on a smooth horizontal plane and connected by four identical springs and viscous dampers. The outer two masses are connected to walls and are subjected to forces having equal magnitude but op­
posite direction. The middle mass has no driving force. The system is initially at rest with zero deflection when forcing functions are applied which nearly resonate with the fourth eigenvalue of the damped homogeneous system. This example was devised to illustrate how the system response grows rapidly when the forcing func­
tion is nearly resonant. Function fhrmck does most of the computation work which occurs at lines 108-109, 132-134, and 139-140. This example illustrates nicely the power of the intrinsic matrix operators provided in MATLAB. A final caveat about the solution method using eigenvalues is that it is somewhat limited by special cases like repeated eigenvalues or a forcing function resonant with a natural frequency. Numerical integration solvers like ode45 are not vulnerable to such difficulties.
MATLAB Example
Output Using Function Threemass
s t r d y n e q;
SOLUTION OF THE DIFFERENTIAL EQUATION M*Y''+C*Y'+K*Y=F1*COS(W*T)+F2*SIN(W*T)
Give t h e name o f a f u n c t i o n t o c r e a t e d a t a v a l u e s (Try t h r e e m a s s a s an example)
>? t h r e e m a s s
I n p u t c o o r d i n a t e number, t m i n and tmax
( o n l y p r e s s r e t u r n t o s t o p e x e c u t i o n ) >? 1,0,5 0
The v a l u e o f i*w i s a t d i s t a n c e 0.050001 from t h e e i g e n v a l u e - 0.0 5 + 1.4 1 3 3 i
I n p u t c o o r d i n a t e number, t m i n and tmax
( o n l y p r e s s r e t u r n t o s t o p e x e c u t i o n ) >? 2,0,5 0
I n p u t c o o r d i n a t e number, t m i n and tmax ( o n l y p r e s s r e t u r n t o s t o p e x e c u t i o n ) >?
The s y s t e m e i g e n v a l u e s a r e:
lam =
- 0.0 1 4 6 - 0.7 6 5 2 i - 0.0 1 4 6 + 0.7 6 5 2 i - 0.0 5 0 0 - 1.4 1 3 3 i - 0.0 5 0 0 + 1.4 1 3 3 i - 0.0 8 5 4 - 1.8 4 5 8 i - 0.0 8 5 4 + 1.8 4 5 8 i
Range o f s o l u t i o n v a l u e s f o r f i n a l t i m e s i s:
maxy =
6.4 2 5 5 0.0 0 0 0 6.4 9 3 5
miny =
- 6.4 9 3 5 - 0.0 0 0 0 - 6.4 2 5 5
A l l done
RESPONSE VARIABLE NUMBER 1
time
Figure 3.5: Motion of Mass 1 in Threemass Model
y(2)
RESPONSE VARIABLE NUMBER 2
time
Figure 3.6: Motion of Mass 2 in Threemass Model
Motion of First and Second Mass MATLAB Code
f u n c t i o n [ t,y,l a m ] = s t r d y n e q %
% [ t,y,l a m ] = s t r d y n e q %.............................................
% T h i s p r o g r a m i n t e g r a t e s t h e s t r u c t u r a l dynamics % e q u a t i o n c h a r a c t e r i z e d by a g e n e r a l s e c o n d o r d e r % m a t r i x d i f f e r e n t i a l e q u a t i o n h a v i n g a h a r m o n i c % f o r c i n g f u n c t i o n. I n p u t i n v o l v e s m a s s, s t i f f n e s s,
% and damping m a t r i c e s a s w e l l a s f o r c e m a g n i t u d e s,
% a f o r c i n g f r e q u e n c y, and i n i t i a l c o n d i t i o n s. D a t a % p a r a m e t e r s f o r t h e p r o g r a m a r e c r e a t e d i n a u s e r % s u p p l i e d f u n c t i o n p r o v i d e d by t h e u s e r. ( F o r an % e x a m p l e, s e e f u n c t i o n t h r e e m a s s shown b e l o w.)
t i t l = ['\n S O L U T I O N OF THE DIFFERENTIAL EQUA T ION\n',...
'M*Y''''+C*Y''+K*Y=F1*COS(W*T )+F2*SIN(W*T)\n\n'];
f p r i n t f ( t i t l );
d i s p (...
'G i v e t h e name o f a f u n c t i o n t o c r e a t e d a t a v a l u e s') d i s p ('( T r y t h r e e m a s s a s an e x a m p l e )') n a m e = i n p u t ('>? ','s');
e v a l ( ['[ m,c,k,f 1,f 2,w,n t,y 0,v 0 ] =',n a m e,';'] ); j j = 1; w h i l e 1
f p r i n t f ('\n I n p u t c o o r d i n a t e number, t m i n and t m a x') f p r i n t f ('\n ( o n l y p r e s s r e t u r n t o s t o p e x e c u t i o n )') [ j,t 1,t 2 ] = i n p u t v ('>? '); i f i s n a n ( j ), b r e a k; e n d; J = i n t 2 s t r ( j ); [ t,y,l a m ] = f h r m c k ( m,c,k,f 1,f 2,w,[ t 1,t 2 ],n t,y 0,v 0 ); i f i s n a n ( t ), r e t u r n, end
[ d i f,h ] = m i n ( a b s ( l a m - i * w ) ); l j = n u m 2 s t r ( l a m ( h ) ); i f j j = = 1, j j = j j + 1; d i s p (' ')
d i s p ( ['T h e v a l u e o f i*w i s a t d i s t a n c e ',...
n u m 2 s t r ( d i f ) ] ) d i s p ( ['f r o m t h e e i g e n v a l u e ',l j ] ) end
p l o t ( t,y (:,j ),'k -'), x l a b e l ('t i m e') y l a b e l ( ['y (',J,')'] )
t i t l e ( ['R E S P O N S E VARIABLE NUMBER ',J ] ) g r i d o n, s h g, d u m y = i n p u t (' ','s'); end
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
74
75
76
77
78
79
80
81
82
83
84
85
f p r i n t f ('\n T h e s y s t e m e i g e n v a l u e s a r e:\n')
d i s p l a y ( l a m )
f p r i n t f (...
'R an g e o f s o l u t i o n v a l u e s f o r f i n a l t i m e s i s:\n') maxy=max(y); m i n y = m in ( y ); d i s p l a y ( m a x y ) d i s p l a y ( m i n y ), f p r i n t f ('A l l d o n e\n')
%================================================
f u n c t i o n [ m,c,k,f 1,f 2,w,n t,y 0,v 0 ] = t h r e e m a s s %
% [ m,c,k,f 1,f 2,w,n t,y 0,v 0 ] = t h r e e m a s s
%.......................................................................................
% T h i s f u n c t i o n c r e a t e s d a t a f o r a t h r e e mass % s y s t e m. The name o f t h e f u n c t i o n s h o u l d be % c h a n g ed t o s p e c i f y d i f f e r e n t p r o b l e m s. However,
% t h e o u t p u t v a r i a b l e l i s t s h o u l d r e m a i n u n c h a n g e d % f o r c o m p a t i b i l i t y w i t h t h e d a t a i n p u t p r o g r a m.
m = e y e ( 3,3 ); k = [ 2,- 1,0;- 1,2,- 1;0,- 1,2 ]; c =.0 5 * k;
% D a t a t o e x c i t e t h e h i g h e s t mode f 1 = [ - 1;0;1 ]; f 2 = [ 0;0;0 ]; w=1.413; n t = 1 0 0 0;
% D a t a t o e x c i t e t h e l o w e s t mode % f 1 = [ 1;1;1 ]; f 2 = [ 0;0;0 ]; w=.7652; n t = 1 0 0 0;
% Homogeneous i n i t i a l c o n d i t i o n s y 0 = [ -.5;0;.5 ]; v 0 = z e r o s ( 3,1 ); y0=0*y0;
%================================================
f u n c t i o n [ t,y,l a m ] = f h r m c k ( m,c,k,f 1,f 2,w,t l i m,n t,y 0,v 0 ) %
% [ t,y,l a m ] = f h r m c k ( m,c,k,f 1,f 2,w,t l i m,n t,y 0,v 0 )
%..................................................................................................................
% T h i s f u n c t i o n u s e s e i g e n f u n c t i o n a n a l y s i s t o s o l v e % t h e m a t r i x d i f f e r e n t i a l e q u a t i o n
% m * y''( t ) + c * y'( t ) + k * y ( t ) = f 1 * c o s ( w * t ) + f 2 * s i n ( w * t )
% w i t h i n i t i a l c o n d i t i o n s o f y ( 0 ) = y 0, y'( 0 ) = v 0 % The s o l u t i o n i s g e n e r a l u n l e s s 1) a z e r o o r r e p e a t e d % e i g e n v a l u e o c c u r s o r 2) t h e s y s t e m i s undamped and % t h e f o r c i n g f u n c t i o n m a t c h e s a n a t u r a l f r e q u e n c y.
% I f e i t h e r e r r o r c o n d i t i o n o c c u r s, p r o g r a m e x e c u t i o n % t e r m i n a t e s w i t h t and y s e t t o n a n.
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
%
% m,c,k - m a s s, damping, and s t i f f n e s s m a t r i c e s
% f 1,f 2 - a m p l i t u d e v e c t o r s f o r t h e s i n e and c o s i n e
% f o r c i n g f u n c t i o n components
% w - f r e q u e n c y o f t h e f o r c i n g f u n c t i o n
% t l i m - a v e c t o r c o n t a i n i n g t h e minimum and
% maximum t i m e l i m i t s f o r e v a l u a t i o n of
% t h e s o l u t i o n
% n t - t h e number o f t i m e s a t whi ch t h e s o l u t i o n
% i s e v a l u a t e d w i t h i n t h e c h o s e n l i m i t s
% f o r whi ch y ( t ) i s computed
% y 0,v 0 - i n i t i a l p o s i t i o n and v e l o c i t y v e c t o r s
%
% t - v e c t o r o f t i m e v a l u e s f o r t h e s o l u t i o n
% y - m a t r i x o f s o l u t i o n v a l u e s where y ( i,j )
% i s t h e v a l u e o f component j a t t i m e t ( i )
% lam - t h e complex n a t u r a l f r e q u e n c i e s a r r a n g e d
% i n o r d e r o f i n c r e a s i n g a b s o l u t e v a l u e
i f n a r g i n = = 0 % G e n e r a t e d e f a u l t d a t a u s i n g 2 m a s s e s m = e y e ( 2,2 ); k = [ 2,- 1;- 1,1 ]; c =.3 * k; f 1 = [ 0;1 ]; f 2 = [ 0;0 ]; w=0.6; t l i m = [ 0,1 0 0 ]; n t = 4 0 0; end
n = s i z e ( m,1 ); t = l i n s p a c e ( t l i m ( 1 ),t l i m ( 2 ),n t ); i f n a r g i n < 1 0, y 0 = z e r o s ( n,1 ); v0=y0; end
% D e t e r m i n e e i g e n v a l u e s and e i g e n v e c t o r s f o r % t h e homogeneous s o l u t i o n A = [ z e r o s ( n,n ), e y e ( n,n ); - m\[ k, c ] ];
[ U,l a m ] = e i g ( A ); [ l a m,j ] = s o r t ( d i a g ( l a m ) ); U = U (:,j );
% Check f o r z e r o o r r e p e a t e d e i g e n v a l u e s and % f o r undamped r e s o n a n c e w m i n = a b s ( l a m ( 1 ) ); t o l = w m i n/1 e 6; [ d i f,J ] = m i n ( a b s ( l a m - i * w ) ); l j = n u m 2 s t r ( l a m ( J ) ); i f wmin==0, d i s p (' ')
d i s p ('T h e homogeneous e q u a t i o n h a s a z e r o') d i s p ('e i g e n v a l u e whi ch i s n o t a l l o w e d.') d i s p ('E x e c u t i o n i s t e r m i n a t e d'), d i s p (' ') t = n a n; y=nan; r e t u r n e l s e i f a n y ( a b s ( d i f f ( l a m ) ) < t o l )
d i s p ('A r e p e a t e d e i g e n v a l u e o c c u r r e d.') d i s p ('E x e c u t i o n i s t e r m i n a t e d'),d i s p (' ') t = n a n; y=nan; r e t u r n e l s e i f d i f < t o l & s u m ( a b s ( c (:) ) ) = = 0
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
d i s p ('T h e s y s t e m i s undamped and t h e f o r c i n g') d i s p ( ['f u n c t i o n r e s o n a t e s w i t h ',...
'e i g e n v a l u e ',l j ] ) d i s p ('E x e c u t i o n i s t e r m i n a t e d.') d i s p (' '), t = n a n; y = n a n; r e t u r n e l s e
% D e t e r m i n e t h e p a r t i c u l a r s o l u t i o n a = ( - w ~ 2 * m + k + i * w * c )\( f 1 - i * f 2 ); y p = r e a l ( a * e x p ( i * w * t ) ); y p 0 = r e a l ( a ); v p 0 = r e a l ( i * w * a ); e n d
% S c a l e t h e h o m o g e n e o u s s o l u t i o n t o s a t i s f y t h e % i n i t i a l c o n d i t i o n s U = U * d i a g ( U\[ y 0 - y p 0; v 0 - v p 0 ] ); y h = r e a l ( U ( 1:n,:) * e x p ( l a m * t ) );
% C o m b i n e r e s u l t s t o o b t a i n t h e t o t a l s o l u t i o n t = t (:); y = [ y p + y h ]';
% S h o w d a t a g r a p h i c a l l y o n l y f o r d e f a u l t c a s e i f n a r g i n = = 0
w a t e r f a l l ( t,( 1:n ),y'), x l a b e l ('t i m e a x i s') y l a b e l ('m a s s i n d e x'), z l a b e l ('D i s p l a c e m e n t s') t i t l e ( ['D I S P L A C E M E N T H I S T O R Y F O R A ',...
i n t 2 s t r ( n ),'- M A S S S Y S T E M'] ) c o l o r m a p ( [ 1,0,0 ] ), s h g e n d
3.6 C o m p u t i n g N a t u r a l F r e q u e n c i e s f o r a R e c t a n g u l a r Me m b r a n e
O n e o f t h e m o s t u s e f u l a p p l i c a t i o n s o f e i g e n v a l u e p r o b l e m s o c c u r s i n n a t u r a l f r e ­
q u e n c y c a l c u l a t i o n s f o r l i n e a r s y s t e m s. L e t u s e x a m i n e f i n i t e d i f f e r e n c e a p p r o x ­
i m a t i o n f o r t h e n a t u r a l f r e q u e n c i e s o f a r e c t a n g u l a r m e m b r a n e a n d h o w w e l l t h e a p p r o x i m a t e r e s u l t s c o m p a r e w i t h e x a c t v a l u e s. C o n s i d e r a t i g h t l y s t r e t c h e d e l a s ­
t i c m e m b r a n e o c c u p y i n g a r e g i o n R in the (x, y) bounded by a curve L on which the transverse deflection is zero. The differential equation and boundary conditions governing the transverse motion U(x, y, t) are
T(Uxx + Uyy) — pUtt , (xi y)£R,
U(x,y,t ) — 0 , (x,y)eL,
where T and ρ denote membrane tension and mass density. The natural vibration modes are motion states where all points of the system simultaneously move with the same frequency, which says U(x, y, t) — u(x, y) sin(Qt). It follows that u(x, y) satisfies
uxx + uyy ω u , (x, y) ,
u(x,y) — 0, (x,y)eL,
wher e ω = In the simple case of a rectangular membrane lying in the region
such that 0 < x < a and 0 < y < 6, the natural frequencies and mode shapes turn out to be
where n and m are positive integers. It is interesting to see how closely these values
can be reproduced when the partial differential equation is replaced by a second
order finite difference approximation defined on a rectangular grid. We introduce grid points expressed as
x(i) — (i - 1)Δχ , i — 1,...,N,
y(j) — (j - l ) Δy, j — 1,...,M,
where
Δχ — a/( N - 1), Δy — b/( M - 1),
and we call u(i,j ) the value of u at x( i ),y( j ). Then the Helmholtz equation is replaced by an algebraic eigenvalue problem of the form
Δ [u(i - 1, j ) - 2u(i, j ) + u(i + 1, j)] + Δ X[u(i, j - 1 )
- 2u(i, j ) +u(i, j + 1)] — Xu(i, j )
wher e
λ — ( Δχ Δ ω)2
and associ at ed homogeneous boundar y condi t i ons
u(1,j) — u( N,j ) — u(i, 1) — u(i, M ) — 0.
This combination of equations can be rearranged into familiar matrix form as
Au — Xu, Bu — 0.
The MATLAB function null can be used to solve the boundary condition equations. We write as u — Qz where Q — null(B) has orthonormal columns. Substituting into the eigenvalue equation and multiplying both sides by Q' then yields a standard eigenvalue problem of the form Cz — Xz where C — Q 'AQ. Denoting the eigen­
vector matrix of C by V, the eigenvector matrix of the original problem is obtained as u — QV, and the desired eigenvalues are simply those of matrix C.
A short function named recmemfr was written to form and solve the algebraic equations just discussed. Although the ideas are simple, indexing the double in­
dexed quantities pertaining to the finite difference grid is slightly tedious. Intrinsic functions ind2sub and sub2ind are helpful to perform the indexing. Lines 32-34 of rememfr compute a subset of the lowest frequency values and sort these in as­
cending order. Lines 37-45 form the homogeneous boundary conditions, and lines 51-56 construct the discretized Helmholtz equation at interior node points. The main computation work is done in lines 59-61 where null and eig are used. Finally, the results are sorted, the modal arrays are reshaped, and results are plotted to com­
pare the approximate and exact frequencies. In the graph shown below for the case where (a,b)=(2,1), the frequencies obtained using the finite differences are seen to be consistently low. Furthermore, the 50’th frequency is off by about 14 percent, even though 200 grid points were used. Applications leading to eigenvalue problems occur frequently. The ideas touched on in this simple example will be encountered again in Chapters 9 and 10. Readers may find it interesting to modify this exam­
ple using a higher order difference approximation to see how much the frequency estimates improve.
MEMBRANE FREQUENCIES FOR AX / BY = 2 AND 200 GRID POINTS
frequency number
Figure 3.7: Approximate and Exact Frequencies for a Rectangular
Membrane
Function recmemfr
f u n c t i o n [ w,w e x,m o d e s,x,y,n x,n y,a x,b y ] = r e c m e m f r (...
a x,b y,n x,n y,n o p l t )
%
% [ w,w e x,m o d e s,x,y,n x,n y,a x,b y ] = r e c m e m f r ( a,b,n x,n y,n o p l t )
%............................................................................................................................................
% T h i s f u n c t i o n employs f i n i t e d i f f e r e n c e met hods t o % e s t i m a t e t h e n a t u r a l f r e q u e n c i e s and mode s h a p e s of % a r e c t a n g u l a r membrane h a v i n g f i x e d e d g e s.
% a x, by - membrane s i d e l e n g t h s a l o n g t h e x and y a x e s
% n x,n y - number o f f i n i t e d i f f e r e n c e p o i n t s t a k e n i n
% t h e x and y d i r e c t i o n s i n c l u d i n g t h e e d g e s
% w - v e c t o r o f ( n x - 2 ) * ( n y - 2 ) f r e q u e n c i e s o b t a i n e d
% by f i n i t e d i f f e r e n c e a p p r o x i m a t i o n o f t h e
% wave e q u a t i o n. T h es e a r e a r r a n g e d i n
% i n c r e a s i n g o r d e r
% wex - v e c t o r o f e x a c t f r e q u e n c i e s
% modes - t h r e e d i m e n s i o n a l a r r a y c o n t a i n i n g t h e mode
% s h a p e s f o r v a r i o u s f r e q u e n c i e s. The a r r a y
% s i z e i s [ n x,n y,( n x - 2 ) * ( n x - 2 ) ] d e n o t i n g
% t h e x d i r e c t i o n, y d i r e c t i o n, and t h e
% f r e q e n c y numbers m a t c h i n g components o f t h e
% w v e c t o r. The i't h mode s h a p e i s o b t a i n e d
% a s r e s h a p e ( v e c s (:,i ),n,m )
% x,y - v e c t o r s d e f i n i n g t h e f i n i t e d i f f e r e n c e g r i d
% n o p l t - o p t i o n a l p a r a m e t e r i n c l u d e d i f no p l o t of
% t h e a p p r o x i m a t e and e x a c t f r e q u e n c i e s i s t o
% be made
i f n a r g i n = = 0; ax=2; nx=20; by=1; ny=10; end d x = a x/( n x - 1 ); d y = b y/( n y - l ); n a = ( 1:n x - 1 )'/a x; n b = ( 1:n y - 1 )/b y;
% Compute e x a c t f r e q u e n c i e s f o r c o m p a r i s o n w e x = p i * s q r t ( r e p m a t ( n a.~ 2,1,n y - 1 ) + r e p m a t ( n b.~ 2,n x - 1,1 ) ); w e x = s o r t ( w e x (:)'); x = l i n s p a c e ( 0,a x,n x ); y = l i n s p a c e ( 0,b y,n y ); n e i g = ( n x - 2 ) * ( n y - 2 ); n v ar = n x * n y;
% Form e q u a t i o n s t o f i x membrane e d g e s k=0; s = [ n x,n y ]; c = z e r o s ( 2 * ( n x + n y ),n v a r ); f o r j = 1:n x
m = s u b 2 i n d ( s,[ j,j ],[ 1,n y ] ); k=k+1;
c ( k,m ( 1 ) ) = 1; k=k+1; c ( k,m ( 2 ) ) = 1; end
f o r j = 1:n y
m = s u b 2 i n d ( s,[ 1,n x ],[ j,j ] ); k=k+1; c ( k,m ( 1 ) ) = 1; k=k+1; c ( k,m ( 2 ) ) = 1; end
% Form f r e q u e n c y e q u a t i o n s a t i n t e r i o r p o i n t s k=0; a = z e r o s ( n e i g,n v a r ); b=a; p h i = ( d x/d y ) ~ 2; p s i = 2 * ( 1 + p h i ); f o r i = 2:n x - 1 f o r j = 2:n y - 1
m = s u b 2 i n d ( s,[ i - 1,i,i + 1,i,i ],[ j,j,j,j - 1,j + 1 ] ); k=k+1; a ( k,m ( 1 ) ) = - 1; a ( k,m ( 2 ) ) = p s i; a ( k,m ( 3 ) ) = - 1; a ( k,m ( 4 ) ) = - p h i; a ( k,m ( 5 ) ) = - p h i; b ( k,m ( 2 ) ) = 1; end end
% Compute f r e q u e n c i e s and mode s h a p e s q = n u l l ( c ); A=a*q; B=b*q; [ m o d e s,l a m ] = e i g ( B\A ); [ l a m,k ] = s o r t ( d i a g ( l a m ) ); w = s q r t ( l a m )'/d x; m o d e s = q * m o d e s (:,k ); m o d e s = r e s h a p e ( m o d e s (:),n x,n y,n e i g );
% P l o t f i r s t f i f t y a p p r o x i m a t e and e x a c t f r e q u e n c i e s i f n a r g i n > 4, r e t u r n, end m = 1:m i n ( [ 5 0,l e n g t h ( w ),l e n g t h ( w e x ) ] ); p c t e r = 1 0 0 * ( w e x ( m ) - w ( m ) )./w e x ( m );
c l f; p l o t ( m,w e x ( m ),'k -',m,w ( m ),'k.',m,p c t e r,'k —') x l a b e l ('f r e q u e n c y n u m b e r'); y l a b e l ('f r e q u e n c y and % e r r o r')
l e g e n d ('e x a c t f r e q u e n c y','a p p r o x. f r e q u e n c y',...
'p e r c e n t e r r o r',2 ) s=['MEMBRANE FREQUENCIES FOR AX / BY = ',... n u m 2 s t r ( a x/b y,5 ),' AND ',n u m 2 s t r ( n x * n y ),...
' GRID POINTS']; t i t l e ( s ), g r i d o n, s h g % p r i n t - d e p s re cmemfr
3.7 Column Space, Null Space, Orthonormal Bases, and SVD
One remaining advanced topic discussed in this chapter is the factorization known as singular value decomposition, or SVD. We will briefly explain the structure of
SVD and some of its applications. It is known that any real matrix having n rows, m columns, and rank r can be decomposed into the form
A = USV'
where
U is an orthogonal n by n matrix such that U 'U = I V is an orthogonal m by m matrix such that V 'V = I S is an n by m diagonal matrix of the form
σ\ 0 0 0 0 0
0 σ2 0 0 0 0
S
0 0 .. 0 0 0 0 0 0 στ 0 0
0 0 0 0 0 0
0 0 0 0 0 0
where σ\,.. .,σ τ are positive numbers on the main diagonal with σ % > σι+1. Constants σ0 are called the singular values with the number of nonzero values being equal to the rank r.
To understand the structure of this decomposition, let us study the case where n > m. Direct multiplication gives
A'AV = V d i a g ( ^,... ,σ 2, zeros(1, m — r)]),
and
AA'U = Ud i a g ( ^,. ..,σ 2, zeros(1, n — r)]).
Consequently, the singular values are square roots of the eigenvalues of the sym­
metric matrix A'A. Matrix V contains the orthonormalized eigenvectors arranged so that σι > σι+\. Although the eigenvalues of A'A are obviously real, it may appear that this matrix could have some negative eigenvalues leading to pure imag­
inary singular values. However, this cannot happen because A 'A Y = λ Υ implies λ = ( AY)'( AY)/( Y'Y), which clearly is nonnegative. Once the eigenvectors and eigenvalues of A'A are computed, columns of matrix U can be found as orthonor­
malized solutions of
[A'A — σ-jI]Uj = 0 , σ-j = 0 , j > r.
The ar gument s j us t pr esent ed show t hat per f or mi ng si ngul ar val ue decomposi t i on i n­
vol ves sol vi ng a symmet ri c ei genval ue pr obl em. However, SVD r equi r es addi t i onal comput at i on beyond sol vi ng a symmet r i c ei genval ue probl em. It can be ver y t i me consumi ng for l arge mat ri ces. The SVD has var i ous uses, such as sol vi ng t he normal
equations. Suppose an n by m matrix A has n > m and r = m. Substituting the SVD into
MAX = A'B
gives
V d i a g ^ f,..., σ2ηι) V'X = VS'U'B.
Consequent l y, t he sol ut i on of t he nor mal equat i ons is
X = V d i a g ^ - 2,...^ m2)S 'U 'B.
Anot her i mpor t ant appl i cat i on of t he SVD concerns gener at i on of ort honormal bases for t he col umn space and t he r ow space. The col umn space has di mensi on r and the null space has dimension m — r. Consider a consistent system
AX = B = U (SV'X).
Denote S V'X as Y and observe that y0 = 0 for j > r since σ0 = 0. Because B can be any vector in the column space, it follows that the first r columns of U, which are also orthonormal, are a basis for the column space. Furthermore, the decomposition can be written as
AV = US.
This implies
AV0 = Ufe] = 0 , j > r
whi ch shows t hat t he fi nal m — r columns of V form an orthonormal basis for the null space. The reader can verify that bases for the row space and left null space follow analogously by considering A' = VS'U', which simply interchanges the roles of U and V
.
MATLAB provides numerous other useful matrix decompositions such as LU, QR, and Cholesky. Some of these are employed in other sections of this book. The reader will find it instructive to read the built-in help information for MATLAB func­
tions describing these decomposition methods. For instance, the command help \ gives extensive documentation on the operation for matrix inversion.
3.8 Computation Time to Run a MATLAB Program
MATLAB is designed to perform matrix computation with maximum speed and accuracy. Consequently, most standard operations like matrix multiplication, Gauss reduction, eigenvalue calculation, SVD, etc. are implemented as highly optimized and compiled intrinsic functions. Efficient program execution requires optimal use of the built-in functions. Executing nested loops can take a lot of time, so using coding with nested loops should be avoided when computation time is important. To
illustrate how deeply nested loops can slow down execution speed we will compare slow multiplication of square matrices by a Fortran style triple loop, and fast multi­
plication using the intrinsic matrix multiply capability. The ratio of the slow time to the fast time is much larger than might initially be expected.
Before proceeding with our example, consider the difficulties of accurately tim­
ing a computational process. In the first place, the clock in Intel based systems has a resolution of about 0.06 sec, whereas the time for MATLAB to do a 100 by 100 matrix multiply is about 0.005 secs on a 733 Mhz Pentium 4 computer. This implies that, just to account for the crude clock increment, the matrix multiply has to be re­
peated at least 1200 times to get a total time accurate within one percent. However, this is not the only timing difficulty. MATLAB continuously performs housekeep­
ing tasks such as memory management. The operating system and other programs running simultaneously in the background also use computer resources and affect recorded times. Hence, any timing of algorithmic processes in MATLAB should be done without having several other programs open. Even then, the authors have found that times recorded for the same computation done repeatedly often vary around five percent.
The following program named mattimer was written to compare slow and fast matrix multiplication. The program input includes the matrix order, the number of seconds a loop is performed to improve timing accuracy, and the number of times the basic timing operation is repeated to show how recorded times vary among suc­
cessive computations. The program also gives the number of floating operations performed per second (Mflops). An n by n matrix multiply involves n 2 dot prod­
ucts each requiring n adds and n multiplies. Hence, the number of floating point operations is 2n3. An order 100 matrix multiply done in 0.005 seconds would give 400 megaflops. Function multimer does the matrix multiply repeatedly and reads the elapsed time until the specified total number of seconds is reached. Performing loops and reading the clock takes some time, which is subtracted from the time to do the looping, matrix multiplication, and clock reading. We also perform the intrinsic matrix multiplication in a separate function so that both the fast and slow methods have the same computational overhead associated with a function call. Results are shown for matrices of order 100 and 1000. The fast time for an order 100 matrix multiply only took 0.00503 seconds giving 398 megaflops. By comparison, the slow method took more than eighteen hundred times as long as the fast method. This is comparable to making a one hour task take about two and a half months, working twenty-four hours a day, seven days a week. Evidently, intrinsic MATLAB matrix multiply works very well, but nested looping is slow. Something else worth noting is that a dense matrix of order 1000 does not stretch the capabilities of a modern micro­
computer. Storing a million word double-precision array only takes 8 megabytes of RAM, which is a small fraction of the 128 megabytes or more typically provided for scientific work. Furthermore, the high order matrix multiply only took 4.6 seconds, which is roughly 1000 times as long as the order 100 time. It turns out that the time needed for most matrix operations increases like the cube of the order, even though a complicated calculation such as singular value decomposition may take around seventeen times as long as a Gauss elimination of the same order.
> > m a t t i m e r ( 1 0 0,1 0,6 0 );
MATRI X MUL T I P L Y T I MI NG T E S T
G e t r e s u l t s f o r a s i n g l e t i m e r c a l l
T h e r e p e a t e d m u l t i p l i c a t i o n o f m a t r i c e s o f o r d e r 1 0 0 m a y t a k e c o n s i d e r a b l e t i m e.
F a s t m u l t i p l y t a k e s 0.0 0 5 0 2 3 8 s e c s. M e g a f l o p s = 3 9 8.1 0 3 4
S l o w m u l t i p l y t a k e s 9.0 7 1 4 s e c s. M e g a f l o p s = 3 9 8.1 0 3 4
t s l o w/t f a s t = 1 8 0 5.6 7 2 3
G e t r e s u l t s f o r t f a s t 5.0 4 7 3 e - 0 0 3 5.0 2 4 8 e - 0 0 3 4.9 9 4 8 e - 0 0 3 5.0 0 7 5 e - 0 0 3 5.3 7 7 5 e - 0 0 3 4.9 9 3 9 e - 0 0 3 5.0 0 1 3 e - 0 0 3 5.0 2 1 7 e - 0 0 3 5.0 1 8 2 e - 0 0 3 4.9 9 0 5 e - 0 0 3
s e v e r a l t i m e r t s l o w 8.8 8 9 9 e + 0 0 0 8.8 2 7 1 e + 0 0 0 8.9 6 8 5 e + 0 0 0 8.8 7 4 2 e + 0 0 0 8.9 5 9 9 e + 0 0 0 8.8 4 9 9 e + 0 0 0 8.8 2 7 1 e + 0 0 0 8.9 8 4 2 e + 0 0 0 9.0 7 8 5 e + 0 0 0 8.9 5 9 8 e + 0 0 0
c a l l s
r a t i o
1.7 6 1 3 e + 0 0 3
1.7 5 6 7 e + 0 0 3
1.7 9 5 6 e + 0 0 3
1.7 7 2 2 e + 0 0 3
1.6 6 6 2 e + 0 0 3
1.7 7 2 1 e + 0 0 3
1.7 6 5 0 e + 0 0 3
1.7 8 9 1 e + 0 0 3
1.8 0 9 1 e + 0 0 3
1.7 9 5 4 e + 0 0 3
T i m e v a r i a t i o n d e f i n e d b y ( m a x ( t ) - m i n ( t ) )/m e a n ( t ) V a r i a t i o n f o r t f a s t = 0.0 7 6 6 5 6 V a r i a t i o n f o r t s l o w = 0.0 2 8 1 8 1
> > m a t t i m e r ( 1 0 0 0,0,6 0 ); MATRI X MUL T I P L Y T I MI NG T E S T
G e t r e s u l t s f o r a s i n g l e t i m e r c a l l
T h e r e p e a t e d m u l t i p l i c a t i o n o f m a t r i c e s o f o r d e r 1 0 0 0 m a y t a k e c o n s i d e r a b l e t i m e.
F a s t m u l t i p l y t a k e s 4.5 6 9 9 s e c s.
M e g a f l o p s = 4 3 7.6 4 2 1
S l o w m u l t i p l y t a k e s 8 8 8 2.3 8 9 9 s e c s. M e g a f l o p s = 0.2 2 5 1 6
t s l o w/t f a s t = 1 9 4 3.6 5 4
P r o g r a m m a t t i m e r
i: f u n c t i o n m a t t i m e r ( n o r d e r,k t i m e s,s e c s )
2: %
3: % m a t t i m e r ( n o r d e r,k t i m e s,s e c s )
4: %.........................................................................................................................
5: i f n a r g i n = = 0
6: n o r d e r = 1 0 0; k t i m e s = 1 0; s e c s = 3 0;
7: e n d
8: f p r i n t f ('\n M A T R I X MUL T I P L Y T I MI N G T E S T\n\n')
9:
i 0: d i s p ('G e t r e s u l t s f o r a s i n g l e t i m e r c a l l')
i i:
i 2: m u l t i m e r ( n o r d e r,s e c s,1 ); t = z e r o s ( k t i m e s,3 );
i 3:
i 4: s e c s = m a x ( s e c s,3 0 ); i f k t i m e s = = 0, r e t u r n, e n d
1 5:
i 6: d i s p ('G e t r e s u l t s f o r s e v e r a l t i m e r c a l l s') i 7: f o r j = 1:k t i m e s
i 8: [ t ( j,3 ),t ( j,1 ),t ( j,2 ) ] = m u l t i m e r ( n o r d e r,s e c s );
i 9: e n d
2 0: T = ( m a x ( t ) - m i n ( t ) )./m e a n ( t );
2 i:
2 2: d i s p (...
2 3: ' t f a s t t s l o w r a t i o')
2 4: f o r j = 1:k t i m e s
2 5: f p r i n t f ('% 1 3.4 e % 1 3.4 e % 1 3.4 e\n',t ( j,:) )
2 6: e n d
2 7: d i s p (' '), d i s p (...
2 8: 'T i m e v a r i a t i o n d e f i n e d b y ( m a x ( t ) - m i n ( t ) )/m e a n ( t )') 2 9: d i s p ( ['V a r i a t i o n f o r t f a s t = ',n u m 2 s t r ( T ( 1 ) ) ] )
3 0: d i s p ( ['V a r i a t i o n f o r t s l o w = ',n u m 2 s t r ( T ( 2 ) ) ] )
3 i:
3 2: % = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
33:
34
35
36
37
38
39
40:
4 i
42:
43:
44
45
46
47
48
49
50:
5 i:
52:
53:
54
55
56
57:
58
59
60:
6 i:
62:
63:
64
65
66
67:
68
69
70:
7 i
72:
73:
74
75
76
77
f u n c t i o n [ r a t i o,t f a s t,t s l o w ] = m u l t i m e r (...
n o r d e r,s e c s,d o p r i n t )
% [ r a t i o,t f a s t,t s l o w ] = m u l t i m e r (...
% n o r d e r,s e c s,d o p r i n t )
% T h i s f u n c t i o n compares t h e t i m e s t o p e r f o r m a % m a t r i x m u l t i p l y u s i n g t h e b u i l t - i n m a t r i x m u l t i p l y % and t h e s l o w method e m p l o y i n g s c a l a r t r i p l e l o o p i n g. % The r a t i o o f compute t i m e s i l l u s t r a t e s how much % f a s t e r c o m p i l e d and v e c t o r i z e d m a t r i x o p e r a t i o n s % c a n be compared t o s i m i l a r c a l c u l a t i o n s u s i n g % i n t e r p r e t e d code w i t h s c a l a r l o o p i n g.
% n o r d e r - o r d e r o f t h e t e s t m a t r i c e s u s e d. The % d e f a u l t f o r n o r d e r i s 100.
% s e c s - number o f s e c o n d s e a c h c o m p u t a t i o n i s r u n % t o g e t a c c u r a t e t i m i n g. The d e f a u l t (a nd
% minimum v a l u e ) i s t h i r t y s e c o n d s.
% d o p r i n t - p r i n t i n t e r m e d i a t e r e s u l t s o n l y i f t h i s % v a r i a b l e i s g i v e n a v a l u e
% r a t i o - r a t i o o f s l o w t o f a s t m u l t i p l y t i m e s % t f a s t - t i m e i n s e c o n d s t o p e r f o r m a m u l t i p l y % u s i n g t h e b u i l t - i n p r e c o m p i l e d m a t r i x
% m u l t i p l y
% t s l o w - t i m e i n s e c o n d s t o p e r f o r m a m u l t i p l y % by t r i p l e l o o p method
% U s er m f u n c t i o n s c a l l e d: m a t m u l t f m a t m u l t s
% T y p i c a l r e s u l t s o b t a i n e d u s i n g a D e l l Di mensi on % XPS B733r c o m p u t e r w i t h 128MB o f RAM gave t h e % f o l l o w i n g v a l u e s:
% >> m a t t i m e r ( 1 0 0,0,6 0 );
% MATRIX MULTIPLY TIMING TEST
% F a s t m u l t i p l y t a k e s 0.0 0 5 0 2 3 8 s e c s.
% M e g a f l o p s = 3 9 8.1 0 3 4
% Slow m u l t i p l y t a k e s 9.0 7 1 4 s e c s.
% M e g a f l o p s = 3 9 8.1 0 3 4
t s l o w/t f a s t = 18 0 5.6 7 2 3
78: % >> m a t t i m e r ( 1 0 0 0,0,6 0 );
7 9: %
8 0: % MATRIX MULTIPLY TIMING TEST
8 i: %
8 2: % F a s t m u l t i p l y t a k e s 4.5 6 9 9 s e c s.
8 3: % Me g a f l o p s = 43 7.6 4 2 1
8 4: %
8 5: % Slow m u l t i p l y t a k e s 8 8 8 2.3 8 9 9 s e c s.
8 6: % Me g a f l o p s = 0.2 2 5 1 6
8 7: %
8 8: % t s l o w/t f a s t = 19 4 3.6 5 4
8 9: % >>
90:
9 i: % F i n d t i m e t o make a l o o p and c a l l t h e c l o c k 9 2: nmax=5e3; n c l o c k = 0; t s t a r t = c p u t i m e;
9 3: w h i l e ncl ock<nmax
9 4: t c l o c k = c p u t i m e - t s t a r t; n c l o c k = n c l o c k + 1;
9 5: end
9 6: % Time t o do one l o o p and c a l l t h e t i m e r 9 7: t c l o c k = t c l o c k/n c l o c k;
98:
9 9: i f n a r g i n < 3, d o p r i n t = 0; e l s e, d o p r i n t = 1; end i o o: i f n a r g i n < 2, s e c s = 3 0; e nd; s e c s = m a x ( s e c s,3 0 ); i o i: i f n a r g i n = = 0, n o r d e r = 1 0 0; end i o 2: a = r a n d ( n o r d e r,n o r d e r ); b = r a n d ( n o r d e r,n o r d e r );
i 0 3:
i o 4: i f d o p r i n t
i 0 5: d i s p (' ')
i o 6: d i s p ('T h e r e p e a t e d m u l t i p l i c a t i o n o f m a t r i c e s')
i o 7: d i s p ( ['o f o r d e r ',n u m 2 s t r ( n o r d e r ),...
i o 8: ' may t a k e c o n s i d e r a b l e t i m e.'] )
i o 9: d i s p (' ')
i i o: end
i i i:
i i 2: % Time u s i n g i n t r i n s i c m u l t i p l y f u n c t i o n i i 3: p a c k; t f a s t = 0; n f a s t = 0; t s t a r t = c p u t i m e; i i 4: w h i l e t f a s t < s e c s
i i 5: c f = m a t m u l t f ( a,b ); n f a s t = n f a s t + 1;
i i 6: t f a s t = c p u t i m e - t s t a r t;
i i 7: end
i i 8: t f a s t = t f a s t/n f a s t - t c l o c k;
i i 9:
i 2 0: % Time u s i n g F o r t r a n s t y l e, t r i p l e f o r:n e x t l o o p i n g i 2 i: p a c k; t s l o w = 0; ns l ow=0; t s t a r t = c p u t i m e; i 2 2: w h i l e t s l o w < s e c s
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
c s = m a t m u l t s ( a,b ); nslow=nslow+1; t s l o w = c p u t i m e - t s t a r t;
end
t s l o w = t s l o w/n s l o w - t c l o c k; r a t i o = t s l o w/t f a s t; m f l o p s = i n l i n e ('n u m 2 s t r ( 2 * n ~ 3/1 e 6/t )','n','t'); i f d o p r i n t
d i s p ( ['F a s t m u l t i p l y t a k e s ',...
n u m 2 s t r ( t f a s t ),' s e c s.'] ) d i s p ( ['M e g a f l o p s = ',...
m f l o p s ( n o r d e r,t f a s t ) ] ), d i s p (' ') d i s p ( ['S l o w m u l t i p l y t a k e s ',...
n u m 2 s t r ( t s l o w ),' s e c s.'] ) d i s p ( ['M e g a f l o p s = ',...
m f l o p s ( n o r d e r,t s l o w ) ] ), d i s p (' ') d i s p ( ['t s l o w/t f a s t = ',...
n u m 2 s t r ( t s l o w/t f a s t ) ] ), d i s p (' ')
end
%===========================================
f u n c t i o n v=mat mul tf (a,b)
% v = m a t m u l t f ( a,b ). Matrix m u l t i p l y u s i n g % precompi led f u n c t i o n i n MATLAB v=a*b;
%===========================================
f u n c t i o n v=mat mul ts( a,b)
% v = m a t m u l t s ( a,b ). Matrix m u l t i p l y u s i n g % F o r t r a n l i k e t r i p l e loop n = s i z e ( a,1 ); m = s i z e ( b,2 ); K = s i z e ( a,2 ); v=z e r os ( n,m); f o r i = 1:n f o r j=1:m t=0;
f o r k=1:K
t = t + a ( i,k ) * b ( k,j );
end
v ( i,j ) = t;
end
end
Chapiter 4
Methods for Interpolation and Numerical Differentiation
4.1 Concepts of Interpolation
Next we study three types of one-dimensional interpolation: polynomial, piece­
wise linear, and cubic spline. The MATLAB functions implementing these methods are discussed along with some additional software developed by the authors to differ­
entiate and integrate splines. A simple discussion of cubic spline interpolation for­
mulated from the viewpoint of elastic beam flexure is given. The chapter concludes with a program to compute finite difference formulas for derivatives of general order.
Interpolation is a process whereby a function is approximated using data known at a discrete set of points. Typically we have points ( xi,yi ) arranged such that xi < xi+l. These points are to be connected by a continuous interpolation func­
tion influenced by smoothness requirements such as: a) the function should not de­
viate greatly from the data at points lying between the data values; and b) the func­
tion should satisfy a differentiability condition such as continuity of first and second derivatives.
Piecewise linear interpolation simply connects successive points by straight lines. This has the disadvantage of producing a function with piecewise constant slope and finite slope discontinuities. An obvious cure for slope discontinuity is to use a curve such as a polynomial of degree n-1 (through n points) to produce an interpo­
lation function having all derivatives continuous. However, it was seen in Section 2.3 that a polynomial passing exactly through the data points may be highly irreg­
ular at intermediate values. Using polynomial interpolations higher than order five or six often produces disappointing results. An excellent alternative to allowing ei­
ther slope discontinuities or demanding slope continuity of all orders is to use cubic spline interpolation. This method connects successive points by cubic curves joined such that function continuity as well as continuity of the first two function derivatives is achieved.
The MATLAB function polyfit(xd,yd,n) can be used to obtain coefficients in a polynomial of degree n which either passes through points in data vectors (xd,yd) or fits the data in the least square sense. Since a polynomial of degree n-1 can pass through n data points, the computation c=polyfit(xd,yd,length(xd)-1) would produce coefficients in a polynomial passing through the data values. Evaluating the polyno-
mial for an array argument x is accomplished by y=polyval(c,x). Combining the two operations gives y=polyval(polyfit(xd,yd,length(xd)-1),x). If the chosen poly­
nomial order is less than length(xd)-1, then a polynomial fitting the data in the least square sense is produced. For example, a polynomial of order 4 might be fitted to several hundred points. Of course, how well the least square polynomial actually fits the data should be assessed by examining a plot of the curve and the data. MATLAB also has various utility functions to work with polynomials such as polyder, polyint, conv, and deconv which differentiate, integrate, multiply, and divide.
Function interp1(xd,yd,x,’method’,’extrap’) is a general purpose interpolation func­
tion providing several types of interpolation including linear and spline. The default value for ‘method’ is ‘linear’, If the ‘extrap’ parameter is omitted, then a value of NaN (not a number) is returned for any input argument not lying between min(xd) and max(xd). Otherwise, extrapolation is performed using the interpolation func­
tions for the outermost intervals. Readers should be cautious about extrapolating far outside the known data range, because this often leads to unreasonable results.
Engineering applications often use idealized functions which are piecewise linear and have finite jump discontinuities. Since function interpl rejects cases where any successive values in the xd vector are equal, we remedy this situation with function lintrp(xd,yd,x) to search xd for any repeated values and separate these values by a small fraction of max(xd)-min(xd). Then interpl is used to perform the interpolation as indicated below.
Function lintrp
i: f u n c t i o n y = l i n t r p ( x d,y d,x )
2: %
3: % y = l i n t r p ( x d,y d,x )
4: %...........................................................................
5: % T h i s f u n c t i o n p e r f o r m s p i e c e w i s e l i n e a r
6: % i n t e r p o l a t i o n t h r o u g h d a t a v a l u e s s t o r e d i n
7: % x d, y d, wher e xd v a l u e s a r e a r r a n g e d i n
8: % n o n d e c r e a s i n g o r d e r. The f u n c t i o n c a n h a n d l e 9: % d i s c o n t i n u o u s f u n c t i o n s s p e c i f i e d when some i o: % s u c c e s s i v e v a l u e s i n xd a r e e q u a l. Then t h e i i: % r e p e a t e d xd v a l u e s a r e s h i f t e d by a s m a l l i 2: % amount t o remove t h e d i s c o n t i n u i t i e s. i 3: % I n t e r p o l a t i o n f o r any p o i n t s o u t s i d e t h e r a n g e
i 4: % of xd i s a l s o p e r f o r m e d by c o n t i n u i n g t h e l i n e
i 5: % s e g me n t s t h r o u g h t h e o u t e r m o s t d a t a p a i r s.
i 6: %
i 7: % x d,y d - v e c t o r s of i n t e r p o l a t i o n d a t a v a l u e s i 8: % x - m a t r i x o f v a l u e s wher e i n t e r p o l a t e d i 9: % v a l u e s a r e r e q u i r e d
2i: % y - m a t r i x o f i n t e r p o l a t e d v a l u e s
22:
2 3: k = f i n d ( d i f f ( x d ) = = 0 );
2 4: i f l e n g t h ( k ) ~ = 0
2 5: x d ( k + 1 ) = x d ( k + 1 ) + ( x d ( e n d ) - x d ( 1 ) ) * 1 e 3 * e p s;
2 6: end
2 7: y = i n t e r p 1 ( x d,y d,x,'l i n e a r', 'e x t r a p');
2o: %
4.2 Interpolation, Differentiation, and Integration by Cubic Splines
Cubic spline interpolation is a versatile method to pass a smooth curve through a sequence of data points. The technique connects the data values with a curve having its third derivative piecewise constant. The curve is piecewise cubic with y(x), y’(x) and y”(x) continuous over the whole data range. The Mat hWor ks markets a Spline Toolbox providing extensive capabilities to work with spline functions. A few func­
tions from that toolbox are included in standard MATLAB. The intrinsic functions spline, ppval, mkpp, and unmkpp are extended here to handle differentiation and integration. Spline interpolation, viewed from Euler beam theory, is also discussed to amplify on the basic ideas. This simple formulation easily accommodates various end conditions. Readers wanting more detail on spline theory will find the books by de Boor [27] and by Ahlberg and Nilson [2] to be helpful.
Cubic spline theory is motivated by a mechanical drafting tool consisting of a flexible strip bent over several supports with heights adjustable to fit given data. Euler beam theory [9] shows that the deflection curve has third derivative values which are constant between successive supports. This implies that the curve is piecewise cubic and the third derivative values (relating to internal shear forces in beam analysis) can be determined to make the support deflections have chosen values. This is the basis of cubic spline interpolation. The method is attractive because the interpolation function y(x)
is obtainable analytically as well as y'(x), y''(x)
and / y(x)dx.
Let us f or mul at e t he pr obl em mat hemat i cal l y by t aki ng a pi ecewi se const ant f or m f or y'''(x) and integrating this repeatedly to get y (x). We assume data points (x i,yi ), 1 < i < n with xi < xi+l. Each successive data pair can be connected by a cubic curve with y'(x) and y''(x) required to be continuous at all interior data points. If values of y'(x) or y''(x) are known at the curve ends, algebraic conditions to impose those values can be written. Using known values of end slope is appropriate, but specifying good second derivative values when end slopes are not known is usually not obvious. As an alternative, it is customary to apply smoothness conditions re­
quiring continuity of y'''(x2) and y'''(xn -\). Books on spline theory [7, 2] refer to imposition of higher order continuity at interior points as ”not-a-knot” conditions.
The piecewise constant third derivative of the interpolation function is described as
n- 1
y'''(x) Cj < x — Xj > 0
j = 1
where Cj are constants to be determined, and the singularity function
< x — a >n= (x — a)n(x > a)
is used. This formula for y'''(x) is easy to integrate, and making the curve pass through the data points is straightforward. It follows that
n- 1
y''(x) = y 1 + Y Cj < x — xj >\ j=1
n- 1
2 / > ^ ^ ^j ~
j=1
n 1
y'(x) = Vi + Vi (x - xi) + \ 53 c3 < x ~ xi >2>
y(x) = y i + yi(x - χ ι) + \y\ (χ - χ ι)2 + ^ 53 c j < χ - χ ί >3,
j=1
/
1 r 1 n
y ( x ) d x = y i { x - xi ) + - y ^ x - x i)2 + - y± (x - x i )3
X1
1 n - 1
+ 2 4 Σ x >4 '
j=1
The interpolation function automatically goes through the first data point, and the remaining constants are required to satisfy
r 1 rr 1 n - 1 2/i — 2/1 = Di{xi ~ χ ι) + (x i ~ x i ) 2 + g 5 3 c3 K Xi ~ x3 >3’ * = 2, 3,... ,n.
j=1
Since n + 1 unknowns are present in the above system, two more end conditions must be included. Five familiar combinations of end conditions include: 1) the ”not- a-knot” condition applied at each end; 2) the slope given at each end; 3) the slope given at the left end and the ”not-a-knot” condition at the right end; 4) the ”not-a- knot” condition at the left end and the slope given at the right end; and 5) a periodic spline is created by making the first and last points have the same values of y, y', and y''.
Spline interpolation involves solution of linear simultaneous equations. A desktop computer solves a system of 200 equations in less than 0.03 seconds; so, the equation solving time is modest unless many points are used. The formulation described above is easy to understand, handles general end conditions, and includes interpolation,
X
differentiation, and integration. It was implemented in two general purpose functions spterp and spcof used below with function curvprop to compute the length and area bounded by a spline curve. Another function splineg using intrinsic function spline is also discussed at the end of the present article. The spline routines provided here are helpful additions for work with splines since they include spline differentiation and integration which do not come in the standard MATLAB package.
4.2.1 Computing the Length and Area Bounded by a Curve
The ideas just described were implemented in functions spterp and spcof which are called in the following program curvprop. This program computes the length of a spline curve and the area bounded by the curve. The length of a curve parameter­
ized in complex form as
Furthermore, when the the curve is closed and is traversed in a counterclockwise direction, the area is given by
The curve length is meaningful for an open or closed curve, but the bounded area only makes sense for a closed curve. The next chapter discusses area properties for shapes bounded by several spline curves. Our present example assumes a simple geometry. It is worth mentioning that applying the last integral to an open curve gives the area enclosed within the curve combined with a line from the last point to the origin and a line from the origin to the first point. This fact is clarified in the next chapter which treats general areas bounded by several spline curves.
The following program curvprop passes a spline curve through data in vectors x,y. The length, bounded area, and a set of data points on the curve are computed. The curve is assumed to have a smoothly turning tangent. The default data example uses points on an ellipse with semi-diameters of two and one. Readers can verify that approximating the ellipse with a 21 point spline curve gives an area approxima­
tion accurate within 0.0055 percent and a boundary length accurate within 0.0068 percent. Of course, better accuracy is achievable with more data points.
4.2.2 Example: Length and Enclosed Area for a Spline Curve Function curvprop
z(t) = x(t) + i y(t), a < t < b
can be computed as
b
length
i: f u n c t i o n [ a r e a,l e n g,X,Y,c l o s e d ] = c u r v p r o p ( x,y,d o p l o t )
2
3
4
5
6
7
8
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
35
36
37
38
39
40
41
42
43
44
45
46
%
% [ a r e a,l e n g,X,Y,c l o s e d ] = c u r v p r o p ( x,y,d o p l o t )
%............................................................................................................
% This f u n c t i o n p a s s e s a cubic s p l i n e curve t hrough % a s e t of d a t a v a l u e s and computes t h e e n c l o s e d % a r e a, t h e curve l e n g t h, and a s e t of p o i n t s on % t h e c u r v e.
%
% x,y -
% d o p l o t -
%
% a r e a - %
%
%
%
%
%
%
% l e n g -
% X,Y -
%
%
% c l o s e d - %
%
% For d e f a u l t t e s t d a t a, choose an e l l i p s e wi t h % s e mi - d i a m e t e r s of 2 and 1. i f nargin==0
m=21; t h = l i n s p a c e ( 0,2 * p i,m ); x= 2 * c o s ( t h ); y = s i n ( t h ); x(m)=2; y(m)=0; end
% Use complex d a t a c o o r d i n a t e s z = x (:) + i * y (:); n = l e n g t h ( z ); t = ( 1:n )'; c h o r d = s u m ( a b s ( d i f f ( z ) ) ); d = a b s ( z ( n ) - z ( 1 ) );
% Use a p e r i o d i c s p l i n e i f t h e curve i s c l o s e d i f d < (chord/1e6)
closed=1; z ( n ) = z ( 1 ); endc=5; z p = s p t e r p ( t,z,1,t,e n d c );
% Use t h e n o t - a - k n o t end c o n d i t i o n f o r open curve e l s e
d a t a v e c t o r s d e f i n i n g t h e cur ve. p l o t t h e curve i f a v a l u e i s i n p u t f o r d o p l o t. Ot herwise, no p l o t i s made. t h e e n c l o s e d a r e a i s computed. This par amet er i s v a l i d only i f t h e curve i s c l o s e d and t h e boundary i s t r a v e r s e d i n c o u n t e r c l o c k w i s e. For a cur ve, t h e a r e a agr e e s wi t h a curve c l o s e d u s i n g a l i n e from t h e l a s t p o i n t t o t h e o r i g i n, and a l i n e from t h e o r i g i n t o t h e f i r s t p o i n t. l e n g t h of t h e curve
s e t of p o i n t s on t h e cur ve. The o u t p u t i n t e r s p e r s e s t h r e e p o i n t s on each segment between t h e s t a r t i n g d a t a v a l u e s. e q u a l s one f o r a c l o s e d cur ve. Equals ze ro f o r an open cur ve.
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
closed=0; endc=1; z p = s p t e r p ( t,z,1,t,e n d c ); end
% Compute l e n g t h and a r e a % p l o t ( a b s ( z p ) ),s h g,p a u s e l e n g = s p t e r p ( t,a b s ( z p ),3,n,1 ); a r e a = s p t e r p ( t,1/2 * i m a g ( c o n j ( z ).* z p ),3,n,1 ); Z = s p t e r p ( t,z,0,1:1/4:n,e n d c );
X=r eal (Z); Y=imag(Z); i f nargin>2
p l o t ( X,Y,'-',x,y,'.'), a x i s equal x l a b e l ('x a x i s'), y l a b e l ('y a x i s') t i t l e ('S P L I N E CURVE'), shg end
%============================================
f u n c t i o n [ v,c ] = s p t e r p ( x d,y d,i d,x,e n d v,c )
%
% [ v,c ] = s p t e r p ( x d,y d,i d,x,e n d v,c )
%.............................................................................
%
% This f u n c t i o n performs cubic s p l i n e i n t e r p o - % l a t i o n. Values of y ( x ),y'( x ),y''( x ) or t h e % i n t e g r a l ( y ( t ) * d t, x d ( 1 )..x ) a r e o b t a i n e d.
% Five t y p e s of end c o n d i t i o n s a r e pr o v i d e d.
%
% xd, yd - d a t a v e c t o r s wi t h xd ar r a n g e d i n
% asc endi ng o r d e r.
% i d - i d e q u a l s 0,1,2,3 t o compute y ( x ),
% y'( x ), i n t e g r a l ( y ( t ) * d t,t = x d ( 1 )..x ),
% r e s p e c t i v e l y.
% v - v a l u e s of t h e f u n c t i o n, f i r s t d e r i v a -
% t i v e, second d e r i v a t i v e, or i n t e g r a l
% from xd(1) t o x
% c - t h e c o e f f i c i e n t s d e f i n i n g t h e s p l i n e
% cur ve. I f t h e s e v a l u e s a r e i n p u t from
% an e a r l i e r comput at i on, t h e n t h e y
% a r e not recomputed.
% endv - v e c t o r g i v i n g t h e end c o n d i t i o n s i n
% one of t h e f o l l o w i n g f i v e forms:
% endv=1 or endv o m i t t e d makes
% c(2) and c ( n - 1 ) zero
% e n d v = [ 2,l e f t _ e n d _ s l o p e,...
% r i g h t _ e n d _ s l o p e ] t o impose s l o p e
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
% v a l u e s a t each end
% e n d v = [ 3,l e f t _ e n d _ s l o p e ] imposes t h e
% l e f t end s l o p e v a l u e and makes
% c( n - 1 ) z e ro
% en d v = [ 4,r i g h t _ e n d _ s l o p e ] imposes t h e
% r i g h t end s l o p e v a l u e and makes
% c(2) zero
% endv=5 d e f i n e s a p e r i o d i c s p l i n e by
% making y,y',y" match a t bot h ends
i f nargin<5 | i s emp t y ( en d v ), endv=1; end n = l e n g t h ( x d ); s x = s i z e ( x ); x = x (:); X=x-xd(1);
i f nar gi n< 6, c = s p c o f ( x d,y d,e n d v ); end
C=c(1:n); s1=c(n+1); m1=c(n+2); X=x-xd(1);
i f id==0 % y(x)
v=yd(1)+s1*X+m1/2*X.*X+...
powermat (x,xd,3)*C/6; e l s e i f id==1 % y'( x )
v=s1+m1*X+powermat(x,xd,2)*C/2; e l s e i f id==2 % y''( x )
v=m1+powermat(x,xd,1)*C;
e l s e % i n t e g r a l ( y ( t ) * d t, t = x d ( 1 )..x )
v=yd(1)*X+s1/2*X.*X+m1/6*X.~3+...
powermat(x,xd,4)*C/24;
end
v = r e s h a p e ( v,s x );
%==============================================
f u n c t i o n c = s p c o f ( x,y,e n d v )
%
% c=s p c o f ( x,y,e n d v )
% This f u n c t i o n de t e r mi ne s s p l i n e i n t e r p o l a t i o n % c o e f f i c i e n t s c o n s i s t i n g of t h e s u ppor t % r e a c t i o n s c o n c a t e n a t e d wi t h y' and y'' a t % t h e l e f t end.
% x,y - d a t a v e c t o r s of i n t e r p l a t i o n p o i n t s. % Denote n as t h e l e n g t h of x.
% endv - v e c t o r of d a t a f o r end c o n d i t i o n s % d e s c r i b e d i n f u n c t i o n s p t e r p.
%
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
% c - a v e c t o r [ c ( 1 );...;c ( n + 2 ) ] where t h e % f i r s t n components a r e s u ppor t
% r e a c t i o n s and t h e l a s t two a r e
% v a l u e s of y'( x ( 1 ) ) and y''( x ( 1 ) ).
i f nar gi n< 3, endv=1; end
x = x (:); y = y (:); n = l e n g t h ( x ); u = x ( 2:n ) - x ( 1 ); a=zer os ( n+2,n+2); a ( 1,1:n ) = 1; a ( 2:n,:) = [ p o w e r m a t ( x ( 2:n ),x,3 )/6,u,u.* u/2 ]; b = z e r o s ( n + 2,1 ); b ( 2:n ) = y ( 2:n ) - y ( 1 ); i f endv(1)==1 % Force, f o r c e c o n d i t i o n
a( n+1,2) =1; a( n+2,n- 1) =1; e l s e i f endv(1)==2 % Slope, s l o p e c o n d i t i o n b(n+1) =endv(2); a(n+1,n+1)=1; b(n+2) =endv(3); a ( n + 2,:) =... [ ( ( x ( n ) - x').~ 2 )/2,1,x ( n ) - x ( 1 ) ]; e l s e i f endv(1)==3 % Slope, f o r c e c o n d i t i o n b(n+1) =endv(2); a(n+1,n+1)=1; a( n+2,n- 1) =1; e l s e i f endv(1)==4 % Force, s l o p e c o n d i t i o n a( n+1,2) =1; b(n+2)=endv(2); a ( n + 2,:) = [ ( ( x ( n ) - x').~ 2 )/2,1,x ( n ) - x ( 1 ) ]; e l s e i f endv(1)==5
a ( n + 1,1:n ) = x ( n ) - x'; b(n)=0; a ( n + 2,1:n ) = 1/2 * ( x ( n ) - x').~ 2; a( n + 2,n + 2 ) = x ( n ) - x ( 1 ); e l s e
e r r o r (...
'I n v a l i d v a l u e of endv i n f u n c t i o n s p c o f') end
i f endv(1)==1 & n<4, c=pi nv( a)*b; e l s e, c=a\b; end
%==============================================
f u n c t i o n a=powermat(x,X,p)
%
% a=powermat(x,X,p)
%........................................
% This f u n c t i o n e v a l u a t e s v a r i o u s powers of a % m a t r i x used i n cubic s p l i n e i n t e r p o l a t i o n.
%
% x,X - a r b i t r a r y v e c t o r s of l e n g t h n and N % a - an n by M m a t r i x of el ements such t h a t
% a ( i,j ) = ( x ( i ) > X ( j ) ) * a b s ( x ( i ) - X ( j ) ) ~ p
182: x = x (:); n = l e n g t h ( x ); X = X (:)'; N= l e n g t h ( X);
183: a = x (:,o n e s ( 1,N ) ) - X ( o n e s ( n,1 ),:); a = a.* ( a > 0 );
184: s w i t c h p, c a s e 0, a = s i g n ( a ); c a s e 1, r e t u r n;
185: c a s e 2, a = a.* a; c a s e 3; a = a.* a.* a;
186: c a s e 4, a = a.* a; a = a.* a; o t h e r w i s e, a = a.~ p; end
4.2.3 Generalizing the Intrinsic Spline Function in MATLAB
The intrinsic MATLAB function spline employs an auxiliary function unmk to create the piecewise polynomial definitions defining the spline. The polynomials can be differentiated or integrated, and then functions mkpp and ppval can be used to evaluate results. We have employed the ideas from those routines to develop func­
tions splineg and splincof extending the minimal spline capabilities of MATLAB. The function splincof(xd,yd,endc) computes arrays b and c usable by mkpp and pp- val. The data vector endc defines the first four types of end conditions discussed above. The function splineg(xd,yd,x,deriv,endc,b,c) handles the same kind of data as function spterp. Sometimes arrays b and c may have been created from a previ­
ous call to splineg or spterp. Whenever these are passed through the call list, they are used by splineg without recomputation. Readers wanting more details on spline concepts should consult de Boor’s book [7].
Two examples illustrating spline interpolation are presented next. In the first pro­
gram called, sinetrp, a series of equally spaced points between 0 and 2π is used to approximate y = sin(x) which satisfies
f x
y'(x) = cos(x) , y"(x) = — sin(x) , / y(x)dx = 1 — cos(x).
J 0
The approximations for the function, derivatives, and the integral are evaluated using splineg. Results shown in Figure 4.1 are quite satisfactory, except for points outside the data interval [0, 2π].
function values
2
1.5
1
0.5
0
-0.5
-1
.1.51------------------------ 1--------------------- 1------------------------ 1--------------------- 1-------------------------1----------------------1
- 0.5 0 0.5 1 1.5 2 2.5
x / pi
Figure 4.1: Spline Differentiation and Integration of sin(x)
Spline Differentiation and Integration of sin(x)
+ +"
+
+
+
"+ +
+
+
+
----- y=sin(x)
O data .... y'(x)
— y''(x) . + J y(x) dx
\
\
\
+
+
+
+
+
+
— \...........:■·■·■·
+ \ .··'
+ Λ -Η··' \
of
_/ + r '.+
/
/
/
/
\
+ N .·' + Λ + -'
·- / + / + / +
.· + \
··■ + \
+ \
/...............+ t A
J + '
Φ + ·. / + '·
(,*...............
/
/
/
/
/+ \
.·' + \
·' + \
........+t +j
/ + '
/ + ·.
/ + ■-
...............1
\
\
\
/
/
/
/
\
\
\
\
\
\
\
\
l
/
/
\
\
\
\
\
\
Example: Spline Interpolation Applied to Sin(x)
Program sinetrp
i: f u n c t i o n s i n e t r p 2: % Exampl e: s i n e t r p
3: %...........................................................................
4: % T h i s exampl e i l l u s t r a t e s c u b i c s p l i n e 5: % a p p r o x i m a t i o n of s i n ( x ), i t s f i r s t two 6: % d e r i v a t i v e s, and i t s i n t e g r a l.
7: %
8: % Us e r m f u n c t i o n s r e q u i r e d:
9: % s p l i n e g, s p l i n c o f
i 0:
i i: % C r e a t e d a t a p o i n t s on t h e s p l i n e c u r v e i 2: x d = l i n s p a c e ( 0,2 * p i,2 1 ); y d = s i n ( x d );
i 3:
i 4: % E v a l u a t e f u n c t i o n v a l u e s a t a d e n s e
i 5: % s e t o f p o i n t s
i 6: x = l i n s p a c e ( - p i/2,5/2 * p i,6 1 );
17: [ y,b,c ] = s p l i n e g ( x d,y d,x,0 ); i 8: y p = s p l i n e g ( x d,y d,x,1,[ ],b,c ); i 9: y p p = s p l i n e g ( x d,y d,x,2,[ ],b,c );
2 0: y i n t = s p l i n e g ( x d,y d,x,3,[ ],b,c ) ;
2 i:
2 2: % P l o t r e s u l t s 23: z = x/p i; z d = x d/p i;
2 4: p l o t ( z,y,'k -',z d,y d,'k o',z,y p, 'k:' ,...
2 5: z,y p p,'k -.',z,y i n t,'k +');
2 6: t i t l e ( ['S p l i n e D i f f e r e n t i a t i o n and ', ...
2 7: 'I n t e g r a t i o n o f s i n ( x )'] );
2 8: x l a b e l ('x / p i'); y l a b e l ('f u n c t i o n v a l u e s');
2 9: l e g e n d ('y = s i n ( x )','d a t a','y''( x )', 'y'' ''( x )', ...
3 0: '\i n t y ( x ) d x',1 ); g r i d on
3 i: f i g u r e ( g c f ); p a u s e;
3 2: % p r i n t - d e p s s i n e t r p
33:
3 4: % ========================= = === === ===== === === ===
35:
3 6: f u n c t i o n [ v a l,b,c ] = s p l i n e g ( x d,y d,x,d e r i v,e n d c,b,c )
3 7: %
3 8: % [ v a l,b,c ] = s p l i n e g ( x d,y d,x,d e r i v,e n d c,b,c )
3 9: %
4 0: %
4 i
42
43:
44
45
46
47:
48
49
50:
5 i
52
53:
54:
55:
56
57:
58
59:
60:
6 i:
62
63:
64:
65:
66
67:
68
69:
70:
7 i
72
73:
74
75
76
77:
78
79
80:
8 i
82
83:
84:
85:
For a cubic s p l i n e curve t hr ough d a t a p o i n t s x d,yd, t h i s f u n c t i o n e v a l u a t e s y ( x ), y'( x ), y''( x ), or i n t e g r a l ( y ( x ) * d x, xd(1) t o x ( j ) ) f o r j = 1:l e n g t h ( x ).T h e c o e f f i c i e n t s needed t o e v a l u a t e t h e s p l i n e a r e a l s o computed.
xd,yd - d a t a v e c t o r s d e f i n i n g t h e cubic s p l i n e curve x - v e c t o r of p o i n t s where curve
p r o p e r t i e s a r e computed. d e r i v - d e n o t i n g t h e s p l i n e curve as y ( x ), der iv=0 g i v e s a v e c t o r f o r y(x)
deriv=1 g i v e s a v e c t o r f o r y'( x )
der iv=2 g i v e s a v e c t o r f o r y''( x )
der iv=3 g i v e s a v e c t o r of v a l u e s
f o r i n t e g r a l ( y ( z ) * d z ) from xd(1) t o x ( j ) f o r j = 1:l e n g t h ( x ) endc - endc=1 makes y'''( x ) cont i nuous a t
xd(2) and x d ( e n d - 1 ). e n d c = [ 2,l e f t _ s l o p e,r i g h t _ s l o p e ] imposes s l o p e v a l u e s a t bo t h ends. e n d c = [ 3,l e f t _ s l o p e ] imposes t h e l e f t end s l o p e and makes t h e d i s c o n t i n u i t y of y''' a t xd(end-1) s m a l l. e n d c = [ 4,r i g h t _ s l o p e ] imposes t h e r i g h t end s l o p e and makes t h e d i s c o n t i n u i t y of y''' a t xd(2) s ma l l. b,c c o e f f i c i e n t s needed t o per form t h e
s p l i n e i n t e r p o l a t i o n. I f t h e s e a r e not g i v e n, f u n c t i o n unmkpp i s c a l l e d t o g e n e r a t e them. v a l v a l u e s y ( x ),y'( x ),y''( x ) or
i n t e g r a l ( y ( z ) d z, z = x d ( 1 )..x ) f o r d e r i v = 0,1,2, or 3, r e s p e c t i v e l y.
i f nargin<5 | i s e m p t y ( e n d c ), endc=1; end i f nar gi n< 7, [ b,c ] = s p l i n c o f ( x d,y d,e n d c ); end n = l e n g t h ( x d ); [N,M]=size(c);
s w i t c h d e r i v
case 0 % F u n c t i o n v al u e v a l = p p v a l ( m k p p ( b,c ),x );
case 1 % F i r s t d e r i v a t i v e
86
87:
88
89:
90:
9 i
92
93
94:
95:
96
97:
98
99:
i 0 0:
i 0 i:
i 0 2
i 0 3:
i 0 4:
i 0 5:
i 0 6
i 0 7:
i 0 8
i 0 9:
i i 0:
i i i:
i i 2:
i i 3:
i i 4:
i i 5:
i i 6:
i i 7:
i i 8:
i i 9:
i 2 0:
i 2 i:
i 2 2:
i 2 3:
i 2 4:
i 2 5:
i 2 6:
i 2 7:
i 2 8:
i 2 9:
i 3 0:
C = [ 3 * c (:,1 ),2 * c (:,2 ),c (:,3 ) ];
va l =p p v a l ( mk p p ( b,C ),x );
case 2 % Second d e r i v a t i v e C = [ 6 * c (:,1 ),2 * c (:,2 ) ]; v a l =p p v a l ( mk p p ( b,C ),x );
case 3 % I n t e g r a l v a l u e s from xd(1) t o x k=M:-1:1;
C = [ c./k ( o n e s ( N,1 ),:),z e r o s ( N,1 ) ] ; d x = x d ( 2:n ) - x d ( 1:n - 1 ); s = z e r o s ( n - 2,1 ); f o r j = 1:n - 2, s ( j ) = p o l y v a l ( C ( j,:),d x ( j ) ); end C (:,5 ) = [ 0;c u m s u m ( s ) ]; val =pp v a l ( mk p p ( b,C ),x );
end
%==============================================
f u n c t i o n [ b,c ] = s p l i n c o f ( x d,y d,e n d c )
%
% [ b,c ] = s p l i n c o f ( x d,y d,e n d c )
%..................................................................
% This f u n c t i o n de t e r mi ne s c o e f f i c i e n t s f o r % cubic s p l i n e i n t e r p o l a t i o n a l l o w i n g f o u r % d i f f e r e n t t y p e s of end c o n d i t i o n s.
% xd,yd - d a t a v e c t o r s f o r t h e i n t e r p o l a t i o n
% endc - endc=1 makes y'''( x ) cont i nuous a t % xd(2) and x d ( e n d - 1 ).
% e n d c = [ 2,l e f t _ s l o p e,r i g h t _ s l o p e ]
% imposes s l o p e v a l u e s a t b o t h ends.
% e n d c = [ 3,l e f t _ s l o p e ] imposes t h e l e f t
% end s l o p e and makes t h e d i s c o n t i n u i t y
% of y''' a t xd(end-1) s m a l l.
% e n d c = [ 4,r i g h t _ s l o p e ] imposes t h e r i g h t
% end s l o p e and makes t h e d i s c o n t i n u i t y
% of y''' a t xd(2) s ma l l.
%
i f nar gi n< 3, endc=1; end; t y p e=e n d c( 1 ); x d = x d (:); y d = y d (:);
s w i t c h t ype
case 1
% y'''( x ) cont i nuous a t t h e xd(2) and xd(end-1) [ b,c ] = u n m k p p ( s p l i n e ( x d,y d ) );
i 3 i:
i 3 2: c a s e 2
i 3 3: % S l o p e g i v e n a t b o t h ends
i 3 4: [ b,c ] = u n m k p p ( s p l i n e ( x d,[ e n d c ( 2 );y d;e n d c ( 3 ) ] ) );
i 3 5:
i 3 6: c a s e 3
i 3 7: % S l o p e a t l e f t end g i v e n. Compute r i g h t end
i 3 8: % s l o p e.
i 3 9: [ b,c ] = u n m k p p ( s p l i n e ( x d,y d ) );
i 4 0: c = [ 3 * c (:,1 ),2 * c (:,2 ),c (:,3 ) ];
i 4 i: s r i g h t = p p v a l ( m k p p ( b,c ),x d ( e n d ) );
i 4 2: [ b,c ] = u n m k p p ( s p l i n e ( x d,[ e n d c ( 2 );y d;s r i g h t ] ) );
i 4 3:
i 4 4: c a s e 4
i 4 5: % S l o p e a t r i g h t end known. Compute l e f t end
i 4 6: % s l o p e.
i 4 7: [ b,c ] = u n m k p p ( s p l i n e ( x d,y d ) );
i 4 8: c = [ 3 * c (:,1 ),2 * c (:,2 ),c (:,3 ) ];
i 4 9: s l e f t = p p v a l ( m k p p ( b,c ),x d ( 1 ) ) ;
i 5 0: [ b,c ] = u n m k p p ( s p l i n e ( x d,[ s l e f t;y d;e n d c ( 2 ) ] ) );
i 5 i:
i 5 2: end
4.2.4 Example: A Spline Curve with Several Parts and Corners
The final spline example illustrates interpolation of a two-dimensional curve where y cannot be expressed as a single valued function of x. Then we introduce a param­
eter tj having its value equal to the index j for each (xj,y j ) used. Interpolating x(t) and y(t) as continuous functions of t produces a smooth curve through the data. Function matlbdat creates data points to define the curve and calls function spcry2d to compute points on a general plane curve. We also introduce the idea of ‘corner points’ where slope discontinuity allows the curve to make sharp turns needed to describe letters such as the ‘t’ in MATLAB. Each curve segment between successive pairs of corner points is parameterized using function spline. Results in Figure 4.2
show clearly that spline interpolation can represent a complicated curve. The re­
lated code appears after the figure. The same kind of parameterization used for two dimensions also works well for three dimensional curves.
Example: Spline Curve Drawing the Word MATLAB Program matlbdat
i: f u n c t i o n m a t l b d a t
A Spline Curve Drawing the Word MATLAB
2
3
4
5
6
7
8
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
35
36
37
38
39
40
41
42
43
44
45
46
% Example: m at l bda t %
...........................................
% This example i l l u s t r a t e s t h e use of s p l i n e s % t o draw t h e word MATLAB.
%
% User m
f u n c t i o n s
r e q u i r e d: spcurv2d
x=[13
17
17
16
17
19
21
22
21
21
23
26
25
28
30
32
37
32
30
32
35
37
37
38
41
42
42
42
45
39
42
42
44
47
48
48
47
47
48
51
53
57
53
52
53
56
57
57
58
61
63
62
61
64
66
64
61
64
67
67]
y=[63
64
58
52
57
62
62
58
51
58
63
63
53
52
56
61
61
61
56
51
55
61
55
52
54
59
63
59
59
59
59
54
52
54
58
62
58
53
51
55
60
61
60
54
51
55
61
55
52
53
58
62
53
57
53
51
53
51
51
51]
x = x';
x=x(:)
>; y=y'
; y=y
(:);
ncr nr = [ 17 22 26 27 28 29 30 31 36 42 47 52]; c l f; [ x s,y s ] = c u r v 2 d ( x,y,1 0,n c r n r ); p l o t ( x s,y s,'k -',x,y,'k *'), a x i s o f f; t i t l e ('A S p l i n e Curve Drawing t h e Word MATLAB'); f i g u r e ( g c f );
% p r i n t -deps mat l b d a t
%=============================================
f u n c t i o n [ X,Y ] = s p c r v 2 d ( x d,y d,n s e g,i c r n r )
%
% [ X,Y ] = s p c r v 2 d ( x d,y d,n s e g,i c r n r )
%........................................................................
% This f u n c t i o n computes p o i n t s (X,Y) on a % s p l i n e curve t hr ough (xd,yd) al l o wi n g s l o p e % d i s c o n t i n u i t i e s a t p o i n t s wi t h cor ner % i n d i c e s i n i c r n r. nseg p l o t segments a r e % used between each s u c c e s s i v e p a i r of p o i n t s.
i f nar gi n< 4, i c r n r = [ ]; end i f nar gi n< 3, nseg=10; end z d = x d (:) + i * y d (:); n = l e n g t h ( z d ); N = [ 1;s o r t ( i c r n r (:) );n ]; Z=zd(1); i f N(1)==N(2); N(1) = [ ]; end i f N(end)==N(end-1); N(end) = [ ]; end f o r k=1:l e n g t h ( N) - 1
zk=zd(N(k):N(k+1)); s k = l e n g t h ( z k ) - 1;
47: s = l i n s p a c e ( 0,s k,1 + s k * n s e g )';
48: Z k = s p l i n e ( 0:s k,z k,s ); Z=[Z;Zk( 2:end)];
49: end
50: X=r eal (Z); Y=imag(Z);
4.3 Numerical Differentiation Using Finite Differences
Differential equation problems are sometimes solved using difference formulas to approximate the derivatives in terms of function values at adjacent points. Deriving difference formulas by hand can be tedious, particularly when unequal point spacing is used. For this reason, we develop a numerical procedure to construct formulas of arbitrary order and arbitrary truncation error. Of course, as the desired order of derivative and the order of truncation error increases, more points are needed to interpolate the derivative. We will show below that approximating a derivative of order k with a truncation error of order hm generally requires (k + m) points unless symmetric central differences are used. Consider the Taylor series expansion
^ F (k) (x )
Fi x + ah) = V ~ ^ ( a h ) k
k!
k=0
where F (k)(x) means the k’th derivative of F(x). This relation expresses values of F as linear combinations of the function derivatives at x. Conversely, the derivative values can be cast in terms of function values by solving a system of simultaneous equations. Let us take a series of points defined by
xt = x + ha.t , 1 < i < n
where h is a fixed step-size and a % are arbitrary parameters. Separating some leading terms in the series expansion gives
1
ρ {χχ) = Σ XT hkF {k\x )
k=0
v”+1
a':
H r
n!
hnF (n)(x)
+
(n + 1)!
h(n+ 1 )F ( ^ ( x ) ] + O(hn+2) , 1 < i < n.
It i s hel pf ul t o us e t he f ol l owi ng not at i on:
f
f p
A
a col umn vect or wi t h component i being equal to a k a column vector with component i being F( x t ) a column vector with component i being h l F (l)(x)
[ α0,α 1 ,...,a n- 1], a square matrix with columns which are powers of a.
k
k
a —
Then the Taylor series expressed in matrix form is
f = A.f P+ ^ Fi y « - + + o (/jn+2)
n! ( n + 1)!
Solving this system for the derivative matrix f p yields
= a -/ _ h"F"y A- ^ - +oi h
n! ( n + 1)!
I n t he l ast equat i on we have r et ai ned t he fi rst t wo r emai nder t er ms i n expl i ci t f or m t o al l ow t he magni t udes of t hese t er ms t o be exami ned. Row k + 1 of the previous equation implies
hn-k
F™(x) = h -\A - lf ) k + 1 ------- - F ^ ( x ) ( A - 1an)k+1-
(x )
hn-k + 1
(n + 1)!
F(n+1)(x)(A- 1 an + 1 )k+ 1 + O(hn - k + 1 ) .
Consequent l y, t he r ows of A - 1 provide coefficients in formulas to interpolate deriva­
tives. For a particular number of interpolation points, say N, the highest derivative approximated will be F (N-1)(x) and the truncation error will normally be of or­
der h1. Conversely, if we need to compute a derivative formula of order k with the truncation error being m, then it is necessary to use a number of points such that n — k = m; therefore n = m + k. For the case where interpolation points are sym­
metrically placed around the point where derivatives are desired, one higher power of accuracy order is achieved than might be expected. We can show, for example, that
= - ί (F( x - 2h) - AF(x - h ) + 6F(x) -
dx ft
4 F (x + h) + F (x + 2h)) + O(h2)
because the truncation error term associated with h 1 is found to be zero. At the same time, we can show that a forward difference formula for f (x) employing equidistant point spacing is
d3 F(x ) 1
— V = — ( - 2.5F(x) - 9F( x + h) + 1 2 F( x + 2 h) +
dx 3 h3
7F (x + 3h) — 1.5F (x + 4h)) + O(h2).
Although the last two formulas contain arithmetically simple interpolation coeffi­
cients, due to equal point spacing, the method is certainly not restricted to equal spacing. The following program contains the function derivtrp which implements the ideas just developed. Since the program contains documentation that is output when it is executed, no additional example problem is included.
4.3.1 Example: Program to Derive Difference Formulas Output from Example
f i n i t d i f;
COMPUTING F ( x,k ), THE K'TH DERIVATIVE OF f ( x ), BY FINITE DIFFERENCE APPROXIMATION
I n p u t t h e d e r i v a t i v e o r d e r ( g i v e 0 t o s t o p, o r ? f o r an e x p l a n a t i o n ) > ?
Le t f ( x ) have i t s k't h d e r i v a t i v e d e n o t e d by F ( k,x ). The f i n i t e d i f f e r e n c e f o r mu l a f o r a s t e p s i z e h i s g i v e n by:
F ( x,k ) = S u m ( c ( j ) * f ( x + a ( j ) * h ), j = 1:n )/h ~ k +... T r u n c a t i o n E r r o r
w i t h m=n-k b e i n g t h e o r d e r o f t r u n c a t i o n e r r o r whi ch d e c r e a s e s l i k e h"m a c c o r d i n g t o:
T r u n c a t i o n E r r o r = - ( h ~ m ) * ( e ( 1 ) * F ( x,n ) +...
e ( 2 ) * F ( x,n + 1 ) * h + e ( 3 ) * F ( x,n + 2 ) * h ~ 2 + O( h ~ 3 ) )
I n p u t t h e d e r i v a t i v e o r d e r ( g i v e 0 t o s t o p, o r ? f o r an e x p l a n a t i o n ) > 4
Gi ve t h e r e q u i r e d t r u n c a t i o n o r d e r > 1
To d e f i n e i n t e r p o l a t i o n p o i n t s X ( j ) = x + h * a ( j ), i n p u t a t l e a s t 5 component s f o r v e c t o r a.
Components of a > - 2,- 1,0,1,2
The f o r mu l a f o r a d e r i v a t i v e of o r d e r 4 i s: F ( x,k ) = s u m.( c ( j ) * F ( X ( j ),j = 1:n )/h ~ 4 + o r d e r ( h ~ 1 ) wher e c i s g i v e n by:
1.0000 - 4.0 0 0 0 6.0000 - 4.0 0 0 0 1.0000
and t h e t r u n c a t i o n e r r o r c o e f f i c i e n t s a r e:
- 0.0 0 0 0 0.1667 - 0.0 0 0 0 0.0125
I n p u t t h e d e r i v a t i v e o r d e r ( g i v e 0 t o s t o p,
o r ? f o r a n e x p l a n a t i o n ) > 3
Give the r e q u i r e d t r u n c a t i o n o r de r > 2
To d e f i n e i n t e r p o l a t i o n p o i n t s X(j ) =x+h*a(j ), i n p u t a t l e a s t 5 components f o r v e c t o r a.
Components of a > 0,1,2,3,4
The formula f o r a d e r i v a t i v e of o r d e r 3 i s: F ( x,k) =s um.( c ( j ) *F( X( j ),j =1:n)/h~3 + order(h~2) where c i s given by:
-2.5000 9.0000 -12.0000 7.0000 -1.5000
and t he t r u n c a t i o n e r r o r c o e f f i c i e n t s a r e:
-1.7500 -2.5000 -2.1417 -1.3750
Input the d e r i v a t i v e o r de r (give 0 t o s t op, or ? f o r an expl ana t i on) > 0
Program finitdif
i: f u n c t i o n [ c,e,m,c r a t,k,a ] = f i n i t d i f ( k,a )
2: %
3: % [ c,e,m,c r a t,k,a ] = f i n i t d i f ( k,a )
4: %..................................................................................................................................
5: % T h i s p r o g r a m comput es f i n i t e d i f f e r e n c e f o r m u l a s of 6: % g e n e r a l o r d e r. For e x p l a n a t i o n of t h e i n p u t and 7: % o u t p u t p a r a m e t e r s, s e e t h e f o l l o w i n g f u n c t i o n 8: % f i n d i f c o. When t h e p r o g r a m i s e x e c u t e d w i t h o u t i n p u t 9: % a r g u m e n t s, t h e n i n p u t i s r e a d i n t e r a c t i v e l y.
10:
i i: i f n a r g i n = = 0, d i s p (' ') % Use i n t e r a c t i v e i n p u t i 2: disp('COMPUTING F ( x,k ), THE K''TH DERIVATIVE OF')
i 3: d i s p ('f ( x ), BY FINITE DIFFERENCE APPROXIMATION')
14: d i s p (' ')
i 5: w h i l e 1
i 6: d i s p ('I n p u t t h e d e r i v a t i v e o r d e r ( g i v e 0 t o s t o p,')
i 7: K = i n p u t ('o r ? f o r an e x p l a n a t i o n ) > ','s');
i 8: k = s t r 2 n u m( K);
i 9: i f s t r c m p ( K,'') | s t r c m p ( K,'0'); d i s p (' '),r e t u r n
20:
2 i:
22
23:
24
25
26
27:
28
29
30:
3 i
32
33
34
35
36
37
38
39
40:
4 i
42
43
44
45
46
47
48
49
50:
5 i:
52
53:
54
55
56
57:
58
59
60:
6 i:
62
63:
64
e l s e i f s t r c m p ( K,'?') d i s p (' '), d i s p (...
'L e t f ( x ) have i t s k''t h d e r i v a t i v e denot ed b y') d i s p (...
'F ( k,x ). The f i n i t e d i f f e r e n c e for mul a f o r a') d i s p ('s t e p s i z e h i s gi ven b y:'), d i s p (' ') d i s p (...
'F ( x,k ) = S u m ( c ( j ) * f ( x + a ( j ) * h ), j = 1:n )/h ~ k +...') d i s p (' T r u n c a t i o n E r r o r'), d i s p (' ')
d i s p ('w i t h m=n-k b ei n g t h e o r d e r of t r u n c a t i o n') d i s p (...
'e r r o r which d e c r e a s e s l i k e h~m a c c o r d i n g t o:') d i s p (' ')
d i s p ('T r u n c a t i o n E r r o r = - ( h ~ m ) * ( e ( 1 ) * F ( x,n ) +...') d i s p (...
'e ( 2 ) * F ( x,n + 1 ) * h + e ( 3 ) * F ( x,n + 2 ) * h ~ 2 + O( h ~ 3 ) )') d i s p (' ') e l s e
d i s p (' ')
m=i nput ('Gi ve t h e r e q u i r e d t r u n c a t i o n o r d e r > '); n=m+k; N=num2str(n); d i s p (' '), d i s p (...
'To d e f i n e i n t e r p o l a t i o n p o i n t s X ( j ) = x + h * a ( j ),') d i s p ( ['i n p u t a t l e a s t ',N,...
' components f o r v e c t o r a.'] ) d i s p (' '), aa =input('Components of a > ','s'); a = e v a l ( ['[',a a,']'] ); n = l e n g t h ( a ); m=n-k; [ c,e,m,c r a t ] = f i n d i f c o ( k,a ); d i s p (' '), d i s p (... ['The for mul a f o r a d e r i v a t i v e of o r d e r ',...
K,' i s:'] )
d i s p ( ['F ( x,k ) = s u m ( c ( j ) * F ( X ( j ),j = 1:n )/h ~',K,...
'+ o r d e r ( h ~',n u m 2 s t r ( m ),')'] ) d i s p ('w h e r e c i s gi ven b y:') d i s p (' '), d i s p ( c ), d i s p (' ') d i s p (...
'a n d t h e t r u n c a t i o n e r r o r c o e f f i c i e n t s a r e:') d i s p (' '), d i s p ( e ) end end e l s e
[ c,e,m,c r a t ] = f i n d i f c o ( k,a );
end
%==================================================
f u n c t i o n [ c,e,m,c r a t ] = f i n d i f c o ( k,a )
65
66
67
68
69
70
7 i
72
73
74
75
76
77
78
79
80
8 i
82
83
84
85
86
87
88
89
90
9 i
92
93
94
95
96
97
98
99
i 0 0
%
% [ c,e,m,c r a t ] = f i n d i f c o ( k,a )
%................................................................
% This f u n c t i o n approximates t h e k't h d e r i v a t i v e % of a f u n c t i o n u s i n g f u n c t i o n v a l u e s a t n % i n t e r p o l a t i o n p o i n t s. Let f ( x ) be a g e n e r a l % f u n c t i o n havi ng i t s k't h d e r i v a t i v e denoted % by F ( x,k ). The f i n i t e d i f f e r e n c e appr oxima ti on % f o r t h e k't h d e r i v a t i v e employing a s t e p s i z e h % i s gi ven by:
% F ( x,k ) = S u m ( c ( j ) * f ( x + a ( j ) * h ), j = 1:n )/h ~ k +
% T r u n c a t i o n E r r o r
% wi t h m=n-k b e i ng t h e o r d e r of t r u n c a t i o n % e r r o r which d e c r e a s e s l i k e h~m and % T r u n c a t i o n E r r o r = ( h ~ m ) * ( e ( 1 ) * F ( x,n ) +...
% e(2)*F(x,n+1)*h+e(3)*F(x,n+2)*h~2+O(h~3))
%
% a - a v e c t o r of l e n g t h n d e f i n i n g t h e
% i n t e r p o l a t i o n p o i n t s x + a ( j ) * h where
% x i s an a r b i t r a r y par amet er p o i n t
% k - o r d e r of d e r i v a t i v e e v a l u a t e d a t x
% c - t h e we i g h t i n g c o e f f i e n t s i n t h e
% d i f f e r e n c e for mul a above. c ( j ) i s
% t h e m u l t i p l i e r f o r v a l u e f ( x + a ( j ) * h )
% e - e r r o r component v e c t o r i n t h e above
% d i f f e r e n c e formula
% m - o r d e r of t r u n c a t i o n o r d e r i n t h e
% for mul a. The r e l a t i o n m=n-k a p p l i e s.
% c r a t - a m a t r i x of i n t e g e r s such t h a t c i s
% approximated by c r a t ( 1,:)./c r a t ( 2,:)
a = a (:); n = l e n g t h ( a ); m=n-k; mat =ones(n,n+4); f o r j =2:n+4; m a t (:,j ) = a/( j - 1 ).* m a t (:,j - 1 ); end A = p i n v ( m a t (:,1:n ) ); ec=-A*mat (:,n+1:n+4); c=A(k+1,:); e = - e c ( k + 1,:);
[ c t o p,c b o t ] = r a t ( c,1 e - 8 ); c r a t = [ c t o p (:)';c b o t (:)'];
Chapiter 5
Gauss Integration with Geometric Property Applications
5.1 Fundamental Concepts and Intrinsic Integration Tools in MATLAB
Numerical integration methods approximate a definite integral by evaluating the integrand at several points and taking a weighted combination of those integrand values. The weight factors can be obtained by interpolating the integrand at selected points and integrating the interpolating function exactly. For example, the Newton- Cotes formulas result from polynomial interpolation through equidistant base points. This chapter discusses concepts of numerical integration needed in applications.
Let us assume that an integral over limits a to b is to be evaluated. We can write
~ b n
/ f (x)dx = Σ Wi f (Xi ) +E
■’ a i= 1
where E represents the error due to replacement of the integral by a finite sum. This is called an n-point quadrature formula. The points x i where the integrand is evalu­
ated are the base points and the constants Wi are the weight factors. Most integration formulas depend on approximating the integrand by a polynomial. Consequently, they give exact results when the integrand is a polynomial of sufficiently low order. Different choices of xi
and Wi
will be discussed below.
It is helpful to express an integral over general limits in terms of some fixed limits, say — 1 to 1. This is accomplished by introducing a linear change of variables
x = a + fit.
Requi r i ng t hat x = a corresponds to t = — 1 and that x = b corresponds to t = 1 gives a = (a + b)/2 and f = (b — a)/2, so that one obtains
J f { x ) d x = ^(5 - a ) J f
a + b b — a ~ + ~ f
dt
F ( t ) dt
w h e r e F(t) = f [(a + b)/2 + (b — a)t/2](b — a)/2. Thus, the dependence of the integral on the integration limits can be represented parametrically by modifying the
1
1
integrand. Consequently, if an integration formula is known for limits —1 to 1, we can write
/
b n
f (x)dx = f ^ ^ Wi f (a + f xi ) + E.
i= 1
The idea of shifting integration limits can be exploited further by dividing the interval a to b into several parts and using the same numerical integration formula to evaluate the contribution from each interval. Employing m intervals of length i = (b — a)/m, we get
,· b m . a+j£
/ f (x)dx = ^ ^ f (x)dx.
Ja 3 = 1 a+(3—1)^
Each of t he i nt egr al s i n t he summat i on can be t r ans f or med t o have l i mi t s — 1 t o 1 by t aki ng
x = a3 + f t
wi t h
a3 = a +( j — 1/2 )i and f = i/2.
Ther ef or e we obt ai n t he i dent i t y
f b m i f 1
f (x)dx = ^ 2 - f ( a 3 + fjt)dt. J a 3 = 1 2 J — 1
Applying the same n-point quadrature formula in each of m equal intervals gives what is termed a composite formula
C b i m n
f ( x ) d x = w t f ( aj + βχ%) + E ·
a 2 3=1 i=1
By i nt er changi ng t he s ummat i on or der i n t he pr evi ous equat i on we get
rb o n m
ob p n m
f (x)dx = - Y Σ f ( a 3 + βχι) + E *
^a i= 1 3 =1
Let us now turn to certain choices of weight factors and base points. Two of the most widely used methods approximate the integrand as either piecewise linear or piece­
wise cubic. Approximating the integrand by a straight line through the integrand end points gives the following formula
f f (x)dx = f ( —1) + f (1) + E.
A much mor e accur at e f or mul a r esul t s by us i ng a cubi c appr oxi mat i on mat chi ng t he i nt egr and at x = —1,0,1. Let us write
f (x) = C 1 + c2x + C3 x2 + c^x3.
Then
r 1 2
J f ( x) dx = 2ci + - c 3.
Evidently the linear and cubic terms do not influence the integral value. Also, c 1 = f (0) and f ( - 1) + f (1) = 2 c1 + 2 c3 so that
I'1 1
J f (x)dx = - [/( - l ) + 4/(0) + /( l ) ] + E.
The er r or E in this formula is zero when the integrand is any polynomial of order 3 or lower. Expressed in terms of more general limits, this result is
f b
/ f ( x) dx =
J a
( 6 — a) 6
f (a)+4f (
f (b)
+E
which is known as Simpson’s rule.
Analyzing the integration error for a particular choice of integrand and quadrature formula can be complex. In practice, the usual procedure taken is to apply a com­
posite formula with m chosen large enough so the integration error is expected to be negligibly small. The value for m is then increased until no further significant change in the integral approximation results. Although this procedure involves some risk of error, adequate results can be obtained in most practical situations.
In the subsequent discussions the integration error that results by replacing an integral by a weighted sum of integrand values will be neglected. It must nevertheless be kept in mind that this error depends on the base points, weight factors, and the particular integrand. Most importantly, the error typically decreases as the number of function values is increased.
It is convenient to summarize the composite formulas obtained by employing a piecewise linear or piecewise cubic integrand approximation. Using m intervals and letting i = (b — a)/m,i t is easy to obtain the composite trapezoidal formula which is
f f (x)dx = i
a
f ( a ) + m
2
+
m— 1
Σ
3=1
f (a + ji)
This formula assumes that the integrand is satisfactorily approximated by piecewise linear functions. The MATLAB function t r apz implements the trapezoidal rule. A similar but much more accurate result is obtained for the composite integration formula based on cubic approximation. For this case, taking m intervals implies 2m + 1 function evaluations. If we let g = (b — a)/(2m) and h = 2g, then
f 3 = f (x3 ) where x3 = a + gj , j = 0,1, 2,..., 2m,
with f (xo) = f (a) and f (x2 ^ h
f (b). Combining results for all intervals gives
b h j f(x)dx = -
m— 1
f (a) + 4f 1 + f (b)+ 5 3 (4f2i+1 + 2 f 2i )
i = 1
m
This formula, known as the composite Simpson rule, is one of the most commonly used numerical integration methods. The following function simpson works for an analytically defined function or a function defined by spline interpolating through discrete data.
Function for Composite Simpson Rule
1: f u n c t i o n a r e a = s i m p s o n ( f u n c n a m e,a,b,n,v a r a r g i n )
2: %
3: % a r e a = s i m p s o n ( f u n c n a m e,a,b,n,v a r a r g i n )
4: % -----------------------------------------------------------------------------------------------------------------------------
5: % S i m p s o n's r u l e i n t e g r a t i o n f o r a g e n e r a l f u n c t i o n 6: % d e f i n e d a n a l y t i c a l l y o r by a d a t a a r r a y
7: %
8: % f uncname - e i t h e r t h e name of a f u n c t i o n v a l i d 9: % f o r a v e c t o r a r gume nt x, o r an a r r a y
1 0: % h a v i n g two col umns w i t h x d a t a i n t h e
1 1: % f i r s t col umn and y d a t a i n t h e s e c o n d
1 2: % col umn. I f a r r a y d a t a i s g i v e n, t h e n
13: % t h e f u n c t i o n i s d e t e r m i n e d by p i e c e w i s e
14: % c u b i c s p l i n e i n t e r p o l a t i o n.
15: % a,b - l i m i t s of i n t e g r a t i o n
1 6: % n - odd number o f f u n c t i o n e v a l u a t i o n s. I f
17: % n i s g i v e n a s e v e n, t h e n t h e n e x t
1 8: % h i g h e r odd i n t e g e r i s u s e d.
19: % v a r a r g i n - v a r i a b l e number of a r g u me n t s p a s s e d 2 0: % f o r u s e i n f uncname
2 1: % a r e a - v a l u e o f t h e i n t e g r a l when t h e i n t e g r a n d
2 2: % i s a p p r o x i m a t e d a s a p i e c e w i s e c u b i c
2 3: % f u n c t i o n
2 4: %
2 5: % Us e r f u n c t i o n s c a l l e d: f u n c t i o n f uncname i n t h e 2 6: % ar g u me n t l i s t
2 7: %----------------------------------------------------------------------------------------------------
28: i f 2 * f i x ( n/2 ) = = n; n=n+1; e nd; n = ma x ( n,3 ); 29: x = l i n s p a c e ( a,b,n );
30: i f i s s t r ( f u n c n a m e )
31: y = f e v a l ( f u n c n a m e,x,v a r a r g i n {:} );
32: e l s e
33: y = s p l i n e ( f u n c n a m e (:,1 ),f u n c n a m e ( :,2 ),x );
34: end
35: a r e a = ( b - a )/( n - 1 )/3 * ( y ( 1 ) - y ( n ) + ...
4 * s u m ( y ( 2:2:n ) ) + 2 * s u m ( y ( 3:2:n ) ) );
An important goal in numerical integration is to achieve accurate results with only a few function evaluations. It was shown for Simpson’s rule that three function evaluations are enough to exactly integrate a cubic polynomial. By choosing the base point locations properly, a much higher accuracy can be achieved for a given number of function evaluations than would be obtained by using evenly spaced base points. Results from orthogonal function theory lead to the following conclusions. If the base points are located at the zeros of the Legendre polynomials (all these zeros are between — 1 and 1) and the weight factors are computed as certain functions of the base points, then the formula
is exact for a polynomial integrand of degree 2n — 1. Although the theory proving this property is not elementary, the final results are quite simple. The base points and weight factors for a particular order can be computed once and used repeatedly. Formulas that use the Legendre polynomial roots as base points are called Gauss quadrature formulas. In a typical application, Gauss integration gives much more accurate results than Simpson’s rule for an equivalent number of function evalua­
tions. Since it is equally easy to use, the Gauss formula is preferable to Simpson’s rule.
MATLAB also has three functions quad and quad8 and quadl to numerically integrate by adaptive methods. These functions repeatedly modify approximations for an integral until the estimated error becomes smaller than a specified tolerance. In the current text, the function quadl is preferable over the other two functions, and quadl is always used when an adaptive quadrature function is needed. Readers should study carefully the system documentation for quadl to understand the various combinations of call list parameters allowed.
5.2 Concepts of Gauss Integration
This section summarizes properties of Gauss integration which, for the same num­
ber of function evaluations, are typically much more accurate than comparable Newton- Cotes formulas. It can be shown for Gauss integration [20] that
Integration Order n
Figure 5.1: Error Coefficient versus Number of Points for Gauss Integration
where the integration error term is
~>2 n - 1/^|\4
— 2-------( n!)-------- (2 n ) _ 1 < ^ < 1
(2n + l)[(2n)!]3 ^ ’ ζ
The base points in the Gauss formula of order n are the roots of the Legendre poly­
nomial of order n and the weight factors are expressible concisely in terms of the base points. The quadrature error term for an n-point formula involves the integrand derivative of order 2n, which implies a zero error for any polynomial of order 2n — 1 or lower. The coefficient of the derivative term in E decreases very rapidly with increasing n, as can be seen in Figure 5.1.
For example, n = 10 gives a coefficient of 2.03 x 10 ~21. Thus, a function having well behaved high order derivatives can be integrated accurately with a formula of fairly low order. The base points x 3 are all distinct, lie between —1 and 1, and are the eigenvalues of a symmetric tridiagonal matrix [26] which can be analyzed very rapidly with the function eigen. Furthermore, the weight factors are simply twice the squares of the first components of the orthonormalized eigenvectors. Because eigen returns orthonormalized eigenvectors for symmetric matrices, only lines 58-60 in function gcquad given below are needed to compute the base points and weight factors.
Function for Composite Gauss Integration
i: f u n c t i o n [ v a l,b p,w f ] = g c q u a d ( f u n c,x l o w,...
2: x h i g h,n q u a d,m p a r t s,v a r a r g i n )
3: %
4: % [ v a l,b p,w f ] = g c q u a d ( f u n c,x l o w,...
5: % x h i g h,n q u a d,m p a r t s,v a r a r g i n )
6:
7: %
8: %
9: % T h i s f u n c t i o n i n t e g r a t e s a g e n e r a l f u n c t i o n u s i n g i o: % a c o mp o s i t e Gauss f o r m u l a o f a r b i t r a r y o r d e r. The i i: % i n t e g r a l v a l u e i s r e t u r n e d a l o n g w i t h b a s e p o i n t s i 2: % and w e i g h t f a c t o r s o b t a i n e d by an e i g e n v a l u e b a s e d i 3: % met hod. The i n t e g r a t i o n i n t e r v a l i s d i v i d e d i n t o i 4: % m p a r t s s u b i n t e r v a l s o f e q u a l l e n g t h and i n t e g r a t i o n i 5: % o v e r e a c h p a r t i s p e r f o r m e d w i t h a Gauss f o r m u l a i 6: % maki ng nqua d f u n c t i o n e v a l u a t i o n s. R e s u l t s a r e i 7: % e x a c t f o r p o l y n o m i a l s of d e g r e e up t o 2 * n q u a d - 1.
i 8: %
i 9: % f u n c - name o f a f u n c t i o n t o be i n t e g r a t e d
2 o: % h a v i n g an a r gume nt l i s t o f t h e f or m
2 i: % f u n c ( x,p 1,p 2,...) wher e any a u x i l i a r y
2 2: % p a r a m e t e r s p 1,p 2,.. a r e p a s s e d t h r o u g h
2 3: % v a r i a b l e v a r a r g i n. Use [ ] f o r t h e
2 4: % f u n c t i o n name i f o n l y t h e b a s e p o i n t s
2 5: % and w e i g h t f a c t o r s a r e n e e d e d.
2 6: % x l o w,x h i g h - i n t e g r a t i o n l i m i t s
2 7: % nqua d - o r d e r o f Gauss f o r m u l a c h o s e n
2 8: % m p a r t s - number of s u b i n t e r v a l s s e l e c t e d i n
2 9: % t h e c o mp o s i t e i n t e g r a t i o n
3 o: % v a r a r g i n - v a r i a b l e l e n g t h p a r a m e t e r u s e d t o
3 i: % p a s s a d d i t i o n a l a r g u me n t s n e e d e d i n
3 2: % t h e i n t e g r a n d f u n c
3 3: % v a l - n u m e r i c a l v a l u e o f t h e i n t e g r a l
3 4: % b p,wf - v e c t o r s c o n t a i n i n g b a s e p o i n t s and
3 5: % w e i g h t f a c t o r s i n t h e c o mp o s i t e
3 6: % i n t e g r a l f o r m u l a
3 7: %
3 8: % A t y p i c a l c a l c u l a t i o n s u c h a s:
3 9: % F u n = i n l i n e ('( s i n ( w * t ).~ 2 ).* e x p ( c * t )','t','w','c');
4 0: % A=0; B=12; nquad=21; mp a r t s = 1 0; w=10; c=8;
4 i: % [ v a l u e,p c t e r r ] = i n t e g r a t e ( F u n,A,B,n q u a d,m p a r t s,w,c );
42: % g i v e s v a l u e = 1.935685556078172e+040 whi c h i s 43: % a c c u r a t e w i t h i n an e r r o r of 1.9 e - 1 3 p e r c e n t.
4 4: %
4 5: % Us e r m f u n c t i o n s c a l l e d: t h e f u n c t i o n name p a s s e d
4 6: % i n t h e a r gume nt l i s t
47:
4 8: %------------------------------------------------------------------------------------------------------------------------------------------------------------
49:
50: i f i s e m p t y ( n q u a d ), nquad=10; end 51: i f i s e m p t y ( m p a r t s ), mp a r t s = 1; end
52:
5 3: % Compute b a s e p o i n t s and w e i g h t f a c t o r s 54: % f o r t h e s i n g l e i n t e r v a l [ - 1,1 ]. ( Ref:
5 5: % 'Me t hods of Nu me r i c a l I n t e g r a t i o n' by 56: % P. Da v i s and P. R a b i n o w i t z, p a g e 93)
57:
5 8: u = ( 1:n q u a d - 1 )./s q r t ( ( 2 * ( 1:n q u a d - 1 ) ).~ 2 - 1 );
5 9: [ v c,b p ] = e i g ( d i a g ( u,- 1 ) + d i a g ( u, 1 ) );
6 0: [ b p,k ] = s o r t ( d i a g ( b p ) ); w f = 2 * v c ( 1,k )'.~ 2;
61:
6 2: % Modi f y t h e b a s e p o i n t s and w e i g h t f a c t o r s 63: % t o a p p l y f o r a c o mp o s i t e i n t e r v a l 64: d = ( x h i g h - x l o w )/m p a r t s; d 1 = d/2;
6 5: d b p = d 1 * b p (:); d w f = d 1 * wf (:); d r = d * ( 1:m p a r t s );
6 6: c b p = d b p (:,o n e s ( 1,m p a r t s ) ) + ...
6 7: d r ( o n e s ( n q u a d,1 ),:) + ( x l o w - d 1 );
6 8: c w f = d w f (:,o n e s ( 1,m p a r t s ) ); w f = c w f (:); b p = c b p (:);
69:
7 0: % Compute t h e i n t e g r a l 71: i f i s e m p t y ( f u n c )
7 2: v a l = [ ];
7 3: e l s e
7 4: f = f e v a l ( f u n c,b p,v a r a r g i n {:} ); v a l = w f'* f (:);
7 5: end
5.3 Comparing Results from Gauss Integration and Function QUADL
A program was written to compare the performance of the Gauss quadrature func­
tion gcquad and the numerical integrator quadl provided in MATLAB. Quadl is a robust adaptive integration routine which efficiently handles most integrands. It can even deal with special integrals having singularities, like log(x) or 1/ sqrt(x) at the origin. Integrating these functions from zero to one yields correct answers although messages occur warning about integrand singularities at the origin. No capabilities
are provided in quadl to directly handle vector integrands (except one component at a time), and no options are provided to suppress unwanted warning or error messages. In the timing program given below, warning messages from quadl were temporarily turned off for the tests.
Often there are examples involving vector-valued integrands that are to be inte­
grated many times over fixed integration limits. A typical case is evaluation of coef­
ficients in Fourier-Bessel series expansions. Then, computing a set of base points and weight factors once and using these coefficients repeatedly is helpful. To illustrate this kind of situation, let us numerically integrate the vector valued function
f(x) = [\/x] log(x) ; humps(x); exp(lOx) cos(107rx); c o s ( 2 0 7 t x — 2 0 sin(7rx))]
from x = 0 to x = 1. Several components of this function are hard to integrate numerically because y/x has infinite slope at x = 0, log(x) is singular at x = 0, the fourth component is highly oscillatory with large magnitude variations, and the last component is highly oscillatory (integrating the last component gives the value of the integer order Bessel function J 20 (20)).
The following function quadtest uses functions quadl and gcquad to integrate f (x) from x = 0 to x = 1. The Gauss integration employs a formula of order 100 with one subinterval, so integrands are effectively approximated by polynomials of order 199. To achieve accurate timing, it was necessary to evaluate the integrals repeatedly until a chosen number of seconds elapsed. Then average times were com­
puted. The program output shows that gcquad was more accurate than quadl for all cases except for log(x) involving a singular integrand. Computations times shown for each component of f (x) are the same when gcquad was used because the inte­
gration was done for all components at once, and then results were divided by five. The total time used by quadl was about 3.5 times as large as the time for qcquad. We are not arguing that these results show gcquad is superior to quadl. However, it does imply that Gauss integration can be attractive in some instances. The geometry problems in the remainder of this chapter include boundary curves defined by cu­
bic splines. Then, using Gauss integration of sufficiently high order produces exact results for the desired geometrical properties.
Output from Program quadtest
>> q u a d t e s t ( 1 0 );
PRESS RETURN TO BEGIN COMPUTATION > ?
INTEGRATION TEST COMPARING FUNCTIONS QUADL AND GCQUAD
The f u n c t i o n s b e i n g i n t e g r a t e d a r e:
s q r t ( x )
l o g ( x )
humps(x)
e x p ( 1 0 * x ).* c o s ( 1 0 * p i * x )
c o s ( 2 0 * p i * x - 2 0 * s i n ( p i * x ) )
R e s u l t s Using Function quadl I n t e g r a l Funct i on Percent Computation
va l u e s e v a l u a t i o n s e r r o r seconds
6.6667e-001 7.8000e+001 -1.9813e-004 6.9720e-003
-1.0000e+000 2.2900e+002 2.6064e-005 2.1071e-002
2.9858e+001 1.9800e+002 6.2164e-010 2.1162e-002
2.0263e+002 7.0800e+002 2.4425e-013 6.8660e-002
1.6475e-001 5.2800e+002 -1.0627e-008 5.1370e-002
R e s u l t s Using Function gcquad I n t e g r a l Funct i on Percent Computation
va l u e s e v a l u a t i o n s e r r o r seconds
6.6667e-001 1.0000e+002 1.5215e-005 9.5628e-003
-9.9994e-001 1.0000e+002 -6.2513e-003 9.5628e-003
2.9858e+001 1.0000e+002 8.8818e-014 9.5628e-003
2.0263e+002 1.0000e+002 -4.1078e-013 9.5628e-003
1.6475e-001 1.0000e+002 -1.5543e-013 9.5628e-003
(Total time u s i ng q u a d l )/( T o t a l time u s i n g gcquad)
equals 3.5395
>>
Program Comparing Numerical Integration Methods
1: f u n c t i o n [ L,G,n a m e s ] = q u a d t e s t ( s e c s )
2: %
3: % [ L,G,n a m e s ] = q u a d t e s t ( s e c s )
4: %..................................................................................................
5: % T h i s p r o g r a m compar es t h e a c c u r a c y and 6: % c o m p u t a t i o n t i m e s f o r s e v e r a l i n t e g r a l s 7: % e v a l u a t e d u s i n g q u a d l and gc qua d
8: %
9: % s e c s - t h e number of s e c o n d s e a c h i n t e g r a t i o n
1 0: % i s r e p e a t e d t o g e t a c c u r a t e t i m i n g. The
1 1: % d e f a u l t v a l u e i s 60 s e c o n d s.
1 2: % L,G - m a t r i c e s w i t h col umns c o n t a i n i n g
13: % r e s u l t s f r om q u a d l and f r o m g c q u a d.
14: % The m a t r i c e s a r e s t r u c t u r e d a s:
15: % [ I n t e g r a l V a l u e,P e r c e n t E r r o r,...
1 6: % F u n c t i o n E v a l u a t i o n s,C o m p u t a t i o n S e c o n d s ]
17: % names - c h a r a c t e r m a t r i x w i t h rows
1 8: % d e s c r i b i n g t h e f u n c t i o n s
19
20:
21:
22
23:
24:
25:
26:
27:
28
29
30:
31:
32
33:
34
35
36
37
38
39
40:
41:
42
43:
44
45
46
47
48
49
50:
51:
52
53:
54:
55:
56:
57
58
59
60:
61:
62
63:
% which were i n t e g r a t e d
%
% User f u n c t i o n s c a l l e d: f t e s t, gcquad %
---------------------------------------------------------------------------------------
g l o b a l n v a l s
i f nargin==0, secs=60; end
f p r i n t f ('\n P R E S S RETURN TO BEGIN COMPUTATION > ') pause
% Summary of t h e f i v e i n t e g r a n d s used n a m e s = s t r v c a t ('s q r t ( x )','l o g ( x )','h u m p s ( x )',...
'e x p ( 1 0 * x ).* c o s ( 1 0 * p i * x )',... 'c o s ( 2 0 * p i * x - 2 0 * s i n ( p i * x ) )'); fprintf(['\n\nINTEGRATION TEST COMPARING',...
' FUNCTIONS QUADL AND GCQUAD\n']) f p r i n t f ('\n T h e f u n c t i o n s b e i n g i n t e g r a t e d a r e:\n') disp(names)
% Compute e x a c t v a l u e s of i n t e g r a l s e x a c t = [ 2/3; - 1; quadl (@humps,0,1,1e-12);
r e a l ( ( e x p ( 1 0 + 1 0 * p i * i ) - 1 )/( 1 0 + 1 0 * p i * i ) );
b e s s e l j ( 2 0,2 0 ) ];
% Find time t o make a loop and c a l l t h e cl ock nmax=5000; nclock=0; t 0= c l o c k; whi l e nclock<nmax
nclock=nclock+1; t c l o c k = e t i m e ( c l o c k,t 0 );
end
t c l o c k = t c l o c k/n c l o c k;
% E val ua t e each i n t e g r a l i n d i v i d u a l l y. Repeat % t h e i n t e g r a t i o n s f o r s e c s seconds t o g e t % a c c u r a t e t i m i n g. Save r e s u l t s i n a r r a y L. L = z e r o s ( 5,4 ); t o l = 1 e - 6; e=exact; warning o f f; f o r k=1:5
nquad=0; tim=0; t 0 =c l o c k; whi l e t im<secs
[ v,n f u n s ] = q u a d l ( @ f t e s t,0,1,t o l,[ ],k ); nquad=nquad+1; t i m = e t i m e ( c l o c k,t 0 ); end
t i m = t i m/n q u a d - t c l o c k; p e = 1 0 0 * ( v/e ( k ) - 1 ); L ( k,:) = [ v,n f u n s,p e,t i m ];
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
end
warning on;
% Obtain t ime t o compute base p o i n t s and weight % f a c t o r s f o r a Gauss for mul a of o r d e r 100 nloop=100; t 0 =c l o c k; f o r j = 1:n l o o p
[ d u m y,b p,w f ] = g c q u a d ( [ ],0,1,1 0 0,1 );
end
t b p w f = e t i m e ( c l o c k,t 0 )/n l o o p;
% Perform t h e Gauss i n t e g r a t i o n u s i n g a % v e c t o r i n t e g r a n d. Save r e s u l t s i n a r r a y G
ngquad=0; tim=0; t 0 =c l o c k; whi l e ti m<secs v = f t e s t ( b p,6 ) * w f;
ngquad=ngquad+1; t i m = e t i m e ( c l o c k,t 0 ); end
ti m=ti m/ngqua d+t bpwf - t c l ock; p e = 1 0 0 * ( v./e - 1 ); G = [ v,1 0 0 * o n e s ( 5,1 ),p e,t i m/5 * o n e s ( 5,1 ) ];
format s h o r t e d i s p (' ')
d i s p (' R e s u l t s Using Funct i on q u a d l')
d i s p (...
' I n t e g r a l Funct i on P e r c e n t Computati on')
d i s p (...
' v a l u e s e v a l u a t i o n s e r r o r s e c o n d s') di s p( L)
d i s p (' R e s u l t s Using Funct i on gcqua d')
d i s p (...
' I n t e g r a l F u nct i on P e r c e n t Computati on')
d i s p (...
' v a l u e s e v a l u a t i o n s e r r o r s e c o n d s')
disp(G)
format s h o r t
d i s p ( ['( T o t a l ti me u s i n g q u a d l )/',...
'( T o t a l ti me u s i n g g c q u a d )'] ) d i s p ( ['e q u a l s ',...
n u m 2 s t r ( s u m ( L (:,e n d ) )/s u m ( G (:,e n d ) ) ) ] ) d i s p (' ')
%=============================================
1 0 9: f u n c t i o n y = f t e s t ( x,n )
i i o: % I n t e g r a n d s u s e d by f u n c t i o n q u a d l
i i i: g l o b a l n v a l s
i i 2: s w i t c h n
i i 3: c a s e 1, y = s q r t ( x ); c a s e 2, y = l o g ( x ); i i 4: c a s e 3, y=humps ( x); i i 5: c a s e 4, y = e x p ( 1 0 * x ).* c o s ( 1 0 * p i * x ); i i 6: c a s e 5, y = c o s ( 2 0 * p i * x - 2 0 * s i n ( p i * x ) ); i i 7: o t h e r w i s e
i i 8: x = x (:) ’; y = [ s q r t ( x );l o g ( x );h u m p s ( x );
i i 9: e x p ( 1 0 * x ).* c o s ( 1 0 * p i * x );
i 2 0: c o s ( 2 0 * p i * x - 2 0 * s i n ( p i * x ) ) ];
i 2 i: end
i 2 2: i f n<6, n v a l s = n v a l s + l e n g t h ( x ); i 2 3: e l s e, n v a l s = n v a l s + 5 * l e n g t h ( x ); end
i 2 4:
i 2 5: %=============================================
i 2 6:
i 2 7: % f u n c t i o n [ v a l,b p,w f ] = g c q u a d ( f u n c,x l o w,...
i 2 8: % x h i g h,n q u a d,m p a r t s,v a r a r g i n )
i 2 9: % See Appe ndi x B
5.4 Geometrical Properties of Areas and Volumes
Geometrical properties of areas and volumes are often needed in physical applica­
tions such as linear stress analysis and rigid body dynamics. For example, consider a prismatic structural member having a general cross-section area denoted by A with a boundary curve L. Analyzing the stresses occurring when the member undergoes axial compression and bi-axial bending leads to integrals of the form
Cnm = J J xnymdxdy A
for integers n and m. The six most important cases and the related property names are: _______________________________________________________
n
m
Symbol
Geometrical Parameter
0
0
a
Area
1
0
ax
First moment of area about the y-axis
0
1
ay
First moment of area about the x-axis
2
0
axx
Moment of inertia about the y-axis
1
1
axy
Product of inertia with respect to the xy axes
0
2
ayy
Moment of inertia about the x-axis
The integral Cnm can be evaluated for very general shapes by converting the area integral to a line integral over the boundary. Then, approximating the boundary curve
parametrically (by spline interpolation, for example) and using numerical integration yield the desired values. Green’s theorem [119] relates area integrals and line inte­
grals according to
dU dV dx dy
dxdy = j) Udy — Vdx
L
where U(x, y) and V(x, y) are single-valued and differentiable functions inside and on L. This implies that
xnym dxdy =
1
n + m + 2
d
— (x"+1ym) + £ ( x"y m+1)
d
dy
dxdy
1
n + m + 2
— ydx)'
provided n + m + 2 = 0. We can even have negative n provided x = 0 is outside L, and negative m provided y = 0 is outside L. The case (n, m) = (0, —1) occurring in curved beam theory can also be treated by line integration, but we will confine attention to the six cases listed above.
If the boundary curve, L, is parameterized as x(t), y(t), a < t < b, then
b
j ) x nym(xdy — y dx) = J x(t)ny(t)m[x(t)y'(t) — y(t)x'(t)] dt
L a
which is a one-dimensional integral amenable to numerical integration. When cubic spline interpolation is used to represent the boundary, then x(t)y '(t) — y(t)x'(t) is a piecewise polynomial function of degree four (not degree five as seems apparent at first glance). Since a Gaussian quadrature formula of order N integrates exactly any polynomial of degree 2N — 1 or less, the integral of interest can be integrated exactly by taking 2N — 1 > 3n + 3m + 4. For our case, using a composite Gauss formula of order six is appropriate. A program is given below to compute properties for a general geometry that can have several separate parts, and these parts may contain holes. The details of that program are discussed later.
The ideas for plane regions can be extended to three dimensions where volume, gravity center location, and inertia tensor are the quantities being computed. Let
R = [x ; y ; z ]
be the Cartesian radius vector for points in a three-dimensional region W covered by
a surface S. The Gauss divergence theorem [119] implies
V = J J J dx dy dz = — J J R ■ η dS, w s
V r = j j j R d x dy dz = ^ R ( R ■ ή) dS w
V r r = Ι/Ι R R'd x dy dz = ^ / / R R ( R ■ ή) dS.
rr
w
I n t he l ast equat i on, R R' is the matrix product [x; y; z] * [x, y, z] and η is the outward directed unit surface normal. We refer to V, V r, and V rr as the volume, the first moment of volume, and the second moment of volume. These quantities can be evaluated exactly for some special cases, such as polyhedra, and volumes of revolution.
The quantity V rr is useful in rigid body dynamics where the inertia tensor, I rr , is needed to compute the rotational kinetic energy. The inertia tensor for a body having unit mass density can be computed from V rr as
Irr = eye(3, 3) sum(diag(Vr r )) — V rr.
The cor r espondi ng i nver se is
e ye(3 3)
V rr =- - - - -^ — s u m( d i a g ( J r r ) ) — Irr.
To illustrate the computation of volume properties, consider the instance where the surface has a parametric equation of the form
R(u,v), ui < u < u2, vi < v < v- 2.
For exampl e, t he el l i psoi d def i ned by
(§)’+(!)’+©’ si
has a sur f ace equat i on
R = [asin(u)cos(v); bsin(u)sin(v); c cos(v)], 0 < u < π, 0 < v < 2π. The unit surface normal and the differential of surface area can be computed as
A d R d R f) db = —— x ——dudv du dv
wher e t he or der of t he cr oss pr oduct i s chosen so t hat t he out war d di r ect ed nor mal is pr oduced. Then,
( R · η) dS = det ( [ R, R u, R v]) = D(u, v) du dv
and the integrals of interest become
V2 U2
V = — J J D( u,v) dudv,
V1 U1 V2 U2
Vr = — J J RD( u,v) dudv,
V1 U1 V2 U2
Vrr = — J J R R' D(u,v)dudv.
Not e t hat t he f unct i on D(u, v) vanishes at points where the radius vector R is per­
pendicular to the surface normal. A useful instance of the parametric form occurs when a closed curve is rotated to form a volume of revolution as illustrated in Fig­
ure 5.2.
Consider a curve defined parametrically in the (x, z) plane as x(t), z(t), a < t < b. If the curve is rotated about the z axis through angular limits θ i < θ < θ2, the lateral surface of the body has a surface equation
R(t, θ) = [cos^); 8ΐη(θ); 1]. * [x ; x ; z]
and the volume property integrals reduce to
V = — j) x[xd,z — zdx],
L
θ1
Vr = — J [cos(0); sin(0); 1] άθ. * j ) [x2; x2; xz]d,xd,z,
θ1 L
θ1
Vrr = — J [cos(0); sin(0); 1] * [cos(0), sin(0), 1]άθ. θ1
* j ) [x ; x ; z] * [x, x, z] xdxdz.
The l i ne i nt egr al s i n t he l ast t hr ee f or mul as have si mi l ar st r uct ur e t o t hose f or pl ane ar ea pr oper t i es, but t he hi ghes t pol ynomi al power i n t he i nt egr ands of t he f or m x nzm is one higher than that encountered for plane area properties. Taking a composite Gauss formula of order seven produces exact results for the volume properties when a spline interpolated boundary curve is used. A program employing these formulas is developed below.
5.4.1 Area Property Program
A program was written to compute the area, the centroidal coordinates, the inertial moments, and the product of inertia for general plane areas bounded by a series of spline curve segments. Shapes such as polygons, having one or more straight boundary segments, are also handled by allowing slope discontinuities at the ends of the straight segments. The program requires data points xd(j), yd( j ),
1 < j < nd
with the boundary traversed in a counterclockwise sense. The first and last points should be identical to make the curve closed. A set of point indices designating any slope discontinuities ( such as those at the corners of a square) are also needed.
A typical geometry for the program appears in
Figure 5.3
. Program data created by the function makcrcsq employs 27 data points. A multiply connected geometry is treated as if it were a simply connected region by introducing fictitious cuts con­
necting outer boundaries and inner holes. Disconnected parts are also joined with zero width strips. Including the cuts and strips has no effect on the area properties because related boundary segments are traversed twice, but in opposite directions. Consequently, the corresponding line integral contributions from the fictitious parts cancel. The complete boundary is parameterized as a spline curve in complex form
z(t) = x(t) + i y(t), 1 < t < nd
wi t h
z(j ) = xd(j) + i yd(j), j = 1, 2,..., nd.
HALF ANNULUS ABOVE A SQUARE WITH A HOLE
7
6
5
co
's
4
3
2
1
8
Figure 5.3: Geometry Showing Numbered Boundary Points
The boundary curve and its derivatives are piecewise polynomial functions. Exact results for the geometrical properties are obtained by using the function gcquad to generate Gauss base points and weight factors for integration limits from 1 to nd, and a number of integration segments equal to nd — 1. The various area properties are accumulated in vector mode for computational efficiency.
The function runaprop is the main driver for the program. It accepts boundary data, calls the function aprop to compute area properties, prints results, and plots the geometry. If no input data are given, the function makcrcsq is called to create data for the illustrative example. The plot produced by the program resembles the one shown, without inclusion of point indices.
15
13
12
11
10
-1
2 3 x axis
0
4
5
6
7
The numerical output for our example has the following simple form:
>> runaprop;
GEOMETRICAL PROPERTY ANALYSIS USING FUNCTION APROP
A XCG YCG AXX AXY AYY
16.7147 3.0000 4.1254 176.3369 206.8620 359.6076
>>
Program for Properties of Spline Bounded Areas
f u n c t i o n [ p,x,y,x d,y d ] = a r e a p r o g ( x d,y d,i c r n r )
%
% [ p,x,y,x d,y d ] = a r e a p r o g ( x d,y d,i c r n r )
%.......................................................................................
% This f u n c t i o n c a l l s f u n c t i o n aprop which % computes g e o m e t r i c a l p r o p e r t i e s f o r an a r e a % bounded by a s p l i n e curve t h r o u g h d a t a % p o i n t s i n ( x d,y d ).
%
% User f u n c t i o n s c a l l e d: aprop
i f n a r g i n = = 2,i c r n r = [ 1,l e n g t h ( x d ) ]; end titl='AREA IN THE XY PLANE';
i f nargin==0
[ x d,y d,i c r n r ] = m a k c r c s q; t i t l =...
'HALF ANNULUS ABOVE A SQUARE WITH A HOLE'; end
d i s p (' ')
d i s p ( [' GEOMETRICAL PROPERTY ANALYSIS',...
' USING FUNCTION APROP']) [ p,z ] = a p r o p ( x d,y d,i c r n r ); x = r e a l ( z ); y=imag(z); d i s p (' ');
d i s p ( [' A XCG YCG ',...
' AXX AXY AYY'])
d i s p ( p ), c l o s e, p l o t ( x d,y d,'k o',x,y,'k -')
x l a b e l ('x a x i s'), y l a b e l ('y a x i s') t i t l e ( t i t l ),a x i s ( c u b r a n g e ( [ x (:),y (:) ],1.2 ) );
32
33
34
35
36
37
38
39
40
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
74
75
76
a x i s s q u a r e; shg
%=========================================
f u n c t i o n [ p,z p l o t ] = a p r o p ( x d,y d,k n )
%
% [ p,z p l o t ] = a p r o p ( x d,y d,k n )
%................................................................
% This f u n c t i o n de t e r mi ne s g e o m e t r i c a l p r o p e r t i e s % of a g e n e r a l p l a n e a r e a bounded by a s p l i n e % curve
%
% xd,yd - d a t a p o i n t s f o r s p l i n e i n t e r p o l a t i o n % wi t h t h e boundary t r a v e r s e d i n c o u n t e r -
% cl ockwise d i r e c t i o n. The f i r s t and l a s t
% p o i n t s must match f o r boundary c l o s u r e.
% kn - v e c t o r of i n d i c e s of p o i n t s where t h e
% s l o p e i s d i s c o n t i n u o u s t o ha ndl e c o r n e r s
% l i k e t h o s e needed f o r shapes such as a
% r e c t a n g l e.
% p - t h e v e c t o r [ a,x c g,y c g,a x x,a x y,a y y ]
% c o n t a i n i n g t h e a r e a, c e n t r o i d c o o r d i n a t e s,
% moment of i n e r t i a about t h e y - a x i s,
% p r oduc t of i n e r t i a, and moment of i n e r t i a
% about t h e x - a x i s
% z p l o t - complex v e c t o r of boundary p o i n t s f o r % p l o t t i n g t h e s p l i n e i n t e r p o l a t e d geometry.
% The p o i n t s i n c l u d e t h e nume r i c al q u a d r a t u r e
% p o i n t s i n t e r s p e r s e d wi t h d a t a v a l u e s.
%
% User f u n c t i o n s c a l l e d: gcquad, curve2d i f nargin==0
t d = l i n s p a c e ( 0,2 * p i,1 3 ); k n =[ 1,1 3 ]; xd=cos ( td) +1; y d = s i n ( t d ) + 1; end
n d = l e n g t h ( x d ); nseg=nd-1; [ d u m,b p,w f ] = g c q u a d ( [ ],1,n d,6,n s e g ); [ z,z p l o t,z p ] = c u r v e 2 d ( x d,y d,k n,b p ); w = [ o n e s ( s i z e ( z ) ), z, z.* c o n j ( z ), z.~ 2 ].*...
r e p m a t ( i m a g ( c o n j ( z ).* z p ),1,4 ); v = ( w f'* w )./[ 2,3,8,8 ]; v r = r e a l ( v ); vi=i mag(v); p = [ v r ( 1:2 ),v i ( 2 ),v r ( 3 ) + v r ( 4 ),v i ( 4 ),v r ( 3 ) - v r ( 4 ) ]; p ( 2 ) = p ( 2 )/p ( 1 ); p ( 3 ) = p ( 3 )/p ( 1 );
%
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
%
% [ z,z p l o t,z p ] = c u r v e 2 d ( x d,y d,k n,t )
%.....................................................................................
% This f u n c t i o n g e n e r a t e s a s p l i n e curve t hrough % gi ven d a t a p o i n t s wi t h c o r n e r s ( s l o p e d i s - % c o n t i n u i t i e s ) al lowed as s e l e c t e d p o i n t s.
f u n c t i o n [ z,z p l o t,z p ] = c u r v e 2 d ( x d,y d,k n,t )
% xd,yd - r e a l d a t a v e c t o r s of l e n g t h nd % d e f i n i n g t h e curve t r a v e r s e d i n
% c ou n t e r c l o c k w i s e o r d e r.
% kn - v e c t o r s of p o i n t i n d i c e s, between one
% and nd, where s l o p e d i s c o n t i n u i t i e s
% occur
% t - a v e c t o r of par amet er v a l u e s a t which
% p o i n t s on t h e s p l i n e curve a r e
% computed. The components of t normal l y
% range from one t o nd, except when t i s
% a n e g a t i v e i n t e g e r,- m. Then t i s
% r e p l a c e d by a v e c t o r of e q u a l l y spaced
% v a l u e s u s i n g m s t e p s between each
% s u c c e s s i v e p a i r of p o i n t s.
% z - v e c t o r of p o i n t s on t h e s p l i n e curve
% c or r e s p o n d i n g t o t h e v e c t o r t
% z p l o t - a complex v e c t o r of p o i n t s s u i t a b l e % f o r p l o t t i n g t h e geometry
% zp - f i r s t d e r i v a t i v e of z wi t h r e s p e c t t o
% t f o r t h e same v a l u e s of t as i s used
% t o compute z
%
% User m f u n c t i o n s c a l l e d: s p l i n e d
%-----------------------------------------------------------------------------------
n d = l e n g t h ( x d ); z d = x d (:) + i * y d (:); t d = ( 1:n d )'; i f i s e m p t y ( k n ), kn=[ 1;nd]; end k n = s o r t ( k n (:) ); i f kn(1)~=1, kn =[ 1;k n ]; end i f kn(end)~=nd, kn=[kn;nd]; end N=l engt h( kn) - 1; m = r o u n d ( a b s ( t ( 1 ) ) ); i f -t(1)==m, t = l i n s p a c e ( 1,n d,1 + N * m )'; end z = [ ]; z p = [ ]; z p l o t = [ ]; f o r j=1:N
k 1 = k n ( j ); k2=kn(j+1); K=k1:k2; k=fi nd(k1<=t & t < k 2 ); i f j==N, k=find(k1<=t & t<=k2); end i f ~isempty(k)
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
z k = s p l i n e ( K,z d ( K ),t ( k ) ); z = [ z;z k ]; z p l o t = [ z p l o t;z d ( k 1 );z k ]; i f nargout==3
z p = [ z p;s p l i n e d ( K,z d ( K ),t ( k ) ) ]; end end end
z p l o t = [ z p l o t;z d ( e n d ) ];
%=========================================
f u n c t i o n [ x,y,i c r n r ] = m a k c r c s q %
% [ x,y,i c r n r ] = m a k c r c s q %
...................................................
% This f u n c t i o n c r e a t e s d a t a f o r a geometry % i n v o l v i n g h a l f of an annulus p l a c e d above a % s quar e c o n t a i n i n g a s quar e h o l e.
%
% x,y - d a t a p o i n t s c h a r a c t e r i z i n g t h e d a t a % i c r n r - i ndex v e c t o r d e f i n i n g c o r n e r p o i n t s %
% User m f u n c t i o n s c a l l e d: none
%-----------------------------------------------------------------------------------------
x s h i f t = 3.0; y s h i f t = 3.0;
a=2; b=1; narc=7; x0=0; y0=2*a-b;
x y = [ a,- a,- b, b, b,- b,- b,- a,- a, a, a;
a, a, b, b,- b,- b, b, a,- a,- a, a ]'; t h e t a = l i n s p a c e ( 0,p i,n a r c )'; c = c o s ( t h e t a ); s = s i n ( t h e t a ); x y=[ xy;[ x0+ a*c,y0+a *s ] ]; c = f l i p u d ( c ); s = f l i p u d ( s ); x y = [ x y;[ x 0 + b * c,y 0 + b * s ];[ a,y 0 ];[ a,a ] ]; x = x y (:,1 ) + x s h i f t; y = x y (:,2 ) + y s h i f t; i c r n r = [ ( 1:1 2 )';1 1 + n a r c;1 2 + n a r c; ...
11+2*narc;12+2*narc;13+2*narc];
%=========================================
% f u n c t i o n [ v a l,b p,w f ] = g c q u a d ( f u n c,x l o w,...
% x h i g h,n q u a d,m p a r t s,v a r a r g i n )
% See Appendix B
%=========================================
1 6 8: % f u n c t i o n r a n g e = c u b r a n g e ( x y z,o v r s i z )
1 6 9: % See Appendi x B
1 7 0:
1 7 1: %=========================================
1 7 2:
1 7 3: % f u n c t i o n v a l = s p l i n e d ( x d,y d,x,i f 2 )
1 7 4: % See Appendi x B
5.4.2 Program Analyzing Volumes of Revolution
Since the geometrical property computation for a volume of revolution is quite similar to that for area properties, the same functions gcquad and curve2d used in the area program are employed below to compute the volume, centroidal coordinates, and inertia tensor of a solid generated by rotating a spline curve through arbitrary an­
gular limits about the z axis. In the following program, the function volrevol calls a general purpose function volrev which computes the geometrical properties and plots the related volume of revolution. The function volrev depends on gcquad, curve2d, function rotasurf to plot the body surface, and function anglefun which deals with rotation angle dependence. The function returns volume properties and surface coordinates on the solid. Area properties of the cross section are also ob­
tained.
The geometry in
Figure 5.4 was analyzed. The area, rotated through 270 degrees, consists of the bottom half of a semicircle capped on the outer radius by a square which is also capped by a smaller semicircle. Results from volrev were confirmed to agree closely with another function srfv, which is discussed in the next section. Be­
cause the function srfv employs triangular surface elements, the two computational models are not identical. This accounts for the slight difference in numerical results.
In conclusion, the volume property program to handle volumes of revolution for spline interpolated cross sections was found to be a useful extension of the methods developed earlier for properties of areas.
Computer Output from Volume of Revolution Program
>> volrevol
PROPERTIES OF A VOLUME OF REVOLUTION Results Using Function VOLREV Volume =59.1476 Rg = [0.91028 0.91028 0.13755]
Inertia Tensor =
1.0e+003 *
0.5773 0.1168 -0.0090 0.1168 0.5773 -0.0090 -0.0090 -0.0090 1.1010
Area Properties
167:
area xcentr zcentr.
2.9638 4.2350 0.1045
axx axz azz
53.8408 1.7264 1.3101
Results Using Function SRFV
Volume =59.1056
Rg = [0.91016 0.91016 0.13749]
Inertia Tensor =
1.0e+003 *
0.5768 0.1167 -0.0090 0.1167 0.5768 -0.0090 -0.0090 -0.0090 1.0999
>>
VOLUME OF REVOLUTION
Figure 5.4: Partial Volume of Revolution
Program for Properties of a Volume of Revolution
5
1: f u n c t i o n v o l r e v o l
2: %
3: % v o l r e v o l
4: %..................................
5:
6:
7:
8:
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
35
36
37:
38
39
40:
41:
42
43:
44
45
46
47:
48
49
% This program d e t er mi ne s g e o m e t r i c a l p r o p e r t i e s % f o r a s o l i d g e n e r a t e d by r o t a t i n g a c l o s e d s p l i n e % curve t hr ough an a r b i t r a r y angl e about t h e z - a x i s. % A d e t a i l e d d e s c r i p t i o n of t h e geometry i s gi ven i n % f u n c t i o n v o l r e v.
%
% User m f u n c t i o n s c a l l e d: v o l r e v s r f v
%-----------------------------------------------------------------------------------------
%
% Data f o r a c r o s s s e c t i o n c o n s i s t i n g of t h e lower % h a l f of a c i r c l e p l u s a s quar e capped by t h e % upper h a l f of a s m a l l e r s e m i c i r c l e. The geometry % i s r o t a t e d t hr ough 270 d eg r ees about t h e z - a x i s.
n1=9; t 1 = - p i:p i/n 1:0; n2=6; t 2 = 0:p i/n 2:p i; Z d = [ 0,e x p ( i * t 1 ),1/2 + i + e x p ( i * t 2 )/2,0 ]; xd=re al (Zd)+4; zd=imag(Zd); t h = [ - p i/2,p i ]; nth=31; kn=[1,2,n1+2,n1+3,n1+n2+3,n1+n2+4];
% Compute t h e g e o m e t r i c a l p r o p e r t i e s [ v,r g,I r r,x,y,z,a p r o p ] = v o l r e v (...
x d,z d,k n,t h,n t h );
d i s p (' ')
disp('PROPERTIES OF A VOLUME OF REVOLUTION') d i s p (' ')
d i s p ('R e s u l t s Using F u nct i on VOLREV') di s p ( ['Vo l u me = ',n u m 2 s t r ( v ) ] ), %di sp(' ') d i s p ( ['R g = [',n u m 2 s t r ( r g (:)'),']'] ), %di sp(' ') d i s p ('I n e r t i a Tensor ='), d i s p ( I r r ), %di sp(' ') d i s p ('A r e a P r o p e r t i e s'), %di sp(' ') d i s p (' a r e a x c e n t r z c e n t r.')
d i s p ( a p r o p ( 1:3 ) )
d i s p (' axx axz a z z')
d i s p ( a p r o p ( 4:6 ) )
% Run a second case t o g e n e r a t e a dense s e t of % s u r f a c e c o o r d i n a t e s t o check r e s u l t s u s i n g % f u n c t i o n s r f v.
N1=61; T 1 = - p i:p i/N 1:0; N2=41; T 2 = 0:pi/N2:pi; Z d = [ 0,e x p ( i * T 1 ),1/2 + i + e x p ( i * T 2 )/2,0 ]; xxd=real (Zd)+4; zzd=imag(Zd); t h = [ - p i/2,p i ]; Nth=121;
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
Kn=[1,2,N1+2,N1+3,N1+N2+3,N1+N2+4];
[V,Rg,I RR,X,Y,Z] =vol r e v(...
x x d,z z d,K n,t h,N t h,1 ); [ v t,r c t,v r r t ] = s r f v ( X,Y,Z ); d i s p ('R e s u l t s Using F u nct i on SRFV') d i s p ( ['Vo l u me = ',n u m 2 s t r ( v t ) ] ) d i s p ( ['R g = [',n u m 2 s t r ( r c t (:)'),']'] ) d i s p ('I n e r t i a Tensor ='), d i s p ( v r r t )
%=========================================
f u n c t i o n [ v,r g,I r r,X,Y,Z,a p r o p,x d,z d,k n ] =...
v o l r e v ( x d,z d,k n,t h,n t h,n o p l o t )
% [ v,r g,I r r,X,Y,Z,a p r o p,x d,z d,k n ] =...
% v o l r e v ( x d,z d,k n,t h,n t h,n o p l o t )
This f u n c t i o n computes g e o m e t r i c a l p r o p e r t i e s f o r a volume of r e v o l u t i o n r e s u l t i n g when a c l o s e d curve i n t h e ( x,z ) p l a n e i s r o t a t e d, t hr ough gi ven a n g u l a r l i m i t s, about t h e z a x i s. The c r o s s s e c t i o n of t h e volume i s d e f i n e d by a s p l i n e curve p a s s e d t hr ough d a t a p o i n t s (xd,zd) i n t h e same manner as was done i n f u n c t i o n a r eapr op f o r p l a n e a r e a s.
x d,z d - d a t a v e c t o r s d e f i n i n g t h e s p l i n e i n t e r p o l a t e d boundary, which i s t r a v e r s e d i n a c ou n t e r c l o c k wi s e d i r e c t i o n
kn - i n d i c e s of any p o i n t s where s l o p e
d i s c o n t i n u i t y i s al lowed t o t u r n s har p c o r n e r s p - v e c t o r of volume p r o p e r t i e s c o n t a i n i n g
[v, xcg, ycg, zcg, vxx, vyy, v z z,... vxy, vyz, vzx] where v i s t h e volume, ( x c g,y c g,z c g ) a r e c o o r d i n a t e s of t h e c e n t r o i d, and t h e remai ning p r o p e r t i e s a r e volume i n t e g r a l s of t h e f o l l o w i n g i n t e g r a n d:
[x.~, y.~ 2, z.~ 2, xy, yz, zx]*dxdyxz X,Y,Z - d a t a a r r a y s c o n t a i n i n g p o i n t s on t h e s u r f a c e of r e v o l u t i o n. P l o t t i n g t h e s e
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
% p o i n t s shows t h e s o l i d volume wi t h
% t h e ends l e f t open. Func t i on f i l l 3
% i s used t o p l o t t h e s u r f a c e wi t h ends
% c l o s e d
% aprop - a v e c t o r c o n t a i n i n g p r o p e r t i e s of t h e % a r e a i n t h e ( x,z ) p l a n e which was used
% t o g e n e r a t e t h e volume. a p r o p = [ a r e a,...
% x c e n t r o i d a l, y c e n t r o i d a l, axx, axz, a z z ].
% User m f u n c t i o n s c a l l e d: r o t a s u r f, gcquad,
% curve2d, a n g l e f u n, s p l i n e d
%-----------------------------------------------------------------------------------------
i f nargin==0
t 1 = - p i:p i/6:0; t 2 = 0:p i/6:p i; Z d = [ 0,e x p ( i * t 1 ),1/2 + i + e x p ( i * t 2 )/2,0,- 1 ]; xd=real (Zd)+4; zd=imag(Zd); k n = [ 1,2,8,9,1 5,1 6 ]; t h = [ - p i/2,p i ]; nth=31; end
% P l o t a s u r f a c e of r e v o l u t i o n based on t h e % i n p u t d a t a p o i n t s i f nargin==6
[ X,Y,Z ] = r o t a s u r f ( x d,z d,t h,n t h,1 );
e l s e
[ X,Y,Z ] = r o t a s u r f ( x d,z d,t h,n t h ); pause end
% Obtain base p o i n t s and weight f a c t o r s f o r t h e % composite Gauss for mul a of o r d e r seven used i n % t h e numeri c al i n t e g r a t i o n n d = l e n g t h ( x d ); nseg=nd-1; [ d u m,b p,w f ] = g c q u a d ( [ ],1,n d,7,n s e g );
% E val ua t e complex p o i n t s and d e r i v a t i v e v a l u e s % on t h e s p l i n e curve which i s r o t a t e d t o form % t h e volume of r e v o l u t i o n [ u,u p l o t,u p ] = c u r v e 2 d ( x d,z d,k n,b p );
% p l o t ( r e a l ( u p l o t ),i m a g ( u p l o t ) ), a x i s e q u a l,s h g u = u (:); u p = u p (:); n = l e n g t h ( b p ); x = r e a l ( u ); d x = r e a l ( u p ); z=imag(u); dz=imag(up); da=x.*dz- z.*dx;
% E val ua t e l i n e i n t e g r a l s f o r a r e a p r o p e r t i e s p = [ o n e s ( n,1 ), x, z, x.~ 2, x.* z, z.~ 2, x.~ 3,...
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
( x.~ 2 ).* z, x.* ( z.~ 2 ) ].* r e p m a t ( d a,1,9 ); p = ( w f (:)'* p )./[ 2 3 3 4 4 4 5 5 5 ];
% S c a l e a r e a p r o p e r t i e s by m u l t i p l i e r s i n v o l v i n g % t h e r o t a t i o n a n g l e f o r t h e vol ume f = a n g l e f u n ( t h ( 2 ) ) - a n g l e f u n ( t h ( 1 ) ); v = f ( 1 ) * p ( 2 ); r g = f ( [ 2 3 1 ] ).* p ( [ 4 4 5 ] )/v; v r r = [ f ( [ 4 5 2 ] ); f ( [ 5 6 3 ] ); f ( [ 2 3 1 ] ) ].*...
[ p ( [ 7 7 8 ] ); p ( [ 7 7 8 ] ); p ( [ 8 8 9 ] ) ]; I r r = e y e ( 3 ) * s u m ( d i a g ( v r r ) ) - v r r; a p r o p = [ p ( 1 ),p ( 2:3 )/p ( 1 ),p ( 4:6 ) ];
%=========================================
f u n c t i o n f = a n g l e f u n ( t )
% f = a n g l e f u n comput es m u l t i p l i e r s i n v o l v i n g % t, t h e r o t a t i o n a n g l e of t h e vol ume. c = c o s ( t ); s = s i n ( t );
f = [ t,s,- c,( t + c * s )/2,s * s/2,( t - c * s )/2 ];
%=========================================
f u n c t i o n [ x,y,z,x d,z d ] = r o t a s u r f ( x d,z d,t h,n t h,n o p l o t ) % [ x,y,z,x d,z d ] = r o t a s u r f ( x d,z d,t h,n t h,n o p l o t )
% T h i s f u n c t i o n g e n e r a t e s p o i n t s on a s u r f a c e of % r e v o l u t i o n g e n e r a t e d by r o t a t i n g an a r e a i n % t h e ( x,z ) p l a n e a b o u t t h e z - a x i s %
% x d,y z - c o o r d i n a t e d a t a f o r t h e c u r v e i n t h e % ( x,y ) whi c h f o r ms t h e c r o s s s e c t i o n
% t h - [ The t a Mi n,Thet a Ma x] d e f i n i n g l i m i t s of
% r o t a t i o n a n g l e a b o u t t h e z - a x i s
% n t h - number of t h e t a v a l u e s u s e d t o g e n e r a t e
% s u r f a c e v a l u e s
% n o p l o t - o p t i o n g i v e n any v a l u e i f no p l o t i s % d e s i r e d. O t h e r w i s e omi t t h i s v a l u e.
% x,y,z - a r r a y s of p o i n t s on t h e s u r f a c e %
% Us e r m f u n c t i o n s c a l l e d: none %-----------------------------------------------------------------------------------------
i f n a r g i n = = 0
n1=9; t 1 = - p i:p i/n 1:0; n2=6; t 2 = 0:p i/n 2:p i; Z d = [ 0,e x p ( i * t 1 ),1/2 + i + e x p ( i * t 2 )/2,0 ]; x d = r e a l ( Z d ) + 4; z d =i ma g ( Zd );
185: t h = [ - p i/2,p i ]; n t h = 3 1;
1 8 6: end
1 8 7: x d = x d (:); z d = z d (:); n d = l e n g t h ( x d );
1 8 8: t = l i n s p a c e ( t h ( 1 ),t h ( 2 ),n t h ) ;
1 8 9: x = x d * c o s ( t ); y = x d * s i n ( t ); z = r e p m a t ( z d,1,n t h );
1 9 0: i f n a r g i n = = 5, r e t u r n; end
1 9 1: c l o s e; s u r f ( x,y,z ), t i t l e('VOLUME OF REVOLUTION') 192: x l a b e l ('x a x i s'), y l a b e l ('y a x i s')
1 9 3: z l a b e l ('z a x i s'), c o l o r m a p ( [ 1 1 1 ] ); h o l d on 194: f i l l 3 ( x (:,1 ),y (:,1 ),z (:,1 ),'w')
1 9 5: f i l l 3 ( x (:,e n d ),y (:,e n d ),z (:,e n d ),'w')
1 9 6: a x i s e q u a l, g r i d on, h o l d o f f, s h g
1 9 7:
1 9 8: %=========================================
1 9 9:
2 0 0: % f u n c t i o n [ z,z p l o t,z p ] = c u r v e 2 d ( x d,y d,k n,t )
2 0 1: % See Appe ndi x B
2 0 2:
2 0 3: %=========================================
2 0 4:
2 0 5: % f u n c t i o n [ v a l,b p,w f ] = g c q u a d ( f u n c,x l o w,...
2 0 6: % x h i g h,n q u a d,m p a r t s,v a r a r g i n )
2 0 7: % See Appe ndi x B
2 0 8:
2 0 9: %=========================================
2 1 0:
2 1 1: % f u n c t i o n r a n g e = c u b r a n g e ( x y z,o v r s i z )
2 1 2: % See Appe ndi x B
2 1 3:
2 1 4: %=========================================
2 1 5:
2 1 6: % f u n c t i o n v a l = s p l i n e d ( x d,y d,x,i f 2 )
2 1 7: % See Appe ndi x B
2 1 8:
2 1 9: %=========================================
2 2 0:
2 2 1: % f u n c t i o n [ v,r c,v r r ] = s r f v ( x,y,z )
2 2 2: % See Appe ndi x B
5.5 Computing Solid Properties Using Triangular Surface Elements and Using Symbolic Math
In this section a numerical method is developed to compute properties of a solid covered by triangular surface elements. An example problem is analyzed by a nu­
merical method and also by use of the symbolic math toolbox. Results of the two analyses are compared.
Many familiar solid bodies such as an ellipsoid, a conical frustum, or a torus have surfaces readily parameterized by equations of the form
This is the type of equation implied when MATLAB function surf uses rectangular X, Y, Z coordinate arrays to depict a curvilinear coordinate net covering a surface. The surface is approximated by a series of quadrilateral surface patches. Geometri­
cal properties of the related solid can be computed approximately by dividing each quadrilateral into two triangular patches, and accumulating the surface integral con­
tributions of the triangles. This approach is attractive because the surface integral properties of triangles can be computed exactly, and all triangles can be processed in parallel. Although the geometrical properties for a solid covered by triangular patches can be computed exactly, the reader should realize that many surface ele­
ments may be required to achieve several digit accuracy for highly curved surfaces.
To fix our ideas, consider the solid in Figure 5.5 which resembles a twisted rope. This body has its outer surface (as distinguished from its ends) described by the following set of equations:
x = xo + ρ cos(p), y = yo + ρ sin(p), z = zo — ξ sin(mp) + η cos(mp), ρ = a + ξ cos(mp) + η sin(mp), 0 < t < 2π, 0 < p < 3π, ξ = b cos(t) | cos(t)|, η = b sin(t) |cos(t)| .
The cross section of the solid is two circular disks touching tangentially. The solid is swept out as the centroid of the area (where the circles touch) moves along a helical path and twists simultaneously. The parameter choices used in our example are
which places the centroid of the solid on the y-axis and makes the ends of the rope lie in the xz plane. Then the geometrical property contributions from both end surfaces are zero because η · R vanishes on the ends.
Let us next think about a solid with its surface composed of triangular patches. For a generic patch with corners at Ri, R j, R k , denote the surface area as ST and the unit surface normal as η. Then
If h is the normal distance from the origin to the plane containing the triangle, then h = η · Ri and ST = Ιη ST |. The first two volume properties are just
R = R( u, v), Ui < u < U2, Vi < v < V2.
a = 3, b = 1, m = 6, xo = yo = 0, zo = 3π/2
η St — -(Rj — Rt) x (Rk — Rt),
and t he t r i angl e cent r oi d i s at
Rc — ^ + Rk)·
z axis
TWISTED ROPE
-4
y axis
4
x axis
Figure 5.5: Solid Resembling a Twisted Rope
and
( V r ) t = J j j\f 1- R ) R d S = h- S T R c.
St
The r emai ni ng i ner t i al pr oper t y i nt egr al i s
( V r r ) t = \J J(■.u R ) R R' d S = ^ S T (Ri i?'+ i?fc R’k+9RC R'c ).
St
These formulas were used to develop the function srfv which computes geometrical properties for a surface described by the same type of data arrays as those used by the function surf. Each quadrilateral patch is divided into two triangles, and the contributions of all triangles are accumulated in vectorized mode for computational efficiency.
The function ropesymu in the following program calls function twistrope to per­
form numerical computation, function twistprop to perform symbolic computation, and function ropedraw to plot the geometry of the twisted rope. Twistrope calls the function srfv which is a general routine to compute properties of solid bodies mod­
eled with triangular surface elements. The numerical example employs point arrays of dimension 804 by 100 to obtain the numerical solution. Results for the numerical and symbolic computations are shown next along with the computer code. Note that the numerical and exact solutions agreed within 0.2 percent. The numerical solution took about 1.3 secs compared with 314 seconds for the symbolic solution. Even though the symbolic solution took 238 times as long to compute as the numerical so­
lution, the symbolic coding was simple and might be appealing in specific situations where the related integrals can be evaluated exactly.
5.6 Numerical and Symbolic Results for the Example
COMPARISON OF NUMERICAL AND SYMBOLIC GEOMETRICAL PROPERTIES FOR A TWISTED ROPE
FOR THE TRIANGULAR SURFACE PATCH MODEL Volume = 44.3239
Rg = [1.6932e-015 0.64979 3.0068e-015]
I r r =
548.6015 -0.0000 29.0040
-0.0000 548.6015 -0.0000
29.0040 -0.0000 423.7983
C o m p u t a t i o n T i m e = 1.3 1 9 4 S e c s.
FOR THE SYMBOLIC MODEL
Volume = 44.4132
Rg = [0 0.64982 0]
I r r =
549.7423 0 29.0639
0 549.7423 0
29.0639 0 424.7014
Computation Time = 314.2 8 Secs.
NUMERICAL APPROXIMATION ERROR USING TRIANGULAR SURFACE PATCHES. THE ERROR VALUES ARE DEFINED AS NORM(APPROX.-EXACT)/NORM(EXACT)
Volume E r r o r = 0.0020102
C e n t r o i d a l Radius E r r o r = 4.7287e-005
I n e r t i a Tensor E r r o r = 0.0020768
COMPARISON OF SOLUTION TIMES (Symbolic Time)/(Numerical Time) = 238.1992
Program ropesymu
f u n c t i o n [ v n,r c n,i r r n,v s,r c s,i r r s,t i m e s,n t,n p ] =...
ropesymu(A,B,M,X0,Y0,Z0,nt,np)
%
% [ v n,r c n,i r r n,v s,r c s,i r r s,t i m e s,n t,n p ] = r o p e s y m u (...
% A,B,M,X0,Y0,Z0,nt,np)
%.......................................................................................................................................
%
% This program computes g e o m e t r i c a l p r o p e r t i e s of a % t w i s t e d rope havi ng a c r o s s s e c t i o n which i s two % c i r c l e s of d i a met er B t o u c h i n g t a n g e n t i a l l y. The % t angency p o i n t i s a t d i s t a n c e A from t h e r o t a t i o n % a x i s z. As t h e a r e a i s r o t a t e d, i t i s a l s o t w i s t e d % i n a h e l i c a l f a s h i o n. For a complete r e v o l u t i o n % about t h e z a x i s, t h e a r e a i s t w i s t e d t hr ough m % t u r n s. The r e s u l t i n g s u r f a c e resemble s a rope % composed of two s t r a n d s. Two r e s u l t s a r e o b t a i n e d % 1) by a numeri cal method where t h e s u r f a c e i s % modeled wi t h t r i a n g u l a r s u r f a c e p a t c h e s and % 2) by symbolic math. See f u n c t i o n s t w i s t r o p e and % t w i s t p r o p f o r d e s c r i p t i o n s of t h e problem p ar amet er s.
21:
22:
23
24:
25:
26
27:
28:
29:
30:
31:
32:
33
34:
35:
36
37:
38:
39:
40:
41:
42
43
44
45
46
47:
48
49
50:
51:
52:
53
54:
55:
56
57:
58:
59:
60:
61:
62:
63:
64:
% Numerical r e s u l t s and computation t i me s f o r t h e two % methods a r e compared, and t h e r e l a t e d s u r f a c e % geometry i s p l o t t e d %
% User f u n c t i o n s c a l l e d: t w i s t r o p e t w i s t p r o p ropedraw %
------------------------------------------------------------------------------------------------
i f nargin==0 % D e f a u l t d a t a case A=3; B=1; m=6; np=201; nt=25;
X0=0; Y0=0; Z0=-3*pi/2; M=6; end
d i s p (' ')
d i s p (' COMPARISON OF NUMERICAL AND SYMBOLIC') disp('GEOMETRICAL PROPERTIES FOR A TWISTED ROPE')
% Run t h e f i r s t time t o g e t a crude g r i d f o r p l o t t i n g [ v n,r c n,i r r n,x,y,z,c ] = t w i s t r o p e ( A,B,M,X 0,Y 0,Z 0,n t,n p );
% Numerical s o l u t i o n u s i n g a dense p o i n t g r i d t o g e t % c l o s e comparison wi t h e x a c t r e s u l t s. C a l c u l a t i o n s % a r e run r e p e a t e d l y f o r a c c u r a t e t i m i n g.
Nt=4*nt; Np=4*np; n=50; t i c; f o r i = 1:n
[ v n,r c n,i r r n ] = t w i s t r o p e ( A,B,M,X 0,Y 0,Z 0,N t,N p );
end
t i mn = t o c/n;
% Perform t h e symbolic a n a l y s i s. This t a k e s a long
% t i me.
t i c;
[ v,r c,v r r,v s,r c s,i r r s ] = t w i s t p r o p ( A,B,M,X 0,Y 0,Z 0 ); t i m s = t o c; t i m e s = [ t i m n,t i m s ];
d i s p (' ')
disp('FOR THE TRIANGULAR SURFACE PATCH MODEL') di s p ( ['Vo l u me = ',n u m 2 s t r ( v n ) ] ) d i s p ( ['R g = [',n u m 2 s t r ( r c n (:)'),']'] ) d i s p ('I r r = '), d i s p ( i r r n )
d i s p ( ['C o m p u t a t i o n Time = ',n u m 2 s t r ( t i m n ),' S e c s.'] )
% P r i n t numeri cal comparisons of r e s u l t s d i s p (' ')
disp('FOR THE SYMBOLIC MODEL')
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
di s p ( ['Vo l u me = ',n u m 2 s t r ( v s ) ] ) d i s p ( ['R g = [',n u m 2 s t r ( r c s (:)'),']'] ) d i s p ('I r r = '), d i s p ( i r r s )
d i s p ( ['C o m p u t a t i o n Time = ',n u m 2 s t r ( t i m s ),' S e c s.'] ) d i s p (' ')
d i s p (' NUMERICAL APPROXIMATION ERROR USING TRIANGULAR') disp('SURFACE PATCHES. THE ERROR VALUES ARE DEFINED AS') d i s p (' NORM(APPROX.-EXACT)/NORM(EXACT)')
e v o l = a b s ( v n - v s )/v s; e r a d = n o r m ( r c s (:) - r c n (:) )/n o r m ( r c s ); e i n e r t = n o r m ( i r r n - i r r s )/n o r m ( i r r s ); d i s p ( ['Vo l u me E r r o r = ',n u m 2 s t r ( e v o l ) ] ) d i s p ( ['C e n t r o i d a l Radius E r r o r = ',n u m 2 s t r ( e r a d ) ] ) d i s p ( ['I n e r t i a Tensor E r r o r = ',n u m 2 s t r ( e i n e r t ) ] )
d i s p (' ')
disp('COMPARISON OF SOLUTION TIMES') d i s p ( ['( S y m b o l i c Time)/(Numerical Time) = ',...
n u m 2 s t r ( t i m s/t i m n ) ] ) d i s p (' ')
% D r a w t h e s u r f a c e u s i n g a c r u d e g r i d t o a v o i d % c r o w d e d g r i d l i n e s r o p e d r a w ( A,B,n p,n t,M,X 0,Y 0,Z 0 );
% = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
f u n c t i o n [ x,y,z,t ] = r o p e d r a w ( a,b,n p,n t,m,x 0,y 0,z 0 )
%
% [ x,y,z,t ] = r o p e d r a w ( a,b,n p,m p,m,x 0,y 0,z 0 )
%....................................................................................................
% T h i s f u n c t i o n d r a w s t h e t w i s t e d r o p e. i f n a r g i n = = 0
a = 3; b = 1; n p = 2 0 0; n t = 2 5; m = 6; x 0 = 0; y 0 = 0; z 0 = - 3 * p i/2; e n d
% D r a w t h e s u r f a c e
t = l i n s p a c e ( 0,2 * p i,n t ); p = l i n s p a c e ( 0,3 * p i,n p )'; t = r e p m a t ( t,n p,1 ); p = r e p m a t ( p,1,n t ); x i = b * c o s ( t ).* a b s ( c o s ( t ) ); e t a = b * s i n ( t ).* a b s ( c o s ( t ) ); r h o = a + x i.* c o s ( m * p ) + e t a.* s i n ( m * p ); x = r h o.* c o s ( p ) + x 0; y = r h o.* s i n ( p ) + y 0; z = - x i.* s i n ( m * p ) + e t a.* c o s ( m * p ) + p + z 0; c l o s e; s u r f ( x,y,z,t ), t i t l e ('T W I S T E D R O P E')
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
x l a b e l ('x a x i s'), y l a b e l ('y a x i s'), z l a b e l ('z a x i s') c o l o r m a p ('p r i s m ( 4 )'), a x i s e q u a l, hol d on
% F i l l t h e ends
f i l l 3 ( x ( 1,:),y ( 1,:),z ( 1,:),'w') f i l l 3 ( x ( e n d,:),y ( e n d,:),z ( e n d,:),'w') v i e w ( [ - 4 0,1 0 ] ), hol d o f f, shg
%===========================================
f u n c t i o n [ v,r c,v r r,V,R c,I r r ] = t w i s t p r o p ( A,B,M,X 0,Y 0,Z 0 ) %
% [ v,r c,v r r,V,R c,I r r ] = t w i s t p r o p ( A,B,M,X 0,Y 0,Z 0 )
%..................................................................................................................
% This f u n c t i o n computes g e o m e t r i c a l p r o p e r t i e s of % a t w i s t e d r o p e. Exact r e s u l t s a r e o b t a i n e d u s i n g % symbolic math t o e v a l u a t e t h r e e s u r f a c e i n t e g r a l s % f o r t h e volume, c e n t r o i d a l r a d i u s, and i n e r t i a % t e n s o r. The symbolic c a l c u l a t i o n s t a k e about f i v e % minutes t o run.
%
% A,B,N - p a r a met er s d e f i n i n g t h e t w i s t e d rope % X0,Y0,Z0 - c e n t e r c o o r d i n a t e s f o r t h e c e n t r o i d of % t h e t w i s t e d rope
% v,r c - symbolic for mul as f o r t h e volume and
% c e n t r o i d r a d i u s
% v r r - symbolic for mul a f o r i n t e g r a l of
% r * r'* d ( v o l )
% V,Rc - numeri cal v a l u e s f o r volume and
% c e n t r o i d r a d i u s
% I r r - numeri cal v al u e f o r t h e i n e r t i a t e n s o r
i f nargin==0
A=6; B=1; M=6; X0=1; Y0=2; Z0=3;
end
syms a b m t p x i e t a rho x y z r r t r p r e a l syms x0 y0 z0 r e a l
syms n dv dv1 v vr1 v r r g v r r 1 v r r r e a l a=sym(A); b=sym(B); P i = s y m ('p i'); x0=sym(X0); y0=sym(Y0); z0=sym(Z0);
% S u r f a c e e q u a t i o n f o r t h e t w i s t e d rope
x i = b * c o s ( t ) * a b s ( c o s ( t ) );
e t a = b * s i n ( t ) * a b s ( c o s ( t ) );
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
rho=a +xi *cos(m*p)+e t a*si n(m*p); x=rho*cos(p)+x0; y=rho*si n(p) +y0; z=-xi *sin(m*p)+eta*cos(m*p)+p+z0;
P i = s y m ('p i');
% Tangent v e c t o r s
r = [ x;y;z ]; r t = d i f f ( r,t ); r p = d i f f ( r,p );
% I n t e g r a t e t o g e t t h e volume d v = d e t ( [ r,r p,r t ] ); d v 1 = i n t ( d v,t,0,2 * P i ); v = s i m p l e ( i n t ( d v 1,p,0,3 * P i )/3 );
% F i r s t moment of volume v r 1 = i n t ( r * d v,t,0,2 * P i ); v r = s i m p l e ( i n t ( v r 1,p,0,3 * P i )/4 );
% Radius t o t h e c e n t r o i d r c = s i m p l e ( v r/v );
% I n t e g r a l of r * r'* d ( v o l )
v r r 1 = i n t ( r * r'* d v,t,0,2 * P i );
v r r = s i m p l e ( i n t ( v r r 1,p,0,3 * P i )/5 );
% Obt ai n numeri cal va l u e s V = d o u b l e ( s u b s ( v,{ a,b,m,x 0,y 0,z 0 },...
{A,B,M,X0,Y0,Z0}));
R c = d o u b l e ( s u b s ( r c,{ a,b,m,x 0,y 0,z 0 },...
{A,B,M,X0,Y0,Z0})); I r r = d o u b l e ( s u b s ( v r r,{ a,b,m,x 0,y 0,z 0 },... {A,B,M,X0,Y0,Z0}));
% R i g i d body i n e r t i a t e n s o r f o r a % body of u n i t mass d e n s i t y I r r = e y e ( 3,3 ) * s u m ( d i a g ( I r r ) ) - I r r;
%===========================================
f u n c t i o n [ v,r c,v r r,x,y,z,t ] = t w i s t r o p e (...
a,b,m,x 0,y 0,z 0,n t,n p )
%
% [ v,r c,v r r,x,y,z,t ] = t w i s t r o p e (...
% a,b,m,x 0,y 0,z 0,n t,n m )
%...............................................................................................
% Geometri cal p r o p e r t i e s of a t w i s t e d r ope.
% This example t a k e s 1.3 seconds t o run
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
i f nar gi n< 8, np=321; end; i f nar gi n<7, nt=161; end i f nargin==0
a=6; b=1; m=6; x0=1; y0=2; z0=3;
end
t = l i n s p a c e ( 0,2 * p i,n t ); p = l i n s p a c e ( 0,3 * p i,n p )'; t = r e p m a t ( t,n p,1 ); p = r e p m a t ( p,1,n t );
% S u r f a c e e q u a t i o n f o r t h e t w i s t e d rope
x i = b * c o s ( t ).* a b s ( c o s ( t ) ); e t a = b * s i n ( t ).* a b s ( c o s ( t ) ); r h o = a +xi.*c os( m*p) +et a.*s i n( m*p); x =r ho.*cos(p) +x0; y = r h o.* s i n ( p ) + y 0; z = - x i.* s i n ( m * p ) + e t a.* c o s ( m * p ) + p + z 0;
[ v,r c,v r r ] = s r f v ( x,y,z );
%===========================================
f u n c t i o n [ v,r c,v r r ] = s r f v ( x,y,z )
%
% [ v,r c,v r r ] = s r f v ( x,y,z )
%........................................................
%
% This f u n c t i o n computes t h e volume, c e n t r o i d a l % c o o r d i n a t e s, and i n e r t i a l t e n s o r f o r a volume % covered by s u r f a c e c o o r d i n a t e s c o n t a i n e d i n % a r r a y s x,y,z %
% x,y,z - m a t r i c e s c o n t a i n i n g t h e c o o r d i n a t e s % of a g r i d of p o i n t s c o ve r i ng t h e
% s u r f a c e of t h e s o l i d
% v - volume of t h e s o l i d
% r c - c e n t r o i d a l c o o r d i n a t e v e c t o r of t h e
% s o l i d
% v r r - i n e r t i a l t e n s o r f o r t h e s o l i d wi t h t h e
% mass d e n s i t y t a k e n as u n i t y
%
% User f u n c t i o n s c a l l e d: s c a t r i p l p r o p t e t %-------------------------------------------------------------------------------------------
% p = i n l i n e (...
% ,v * ( e y e ( 3 ) * ( r (:),,* r (:) ) - r (:) * r (:),,),,,v,,,r ’ );
% d = m e a n ( [ x (:),y (:),z (:) ] );
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
%x=x-d(1); y =y- d( 2); z = z - d ( 3 );
[ n,m ] = s i z e ( x ); i =1:n - 1
x i j = x ( i,j )
x I j = x ( I,j )
x I J = x ( I,J )
x i J = x ( i,J )
y i j =y( i,j )
y I j = y ( I,j )
y I J = y ( I,J )
y i J = y ( i,J )
I=i+1; j=1 z i j = z ( i,j ) z I j = z ( I,j ) z I J = z ( I,J ) z i J = z ( i,J )
m-1; J=j+1;
% Tet r a h e d r o n volumes
v 1 = s c a t r i p l ( x i j,y i j,z i j,x I j,y I j,z I j,x I J,y I J,z I J ); v 2 = s c a t r i p l ( x i j,y i j,z i j,x I J,y I J,z I J,x i J,y i J,z i J ); v=sum(sum(v1+v2));
% F i r s t moments of volume
X1=xi j +xIj +xI J Y1=yi j +yIj +yI J Z 1 = z i j + z I j + z I J vx=sum(sum(v1.*X1+v2.*X2)) vy=sum(sum(v1.*Y1+v2.*Y2)) vz=sum(sum(v1.*Z1+v2.*Z2))
X2=xi j +xIJ+xi J;
Y2=yi j +yIJ+yi J;
Z 2 = z i j + z I J + z i J;
% Second moments of volume v r r = p r o p t e t ( v 1,x i j,y i j,z i j,x I j,y I j,z I j,... x I J,y I J,z I J,X 1,Y 1,Z 1 ) +... p r o p t e t ( v 2,x i j,y i j,z i j,x I J,y I J,z I J,... x i J,y i J,z i J,X 2,Y 2,Z 2 ); r c = [ v x,v y,v z ]/v/4; v s = s i g n ( v ); v = a b s ( v )/6; v r r = v s * v r r/1 2 0;
v r r = [ v r r ( [ 1 4 5 ] ), v r r ( [ 4 2 6 ] ), v r r ( [ 5 6 3 ] ) ]'; v r r = e y e ( 3,3 ) * s u m ( d i a g ( v r r ) ) - v r r;
% v r r = v r r - p ( v,r c ) + p ( v,r c + d ); rc=rc+d;
%===========================================
f u n c t i o n v = s c a t r i p l ( a x,a y,a z,b x,b y,b z,c x,c y,c z )
%
% v = s c a t r i p l ( a x,a y,a z,b x,b y,b z,c x,c y,c z )
%...............................................................................................
% S c a l a r t r i p l e p r oduc t d o t ( c r o s s ( a,b ),c ) where % t h e c a r t e s i a n components of v e c t o r s a,b,a n d c % a r e gi ven i n a r r a y s of t h e same s i z e. v = a x.* ( b y.* c z - b z.* c y ) + a y.* ( b z.* c x - b x.* c z )... + a z.* ( b x.* c y - b y.* c x );
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
% =========================================
f u n c t i o n v r r = t e n s p r o d ( v,x,y,z )
%
% v r r = t e n s p r o d ( v,x,y,z )
%...................................................
% This f u n c t i o n forms t h e v a r i o u s components % of v*R*R'. The c a l c u l a t i o n i s v e c t o r i z e d % over a r r a y s of p o i n t s
vxx=sum(sum(v.*x.*x))
vzz=sum(sum(v.*z.*z))
vxz=sum(sum(v.*x.*z))
vyy=sum(sum(v.*y.*y))
vxy=sum(sum(v.*x.*y))
vyz=sum(sum(v.*y.*z))
v r r =[ v x x; vyy; vzz; vxy; vxz; vyz];
% =========================================
f u n c t i o n v r r = p r o p t e t ( v,x 1,y 1,z 1,x 2,y 2,z 2,...
x 3,y 3,z 3,x c,y c,z c )
%
% v r r = p r o p t e t ( v,x 1,y 1,z 1,x 2,y 2,z 2,x 3,y 3,z 3,...
% x c,y c,z c )
%...............................................................................................................
% This f u n c t i o n computes t e n s o r p r o p e r t i e s of a % t e t r a h e d r o n w i t h i t s bas e b e i n g a t r i a n g u l a r % s u r f a c e and i t s apex a t t h e o r i g i n v r r = t e n s p r o d ( v,x 1,y 1,z 1 ) + t e n s p r o d ( v,x 2,y 2,z 2 ) +.. t e n s p r o d ( v,x 3,y 3,z 3 ) + t e n s p r o d ( v,x c,y c,z c );
5.7 Geometrical Properties of a Polyhedron
A polyhedron is a solid covered by polygonal faces. Since polyhedra with suffi­
ciently many faces can approximate volumes of complex shape, computing the vol­
ume, centroidal position, and inertia tensor of a polyhedron has useful applications. A polyhedron can be treated as the combination of a number of pyramids with bases which are the polyhedron faces and apexes located at the coordinate origin. Once the geometrical properties of a pyramid are known, results for a polyhedron are found by combining results for all faces [111].
Consider a general volume V covered by surface S. It follows from the divergence theorem of Gauss [59] that
XnYmZe dX dY dZ = n + m1+e+3 Jj XnYmZ£( ή · R) dS
V S
w h e r e ή isthe outward directed surface normal and R isthe column vector [ X; Y; Z ].
This formula implies
V = JJJ d Xd Yd Z JJ ή RdS,
V S
VR = Jf fRdXdYdZ=\f f R{ f l.R) dS,
V S
and
V HR = JJJ R R d X d Y d Z = l- JJ R R ^ ■ R) dS
V S
w h e r e R means the transpose of R. Let us apply these formulas to a pyramid with the apex at R = 0 and the base being a planar region S b of area A. For points on the side of the pyramid of height h we find that ή · R = 0, and for points on the base ή · R = h. Consequently
v=\SShds=lA·
Sb
V r =\ J J m d s =\ j j RdS*
Sb Sb
V r r =IJJR R h d S = ^ JJ R R dS.
Sb Sb
T h e v o l u m e i s e q u a l t o o n e t h i r d o f t h e h e i g h t t i m e s t h e b a s e a r e a, r e g a r d l e s s o f t h e b a s e s h a p e. I f R b and R p signify the centroidal radii of the base and the pyramid volume, respectively, we get
_YR _\R bA _ 3 Rp V ~ _ 4
Therefore, the centroid of the volume lies | of the way along a line from the apex to the centroid of the base. For any planar area it is not hard to show that the area A and unit surface normal ή can be computed using the line integral
η Α =\) ψ R x dR.
2 J L
The last formula simplifies for a polygon having corners at R 1, R 2 ,■■■, R n to yield 1 n
i ) A = - Rj x -Rj+i where R n + 1 = i?i.
2 3=1
To compute the first and second area moments for a general planar area, it is helpful to introduce coordinates centered anywhere in the plane containing the base. We let
R = Ro + i x + j y
where R 0 is a vector to a point in the plane of the base, and i and j are orthonormal unit vectors which are tangent to the plane and are chosen such that I, j, ή form a right-handed system. The local coordinates (x, y) can be computed using
Then we get
x = (R — R 0) i and y = (R — R 0) j ■
V r = ^ j j (Ro + i x+j y) dxd,y
Sb
h
= ~^(Ro + 1 X + J y)A h
= - R bA
where (x, y) are the centroidal coordinates of the area measured relative to the local axes. Similarly we have
V rr = — i f [ RoR0 + (Roi + l R0)x + (-RoJ +J - Ro)y +
A+
Sb
(ij + j i )xy + i i x2 + j j y2\dxdy
R 0 R 0 + (R0 i + i R o) x + (R0j + j R o)y
i i A xx + JJ A yy + ( ^ j + J j )Axy
where
Axx = J J x dxdy , Axy = J J x y d x d y, Ayy = J J y dxdy■
Sb Sb Sb
The formula for V r r simplifies when R 0 is chosen as the centroidal radius R b. Then x = y = 0 so that
h , , , ,
V r r = - [RbR'bA + i i Abxx+ j j Ab +(ί j + j t )Ab }
with the quantities A bxx, A byy, Abcy denoting reference to the centroidal axes.
The analysis to compute polyhedron properties can now be completed using vec­
tor algebra along with area property calculations of the type introduced earlier. To
define data for a particular polyhedron we provide vectors x, y, z containing global coordinates of all corners. We also employ a matrix named i d f a c e having a row dimension equal to the number of faces on the polyhedron and a column dimension equal to the largest number of corners on any face. Row i of i d f a c e consists of corner indices of the i’th face with the row being padded with zeros on the right if necessary. Each face is traversed in the counterclockwise sense relative to the out­
ward normal. Consider a figure showing a triangular block with a hole, having twelve corners and eight faces as shown in
Figure 5.6. The required geometry descriptions are defined in example polhdrun. The results produced for this example are
>> p o l h d r u n; v = 15 r c =
0.0000
2.6667
1.3333
v r r =
5.0000
0.0000
0.0000
0.0000
120.8333
60.4167
0.0000
60.4167
40.8333
r =
161.6667
- 0.0 0 0 0
- 0.0 0 0 0
- 0.0 0 0 0
45.8333
- 6 0.4 1 6 7
- 0.0 0 0 0
- 6 0.4 1 6 7
125.8333
These values can be easily verified by manual calculations.
Surface Plot of a General Polyhedron
Figure 5.6: Surface Plot of a General Polyhedron
Program polhdrun
f u n c t i o n pol hdrun % Example: pol hdrun
%...........................................
%
% This program i l l u s t r a t e s t h e use of r o u t i n e % p o l hedr n t o c a l c u l a t e t h e g e o m e t r i c a l % p r o p e r t i e s of a pol yhedron.
%
% User m f u n c t i o n s c a l l e d:
% cr osmat, pol yxy, cubrange, pyramid,
% p o l h d p l t, po l h ed r n
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
i d f a c e =
[1
2
3
6
5
4
6
3
17
1
3
9
7
0
0
0
0
18
1
7
8
2
0
0
0
0
19
2
8
9
3
0
0
0
0
20
7
9
12
10
11
12
9
8;
21
4
10
12
6
0
0
0
0
22
4
5
11
10
0
0
0
0
23
5
6
12
11
0
0
0
0]
24
x
t(
l
p
d
h
l
o
p
,y,
z,i d f a c e,
[1,
1,1]
);
[ v,r c,v r r,i r r ] = p o l h e d r n ( x,y,z,i d f a c e )
%=
f u n c t i o n [ v,r c,v r r,i r r ] = p o l h e d r n ( x,y,z,i d f a c e ) %
% [ v,r c,v r r,i r r ] = p o l h e d r n ( x,y,z,i d f a c e )
%.....................................................................................
%
% This f u n c t i o n de t e r mi ne s t h e volume,
% c e n t r o i d a l c o o r d i n a t e s and i n e r t i a l moments % f o r an a r b i t r a r y pol yhedron.
%
% x,y,z - v e c t o r s c o n t a i n i n g t h e cor ner % i n d i c e s of t h e polyhedron
% i d f a c e - a m a t r i x i n which row j d e f i n e s t h e % co r n e r i n d i c e s of t h e j't h f a c e.
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
74
75
76
77
78
79
80
81
82
83
84
85
86
% Each f a c e i s t r a v e r s e d i n a
% cou n t e r c l o c k w i s e sens e r e l a t i v e t o
% t h e outward normal. The column
% dimension e q u a l s t h e l a r g e s t number
% of i n d i c e s needed t o d e f i n e a f a c e.
% Rows r e q u i r i n g fewer t h a n t h e
% maximum number of co r n e r i n d i c e s a r e
% padded wi t h z e r o s on t h e r i g h t.
%
% v - t h e volume of t h e polyhedron
% r c - t h e c e n t r o i d a l r a d i u s
% v r r - t h e i n t e g r a l of R*R'*d(vol)
% i r r - t h e i n e r t i a t e n s o r f o r a r i g i d body
% of u n i t mass o b t a i n e d from v r r as
% e y e ( 3,3 ) * s u m ( d i a g ( v r r ) ) - v r r
%
% User m f u n c t i o n s c a l l e d: pyramid %-----------------------------------------------------------------------------------------
r = [ x (:),y (:),z (:) ]; n f = s i z e ( i d f a c e,1 ); v=0; vr=0; vrr =0; f o r k=1:nf
i = i d f a c e ( k,:); i = i ( f i n d ( i > 0 ) ); [ u,u r,u r r ] = p y r a m i d ( r ( i,:) ); v=v+u; vr=vr +ur; v r r = v r r + u r r; end
r c = v r/v; i r r = e y e ( 3,3 ) * s u m ( d i a g ( v r r ) ) - v r r; %=============================================
f u n c t i o n [ a r e a,x b a r,y b a r,a x x,a x y,a y y ] = p o l y x y ( x,y ) %
% [ a r e a,x b a r,y b a r,a x x,a x y,a y y ] = p o l y x y ( x,y )
%.......................................................................................................
%
% This f u n c t i o n computes t h e a r e a, c e n t r o i d a l % c o o r d i n a t e s, and i n e r t i a l moments of an % a r b i t r a r y polygon.
%
% x,y - v e c t o r s c o n t a i n i n g t h e co r n e r
% c o o r d i n a t e s. The boundary i s
% t r a v e r s e d i n a cou n t e r c l o c k w i s e
% d i r e c t i o n
%
% a r e a - t h e polygon a r e a
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
% x b a r,y b a r - t h e c e n t r o i d a l c o o r d i n a t e s
% axx - i n t e g r a l of x~2*dxdy
% axy - i n t e g r a l of xy*dxdy
% ayy - i n t e g r a l of y~2*dxdy
%
% User m f u n c t i o n s c a l l e d: none %-----------------------------------------------------------------------------------------
n = 1:l e n g t h ( x ); n1=n+1; x = [ x (:);x ( 1 ) ]; y = [ y (:);y ( 1 ) ]; a = ( x ( n ).* y ( n 1 ) - y ( n ).* x ( n 1 ) ) ar ea=s um( a )/2; a6=6*area;
x b a r = a * ( x ( n ) + x ( n 1 ) )/a 6; y b a r = a * ( y ( n ) + y ( n 1 ) )/a 6; a y y = a * ( y ( n ).~ 2 + y ( n ).* y ( n 1 ) + y ( n 1 ).~ 2 )/1 2; a x y = a * ( x ( n ).* ( 2 * y ( n ) + y ( n 1 ) ) + x ( n 1 ).* ...
( 2 * y ( n 1 ) + y ( n ) ) )/2 4;
a x x = a * ( x ( n ).~ 2 + x ( n ).* x ( n 1 ) + x ( n 1 ).~ 2 )/1 2;
%=============================================
f u n c t i o n [ v,v r,v r r,h,a r e a,n ] = p y r a m i d ( r )
%
% [ v,v r,v r r,h,a r e a,n ] = p y r a m i d ( r )
%.............................................................................
%
% This f u n c t i o n de t e r mi ne s g e o m e t r i c a l % p r o p e r t i e s of a pyramid wi t h t h e apex a t t h e % o r i g i n and co r n e r c o o r d i n a t e s of t h e base % s t o r e d i n t h e rows of r.
%
% r - m a t r i x c o n t a i n i n g t h e co r n e r
% c o o r d i n a t e s of a pol ygonal base s t o r e d
% i n t h e rows of m a t r i x r.
%
% v - t h e volume of t h e pyramid
% v r - t h e f i r s t moment of volume r e l a t i v e t o
% t h e o r i g i n
% v r r - t h e second moment of volume r e l a t i v e % t o t h e o r i g i n
% h - t h e pyramid h e i g h t
% a r e a - t h e base a r e a
% n - t h e outward d i r e c t e d u n i t normal t o
% t h e base
%
% User m f u n c t i o n s c a l l e d: crosmat, polyxy
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
%
n s = s i z e ( r,1 );
n a = s u m ( c r o s m a t ( r,r ( [ 2:n s,1 ],:) ) )'/2; area=norm(na); n = n a/a r e a; p = n u l l ( n'); i = p (:,1 ); j = p (:,2 ); i f d e t ( [ p,n ] ) < 0, j = - j; end; r 1 = r ( 1,:); r r = r - r 1 ( o n e s ( n s,1 ),:); x = r r * i; y = r r * j;
[ a r e a t,x c,y c,a x x,a x y,a y y ] = p o l y x y ( x,y ); r c = r 1'+ x c * i + y c * j; h=r1*n; v=h*ar ea/3; vr=v*3/4*rc; axx=axx-area*xc~2; ayy=ayy-area*yc~2; axy=axy-area*xc*yc;
v r r = h/5 * ( a r e a * r c * r c ’+ a x x * i * i ’+ a y y * j * j'+ ... a x y * ( i * j'+ j * i') );
%==========================================
f u n c t i o n p o l h d p l t ( x,y,z,i d f a c e,c o l r )
%
% p o l h d p l t ( x,y,z,i d f a c e,c o l r )
%.....................................................................
%
% This f u n c t i o n makes a s u r f a c e p l o t of an % a r b i t r a r y pol yhedron.
%
% x,y,z - v e c t o r s c o n t a i n i n g t h e cor ner % i n d i c e s of t h e polyhedron
% i d f a c e - a m a t r i x i n which row j d e f i n e s t h e
% co r n e r i n d i c e s of t h e j't h f a c e.
% Each f a c e i s t r a v e r s e d i n a
% cou n t e r c l o c k w i s e sens e r e l a t i v e t o
% t h e outward normal. The column
% dimension e q u a l s t h e l a r g e s t number
% of i n d i c e s needed t o d e f i n e a f a c e.
% Rows r e q u i r i n g fewer t h a n t h e
% maximum number of co r n e r i n d i c e s a r e
% padded wi t h z e r o s on t h e r i g h t.
% c o l r - c h a r a c t e r s t r i n g or a v e c t o r % d e f i n i n g t h e s u r f a c e c o l o r
%
% User m f u n c t i o n s c a l l e d: cubrange %-----------------------------------------------------------------------------------------
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
i f nar gi n< 5, c o l r = [ 1 0 1]; end hol d o f f, c l o s e; n f = s i z e ( i d f a c e,1 ); v = c u b r a n g e ( [ x (:),y (:),z (:) ] ,1.l ); f o r k=1:nf
i = i d f a c e ( k,:); i = i ( f i n d ( i > 0 ) ); x i = x ( i ); y i = y ( i ); z i = z ( i ); f i l l 3 ( x i,y i,z i,c o l r ); hol d on; end
a x i s ( v ); g r i d on;
x l a b e l ('x a x i s'); y l a b e l ('y a x i s'); z l a b e l ('z a x i s');
t i t l e ('S u r f a c e P l o t of a General P o l y h e d r o n'); f i g u r e ( g c f ); hol d o f f;
%=============================================
f u n c t i o n c = c r os ma t ( a,b)
%
% c=c r os ma t ( a,b)
%% ~~~~~~~~~~~~~~
% This f u n c t i o n computes t h e v e c t o r c r o s s % p r oduc t f o r v e c t o r s s t o r e d i n t h e rows % of m a t r i c e s a and b, and r e t u r n s t h e % r e s u l t s i n t h e rows of c.
%
% User m f u n c t i o n s c a l l e d: none %
------------------------------------------------------------------------------------
c = [ a (:,2 ).* b (:,3 ) - a (:,3 ).* b (:,2 ),...
a (:,3 ).* b (:,1 ) - a (:,1 ).* b (:,3 ),...
a (:,1 ).* b (:,2 ) - a (:,2 ).* b (:,1 ) ];
%=============================================
% f u n c t i o n r a n g e = c u b r a n g e ( x y z,o v r s i z )
% See Appendix B
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:
b b b
h = l-H£Ldx , I2 = iJkLdr , f {x)
J yjx — a J yb — x J (x — a)(b — x)
a a a
The singularities in these integrals can be removed using substitutions x — a =
t2, b — x = t 2, and (x — a)(b — x) = (b + a )/2 + ( b — a)/2 cos(t) which lead to
I 1 = 2 j f (a + t 2) dt , I 2 = 2 j f (b — t 2) dt
0 0
π
/
, b + a b — a , , ,
+ ~ Y ~ cos(t))dt.
0
These modified 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) = eux 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 13. When f (x) is a polynomial, then taking parameter norder in function quadgsqrt equal to the polynomial order gives exact results. With norder taken sufficiently 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 fifteen 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 modified to accommodate a form of f (x) which returns a vector.
5.8.1 Program Listing Singular Integral Program
i: f u n c t i o n [ v g,t g,v L,t L,p c t d i f f ] = s q r t q u a d t e s t
2:
3:
4:
5:
6:
7:
8:
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
35
36
37
38
39
40:
41:
42
43
44
45
46
[ v g,t g,v L,t L,p c t d i f f ] = s q r t q u a d t e s t
This f u n c t i o n compares t h e ac curacy and computation ti me f o r f u n c t i o n s quadgs qr t and q u a d l s q r t t o e v a l u a t e:
i n t e g r a l ( e x p ( u * x ) * c o s ( v * x )/r a d i c a l ( x ), a<x<b) where r a d i c a l ( x ) i s s q r t ( x - a ), s q r t ( b - x ), or s q r t ( ( x - a ) * ( b - x ) )
Program Output >> s q r t q u a d t e s t;
EVALUATING INTEGRALS WITH SQUARE ROOT TYPE SINGULARITIES AT THE END POINTS
Funct i on i n t e g r a t e d: f t e s t ( x,u,v ) = e x p ( u * x ).* c o s ( v * x )
a = 1 b = 4
u = 3 v = 10
R e s u l t s from f u n c t i o n gquads qr t
4.836504484e+003 -8.060993912e+003 -4.264510048e+003 Computation ti me = 0.0159 s e c.
R e s u l t s from f u n c t i o n q u a d l s q r t
4.836504484e+003 -8.060993912e+003 -4.264510048e+003 Computation ti me = 7.0 3 s ec.
P e r c e n t d i f f e r e n c e f o r t h e two methods - 3.6669e-012 -1.5344e-012 1.4929e-012 >>
% The t e s t f u n c t i o n
f t e s t = i n l i n e ('e x p ( u * x ).* c o s ( v * x )','x','u','v');
% Li mi t s and f u n c t i o n p a r a met er s a=1; b=4; u=3; v=10;
nloop=100; t i c;
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
f o r j = 1:n l o o p
v 1 g = q u a d g s q r t ( f t e s t,1,a,b,4 0,1,u,v );
v 2 g = q u a d g s q r t ( f t e s t,2,a,b,4 0,1,u,v );
v 3 g = q u a d g s q r t ( f t e s t,3,a,b,4 0,1,u,v );
end
vg=[v1g,v2g,v3g]; t g = t o c/n l o o p; d i s p (' ')
disp('EVALUATING INTEGRALS WITH SQUARE ROOT TYPE') d i s p (' SINGULARITIES AT THE END POINTS') d i s p (' ')
d i s p ('F u n c t i o n i n t e g r a t e d:') d i s p ('f t e s t ( x,u,v ) = e x p ( u * x ).* c o s ( v * x )') d i s p (' ')
d i s p ( ['a = ',n u m 2 s t r ( a ),' b = ',n u m 2 s t r ( b ) ] )
d i s p ( ['u = ',n u m 2 s t r ( u ),' v = ',n u m 2 s t r ( v ) ] )
d i s p (' ')
d i s p ('R e s u l t s from f u n c t i o n g q u a d s q r t') f p r i n t f ('% 1 7.9 e %17.9e %1 7.9 e\n',v g ) d i s p ( ['C o m p u t a t i o n time = ',n u m 2 s t r ( t g ),' s e c.'] )
t o l = 1 e - 1 2; t i c;
v 1 L = q u a d l s q r t ( f t e s t,1,a,b,t o l,[ ],u,v ); v 2 L = q u a d l s q r t ( f t e s t,2,a,b,t o l,[ ],u,v ); v 3 L = q u a d l s q r t ( f t e s t,3,a,b,t o l,[ ],u,v ); vL=[v1L,v2L,v3L]; t L=t oc;
d i s p (' ')
d i s p ('R e s u l t s from f u n c t i o n q u a d l s q r t') f p r i n t f ('% 1 7.9 e %17.9e %17.9e\n',vL) d i s p ( ['C o m p u t a t i o n time = ',n u m 2 s t r ( t L ),' s e c.'] )
p c t d i f f = 1 0 0 * ( v g - v L )./v L; d i s p (' ') d i s p ('P e r c e n t d i f f e r e n c e f o r t h e two met hods') f p r i n t f ('% 1 3.4 e %12.4e % 1 2.4 e\n',p c t d i f f )
%=========================================
f u n c t i o n v = q u a d g s q r t (...
f u n c,t y p e,a,b,n o r d e r,n s e g s,v a r a r g i n )
%
% v = q u a d g s q r t ( f u n c,t y p e,a,b,n o r d e r,n s e g s,v a r a r g i n ) %
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
%
% This f u n c t i o n e v a l u a t e s an i n t e g r a l havi ng a
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
% s quar e r o o t t y p e s i n g u l a r i t y a t one or bot h ends % of t h e i n t e g r a t i o n i n t e r v a l a<x<b. Composite % Gauss i n t e g r a t i o n i s used wi t h f u nc ( x) t r e a t e d % as a polynomial of degr ee n o r d e r.
% The i n t e g r a n d has t h e form:
% f u n c ( x )/s q r t ( x - a ) i f type==1.
% f u n c ( x )/s q r t ( b - x ) i f type==2.
% f u n c ( x )/s q r t ( ( x - a ) * ( b - x ) ) i f type==3.
% The i n t e g r a t i o n i n t e r v a l i s s u b d i v i d e d i n t o % nsegs s u b i n t e r v a l s of equal l e n g t h.
%
% func - a c h a r a c t e r s t r i n g or f u n c t i o n handl e % naming a f u n c t i o n cont i nuous i n t h e
% i n t e r v a l from x=a t o x=b
% t ype - 1 i f t h e i n t e g r a n d i s s i n g u l a r a t x=a
% 2 i f t h e i n t e g r a n d i s s i n g u l a r a t x=b
% 3 i f t h e i n t e g r a n d i s s i n g u l a r a t bot h
% x=a and x=b.
% a,b - i n t e g r a t i o n l i m i t s wi t h b>a % no r d e r - polynomial i n t e r p o l a t i o n o r d e r w i t h i n % each i n t e r v a l. Lowest n o r d e r i s 20.
% nsegs - number of i n t e g r a t i o n s u b i n t e r v a l s %
% User m f u n c t i o n s c a l l e d: gcquad %
% Reference: Abromowitz and Stegun, 'Handbook of % Mathematical F u n c t i o n s', Chapter 25
% -----------------------------------------------------------------------------------
i f nar gi n< 6, nsegs=1; end; i f nar gi n< 5, norder=50; end s w i t c h t ype
case 1 % S i n g u l a r i t y a t t h e l e f t end.
% Use Gauss q u a d r a t u r e [dumy,bp,wf ]=gcquad(...
'',0,s q r t ( b - a ),n o r d e r + 1,n s e g s ); t =a+bp.~2; y = f e v a l ( f u n c,t,v a r a r g i n {:} ); v = w f (:)'* y (:) * 2; case 2 % S i n g u l a r i t y a t t h e r i g h t end.
% Use Gauss q u a d r a t u r e [dumy,bp,wf ]=gcquad(...
'',0,s q r t ( b - a ),n o r d e r + 1,n s e g s ); t = b - b p.~ 2; y = f e v a l ( f u n c,t,v a r a r g i n {:} ); v = w f (:)'* y (:) * 2; case 3 % S i n g u l a r i t y a t bot h ends.
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
% Use Chebyshev i n t e g r a t i o n n=norder; b p = c o s ( p i/( 2 * n + 2 ) * ( 1:2:2 * n + 1 ) ); c1=( b+a)/2; c 2 = ( b - a )/2; t=c1+c2*bp; y = f e v a l ( f u n c,t,v a r a r g i n {:} ); v=pi/(n+1)*sum(y);
end
%=========================================
f u n c t i o n v = q u a d l s q r t ( f n a m e,t y p e,a,b,t o l,t r a c e,v a r a r g i n ) %
% v = q u a d l s q r t ( f n a m e,t y p e,a,b,t o l,t r a c e,v a r a r g i n )
%....................................................................................................................
%
% This f u n c t i o n us es t h e MATLAB i n t e g r a t o r quadl % t o e v a l u a t e i n t e g r a l s havi ng s quar e r o o t t ype % s i n g u l a r i t i e s a t one or bot h ends of t h e % i n t e g r a t i o n i n t e r v a l a < x < b.
% The i n t e g r a n d has t h e form:
% f u n c ( x )/s q r t ( x - a ) i f type==1.
% f u n c ( x )/s q r t ( b - x ) i f type==2.
% f u n c ( x )/s q r t ( ( x - a ) * ( b - x ) ) i f type==3.
%
% func - t h e ha ndl e f o r a f u n c t i o n cont i nuous % from x=a t o x=b
% t ype - 1 i f t h e i n t e g r a n d i s s i n g u l a r a t x=a
% 2 i f t h e i n t e g r a n d i s s i n g u l a r a t x=b
% 3 i f t h e i n t e g r a n d i s s i n g u l a r a t bot h
% x=a and x=b.
% a,b - i n t e g r a t i o n l i m i t s wi t h b > a
i f nargin<6 | i s e m p t y ( t r a c e ), t r a c e = 0; end i f nargin<5 | i s e m p t y ( t o l ), t o l = 1 e - 8; end i f nargin<7
var a r g i n { 1 } = t y p e; v a r a r g i n { 2 } = [ a,b ]; varargin{3}=fname; e l s e
n = l e n g t h ( v a r a r g i n ); c = [ a,b ]; var argi n{n+1} =type; varargi n{n+2}=c; varargin{n+3}=fname; end
i f type==1 | type==2
v = 2 * q u a d l ( @ f s h i f t,0,s q r t ( b - a ),...
t o l,t r a c e,v a r a r g i n {:} );
e l s e
1 8 2: v = q u a d l ( @ f s h i f t,0,p i,t o l, t r a c e,v a r a r g i n {:} );
1 8 3: end
1 8 4:
1 8 5: %=========================================
1 8 6:
1 8 7: f u n c t i o n u = f s h i f t ( x,v a r a r g i n )
1 8 8: % u = f s h i f t ( x,v a r a r g i n )
1 8 9: % T h i s f u n c t i o n s h i f t s a r g u me n t s t o p r o d u c e 190: % a n o n s i n g u l a r i n t e g r a n d c a l l e d by q u a d l 191: N = l e n g t h ( v a r a r g i n ); f n a me = v a r a r g i n { N};
1 9 2: c = v a r a r g i n { N - 1 }; t y p e = v a r a r g i n { N - 2 };
1 9 3: a = c ( 1 ); b = c ( 2 ); c 1 = ( b + a )/2; c 2 = ( b - a )/2;
1 9 4:
1 9 5: s w i t c h t y p e
1 9 6: c a s e 1, t = a + x.~ 2; c a s e 2, t = b - x.~ 2;
1 9 7: c a s e 3, t = c 1 + c 2 * c o s ( x );
1 9 8: end
1 9 9:
2 0 0: i f N>3, u = f e v a l ( f n a m e,t,v a r a r g i n { 1:N - 3 } );
2 0 1: e l s e, u = f e v a l ( f n a m e,t ); end
2 0 2:
2 0 3: %=========================================
2 0 4:
2 0 5: % f u n c t i o n [ v a l,b p,w f ] = g c q u a d ( f u n c,x l o w,...
2 0 6: % x h i g h,n q u a d,m p a r t s,v a r a r g i n )
2 0 7: % See Appe ndi x B
5.9 Gauss Integration of a Multiple Integral
Gauss integration can be used to evaluate multiple integrals having variable limits. Consider the instance typified by the following triple integral
/■c 2 /■ b2 (z) i- a2 (y,z)
I = / F (x,y,z ) dxdydz.
Jc i J bi(z) Ja i(y,z)
This integral can be changed into one with constant limits by the substitutions
z = cp + cm u , —1 < u < 1,
y = bp + bmt , —1 < t < 1,
x = ap + am s , — 1 < s < 1
where
cp =
C2 + Cl 2 ’
cm —
C2 - Cl 2 ’
p
b
b2 + bl 2 ’
bm
52 - h 2 ’
a2 + al
a2 — a1
ap =
2
, am —
2
The above integral becomes
,■ 1 ,■ 1
where
I j j j cmbmamf ^, u) ds dt du
f (s,t,u) F (ap + am S, bp + bmt, Cp + cmu),
am = am{yi z) = am(bp + bmt, cp + cmu), bm = bm(z) = bm(cp + cmu ).
Thus, the integral has the form
I = / G(s,t,u) dsdt du
J - 1 J - 1 J-1
where
G cmbmam f.
Performing the integration over each limit using an n-point quadrature formula with weight factors wt and base points x % yields
n n n
I = WkwJwlG(xl, Xj, Xk ).
k=1j=1i=1
A function allowing an integrand and integration limits of general form was devel­
oped. An example is considered where the inertial moment of a sphere having unit radius, unit mass density, and centered at ( 0,0,0) is to be obtained about an axis through x = 2,y = 0, parallel to the z-axis. The related integral
/■ 1 /V l - z 2 l - y 2- z 2
1 = 1 1 I \{x — 2)2 + y 2\ dx dy dz
J - 1 J - ^/I ^ z 2 J - y/l - y 2- z 2
has a value of 88π/15. Shown below is a function quadi t 3d and related limit and integrand functions. The function t ri pl int (n) computes the ratio of the numerically integrated function to the exact result. The function specification t ri pl int(20) yields a value of 1.000067. Even though the triple integration procedure is not computa­
tionally very fast, it is nevertheless robust enough to produce accurate results when a sufficiently high integration order is chosen.
5.9.1 Example: Evaluating a Multiple Integral Triple Integration Program
f u n c t i o n v a l = t r i p l i n t ( n )
%
% v a l = t r i p l i n t ( n )
% T r i p l e i n t e g r a t i o n exampl e on i n e r t i a l % moment o f a s p h e r e.
%
% Us e r m f u n c t i o n s c a l l e d: f s p h e r e, b s l, b s 2,
% a s l, a s 2
i f n a r g i n = = 0, n=20; end
v a l = q u a d i t 3 d ('f s p h e r e',[ - 1,1 ],'b s l','b s 2',... 'a s 1','a s 2',n )/( 8 8 * p i/1 5 );
%=============================================
f u n c t i o n s = q u a d i t 3 d ( f,c,b 1,b 2,a 1,a 2,w )
%
% s = q u a d i t 3 d ( f,c,b 1,b 2,a 1,a 2,w )
%...............................................................................
% T h i s f u n c t i o n comput es t h e i t e r a t e d i n t e g r a l %
% s = i n t e g r a l (...
% f ( x,y,z ), x = a 1..a 2, y = b 1..b 2, z = c 1..c 2 )
%
% wher e a1 and a2 a r e f u n c t i o n s o f y and z, b1 % and b2 a r e f u n c t i o n s o f z, and c i s a v e c t o r % c o n t a i n i n g c o n s t a n t l i m i t s on t h e z v a r i a b l e. % Hence, a s many a s f i v e e x t e r n a l f u n c t i o n s may % be i n v o l v e d i n t h e c a l l l i s t. For e x a mpl e,
% when t h e i n t e g r a n d and l i m i t s a r e:
%
% f = x.~2+y~2+z~2 % a2 = s q r t ( 4 - y ~ 2 - z ~ 2 )
% a1 = - a 2 % b2 = s q r t ( 4 - z ~ 2 )
% b1 = - b 2 % c = [ - 2,2 ]
%
% Then t h e e x a c t v a l u e i s 1 2 8 * p i/5.
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:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
% The appr oximati on produced from a 20 p o i n t
% Gauss for mul a i s a c c u r a t e w i t h i n .007 p e r c e n t.
%
% f - a f u n c t i o n f ( x,y,z ) which must r e t u r n
% a v e c t o r v a l u e when x i s a v e c t o r,
% and y and z a r e s c a l a r.
% a1,a 2 - i n t e g r a t i o n l i m i t s on t h e x v a r i a b l e % which may s p e c i f y names of f u n c t i o n s
% or have c o n s t a n t v a l u e s. I f a1 i s a
% f u n c t i o n i t s houl d have a c a l l l i s t
% of t h e form a 1 ( y,z ). A s i m i l a r form
% a p p l i e s t o a2.
% b1,b2 - i n t e g r a t i o n l i m i t s on t h e y v a r i a b l e % which may s p e c i f y f u n c t i o n s of z or
% have c o n s t a n t v a l u e s.
% c - a v e c t o r d e f i n e d by c=[ c1,c2] where
% c1 and c2 a r e f i x e d i n t e g r a t i o n
% l i m i t s f o r t h e z d i r e c t i o n.
% w - t h i s argument d e f i n e s t h e q u a d r a t u r e
% for mul a used. I t has t h e f o l l o w i n g
% t h r e e p o s s i b l e forms. I f w i s o m i t t e d,
% a Gauss for mul a of o r d e r 12 i s used.
% I f w i s a p o s i t i v e i n t e g e r n, a Gauss
% for mul a of o r d e r n i s used. I f w i s an
% n by 2 m a t r i x, w (:,1 ) c o n t a i n s t h e base
% p o i n t s and w (:,2 ) c o n t a i n s t h e weight
% f a c t o r s f o r a q u a d r a t u r e for mul a over
% l i m i t s -1 t o 1.
%
% s - t h e n u m e r i c a l l y e v a l u a t e d i n t e g r a l
%
% User m f u n c t i o n s c a l l e d: gcquad
%---------------------------------------------------------------------------
i f nargin<7
% f u n c t i o n gcquad g e n e r a t e s base p o i n t s % and weight f a c t o r s
n=12; [ d u m m y,x,W] = g c q u a d ('',- 1,1,n,1 ); e l s e i f s i ze( w,1) ==1 & s i ze( w,2) ==1 n=w; [ d u m m y,x,W] = g c q u a d ('',- 1,1,n,1 ); e l s e
n = s i z e ( w,1 ); x = w (:,1 ); W=w(:,2); end
s=0; c p = ( c ( 1 ) + c ( 2 ) )/2; c m = ( c ( 2 ) - c ( 1 ) )/2;
86
87
88
89
90
91
92
93
94
95
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
f o r k=1:n
zk=cp+cm*x(k);
i f i s c h a r ( b l ), B 1 = f e v a l ( b 1,z k ); e l s e, B1=b1; end
i f i s c h a r ( b 2 ), B 2 = f e v a l ( b 2,z k ); e l s e, B2=b2; end
Bp=(B2+B1)/2; Bm=(B2-B1)/2; sj =0;
f o r j = 1:n
yj=Bp+Bm*x(j);
i f i s c h a r ( a 1 ), A 1 = f e v a l ( a 1,y j,z k ); e l s e, A1=a1; end
i f i s c h a r ( a 2 ), A 2 = f e v a l ( a 2,y j,z k ); e l s e, A2=a2; end
Ap=(A2+A1)/2; Am=(A2-A1)/2; f v a l = f e v a l ( f, Ap+Am*x, y j, z k ); s i = f v a l (:).'* W (:); sj=sj+W(j)*Am*si; end
s=s+W(k)*Bm*sj;
end
s=cm*s;
%=======================================
f u n c t i o n v = f s p h e r e ( x,y,z )
%
% v = f s p h e r e ( x,y,z )
%........................................
% I n t e g r a n d.
%---------------------------------------------------------------------------
v=( x- 2).~2+y.~2;
%=======================================
f u n c t i o n x = a s 1 ( y,z )
%
% x=a s 1 ( y,z )
% Lower x i n t e g r a t i o n l i m i t.
%---------------------------------------------------------------------------
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
x = - s q r t ( 1 - y.~ 2 - z.~ 2 );
%=============================================
f u n c t i o n x = a s 2 ( y,z )
%
% x=a s 2 ( y,z )
% Upper x i n t e g r a t i o n l i m i t.
%-----------------------------------------------------------------------------------------
x = s q r t ( 1 - y.~ 2 - z.~ 2 );
%=============================================
f u n c t i o n y=bs1(z)
%
% y=bs1(z)
% Lower y i n t e g r a t i o n l i m i t.
%-----------------------------------------------------------------------------------------
y = - s q r t ( 1 - z.~ 2 );
%=============================================
f u n c t i o n y=bs2(z)
%
% y=bs2(z)
% Upper y i n t e g r a t i o n l i m i t.
%-----------------------------------------------------------------------------------------
y = s q r t ( 1 - z.~ 2 );
%=============================================
% f u n c t i o n [ v a l,b p,w f ] = g c q u a d ( f u n c,x l o w,...
% x h i g h,n q u a d,m p a r t s,v a r a r g i n )
% See Appendix B
Chapiter 6
Fourier Series and the Fast Fourier Transform
6.1 Definitions and Computation of Fourier Coefficients
Trigonometric series are useful to represent periodic functions. A function defined for — t o < x < t o has a period of 2π if f (x + 2π) = f (x) for all x. In most practical situations, such a function can be expressed as a complex Fourier series
tt
f(x) = ^ c0el°x where i = V - ϊ -
3=- ^
The numbers c3, called complex Fourier coefficients, are computed by integration as
1 Γ2π
c3 = — f ( x) e lJxdx.
2π J
0
The Fourier series can also be rewritten using sines and cosines as
tt
f (x) = co + ^j ( c3 + c- 3 ) cos(jx) + i(c3 — c- 3 ) sin(jx).
3 = 1
Denoting
yields
c3 + c-3 md b3 = l(c3 — c-3)
1 tt
f ( x) = - a 0 +
Σ a3 cos(jx)
+ b3
sin(jx)
2 3=1
which is called a Fourier sine-cosine expansion. This series is especially appealing when f ( x) is real valued. For that case c_j = c0 for all j, which implies that co must be real and
a3 = 2 real(c3) , b3 = —2 imag(c3) for j > 0.
Suppose we want a Fourier series expansion for a more general function f ( x) having period p instead of 2π. If we introduce a new function g(x) defined by
.(*> = /( £ )
a
then g(x) has a period of 2π. Consequently, g(x) can be represented as
OO
g(x) = Σ c3e13x.
3=-tt
Fromthe fact that f (x) = g(2nx/p) we deduce that
tt
f (x) = Σ c.3e2m3xlv·
3=-tt
A need sometimes occurs to expand a function as a series of sine terms only, or as a series of cosine terms only. If the function is originally defined for 0 < x < |, then making f ( x) = —f ( p — x) for | < x < p gives a series involving only sine terms. Similarly, if f ( x) = +f ( p — x) for | < x < p, only cosine terms arise. Thus we get
tt
f (x) = co + Σ ^ 3 + c - 3 ) cos(2Tijx/p) if f (x) = f (p — x),
3=1
or
f (x) = Σ i(c3 — c - 3 ) sin(2 Tijx/p) if f (x) = —f (p — x).
3 = 1
When the Fourier series of a function is approximated using a finite number of terms, the resulting approximating function may oscillate in regions where the actual func­
tion is discontinuous or changes rapidly. This undesirable behavior can be reduced by using a smoothing procedure described by Lanczos [60]. Use is made of Fourier series of a closely related function f ( x) defined by a local averaging process accord­
ing to
„ 1 rx+%
f(x) = x /( C R A J x - f
where the averaging interval Δ should be a small fraction of the period p. Hence we write Δ = ap with a < 1. The functions f ( x) and f (x) are identical as a ^ 0. Even for a > 0, these functions also match exactly at any point x where f (x) varies linearly between x — y and x + γ. An important property of f ( x) is that it agrees closely with f (x) for small a but has a Fourier series which converges more rapidly than the series for f (x). Furthermore, from its definition,
Λ 0 0 1 /-Χ+Ψ 00
/(s) = Σ C3 ~ e2^%3x^p dx = c3e2^l3xlp
j x - ^ -
where c 0 = c0 and c3 = c3 si n(nja)/(nj a) for j = 0. Evidently the Fourier coef­
ficients of f (x) are easily obtainable from those of f (x). When the series for f (x) converges slowly, using the same number of terms in the series for f (x) often gives an approximation preferable to that provided by the series for f (x). This process is called smoothing.
6.1.1 Trigonometric Interpolation and the Fast Fourier Transform
Computing Fourier coefficients by numerical integration is very time consuming. Consequently, we are led to investigate alternative methods employing trigonometric polynomial interpolation through evenly spaced data. The resulting formulas are the basis of an important algorithm called the Fast Fourier Transform (FFT) . Although the Fourier coefficients obtained by interpolation are approximate, these coefficients can be computed very rapidly when the number of sample points is an integer power of 2 or a product of small primes. We will discuss next the ideas behind trigonometric polynomial interpolation among evenly spaced data values.
Suppose we truncate the Fourier series and only use harmonics up to some order N. We assume f (x) has period 2π so that
N
f (x)= Σ c3 e13x.
3=- N
This trigonometric polynomial satisfies f (0) = f (2π) even though the original func­
tion might actually have a finite discontinuity at 0 and 2π. Consequently, we may choose to use, in place of f (0), the limit as e ^ 0 of [f (e) + f (2π — e)]/2.
It is well known that the functions e13x satisfy an orthogonality condition for inte­
gration over the interval 0 to 2π. They also satisfy an orthogonality condition regard­
ing summation over equally spaced data. The latter condition is useful for deriving a discretized approximation of the integral formula for the exact Fourier coefficients. Let us choose data points
xj = ° < J < (2ΛΓ-!),
and write the simultaneous equations to make the trigonometric polynomial match the original function at the equally spaced data points. To shorten the notation we let
t = en/N,
and write
N
fk = Σ c3tk3.
3=- N
Suppose we pick an arbitrary integer n in the range —N < n < N. Multiplying the last equation by t -kn and summing from k = 0 to 2N — 1 gives
2N-1 2N-1 N
Σ f kt -kn = Σ t -kn Σ c3tk3.
k =0 k =0 3= - N
Interchanging the summation order in the last equation yields
2N-1 N 2N-1
Σ f kt -kn = Σ c ^ ζk
k =0 3= - N k =0
where ζ _ el(j η)π/Ν. Summing the inner geometric series gives
2N-1 f ζ2Ν
»k 1 --- “
Ak = J “ [z^- for c φ 1,
^ ' 2N for ζ =1.
k=0
We find, for all k and n in the stated range, that
ζ2Ν et‘^'K(k-n) i
Therefore we get
2N - 1
Σ f kt -kn _ 2Ncn , - N < n < N.
k=0
In the cases where n _ ± N, the procedure just outlined only gives a relationship governing cN + c- N. Since the first and last terms cannot be computed uniquely, we customarily take N large enough to discard these last two terms and write simply
1 2N-1
c" = m Σ f ^ kn > ~ N < n < N.
k=0
This formula is the basis for fast algorithms (called FFT for Fast Fourier Transform) to compute approximate Fourier coefficients. The periodicity of the terms depending on various powers of el^/N can be utilized to greatly reduce the number of trigono­
metric function evaluations. The case where N equals a power of 2 is especially attractive. The mathematical development is not provided here. However, the related theory was presented by Cooley and Tukey in 1965 [21] and has been expounded in many textbooks [53, 96]. The result is a remarkably concise algorithm which can be comprehended without studying the details of the mathematical derivation. For our present interests it is important to understand how to use MATLAB’s intrinsic function for the FFT (fft).
Suppose a periodic function is evaluated at a number of equidistant points ranging over one period. It is preferable for computational speed that the number of sample points should equal an integer power of two (n _ 2m). Let the function values for argument vector
x _ p/n * (0 : n — 1)
be an array f denoted by
f [ f l f · · · ,fn].
The function evaluation ff t
(f ) produces an array of complex Fourier coefficients multiplied by n and arranged in a peculiar fashion. Let us illustrate this result for n _ 8. If
f _ [fl, f2, ··· , fs]
then fft(f ) / 8 produces
c [c0? c1, c2? c3? c*i c-3j c-2j c—1].
The term denoted by c* actually turns out to equal c4 + c- 4, so it would not be used in subsequent calculations. We generalize this procedure for arbitrary n as follows. Let N _ n/2 — 1. In the transformed array, elements with indices of 1, · ·· ,N + 1 correspond to c0, · ·· ,cN and elements with indices of n,n — 1,n — 2, · ·· ,N + 3 correspond to c- 1, c- 2, c- 3, · ·· , c- N. It is also useful to remember that a real valued function has c- n _ conj(cn). To fix our ideas about how to evaluate a Fourier series, suppose we want to sum an approximation involving harmonics from order zero to order (nsum — 1). We are dealing with a real valued function defined by func with a real argument vector x. The following code expands func and sums the series for argument x using nsum terms.
f u n c t i o n f o u v a l = f f t a p r o x ( f u n c,p e r i o d,n f f t,n s u m,x ) f c = f e v a l ( f u n c,p e r i o d/n f f t * ( 0:n f f t - 1 ) ); f c = f f t ( f c )/n f f t; f c ( 1 ) = f c ( 1 )/2; w = 2 * p i/p e r i o d * ( 0:n s u m - 1 ); f o u v a l = 2 * r e a l ( e x p ( i * x (:) * w ) * f c (:) );
6.2 Some Applications
Applications of Fourier series arise in numerous practical situations such as struc­
tural dynamics, signal analysis, solution of boundary value problems, and image processing. Three examples are given below that illustrate use of the FFT. The first example calculates Bessel functions and the second problem studies forced dynamic response of a lumped mass system. The final example presents a program for con­
structing Fourier expansions and displaying graphical results for linearly interpolated or analytically defined functions.
6.2.1 Using the FFT to Compute Integer Or de r Bessel Functions
The FFT provides an efficient way to compute integer order Bessel functions Jn(x) which are important in various physical applications [119]. Function J n(x) can be obtained as the complex Fourier coefficient of e n in the generating function described by
tt
elxsin(9) _ J 2 Jn(x)em9.
n=-tt
Orthogonality conditions imply
1 ί 2π
Jn(x) = — ^ ^ W -ηθ) d0
2π J 0
Surface Plot For Jn(x)
W.··-·"
Figure 6.1: Surface Plot for Jn (x)
The Fourier coefficients represented by J n(x) can be computed approximately with the FFT. The infinite series converges very rapidly because the function it represents has continuous derivatives of all finite orders. Of course, e lx sm(0) is highly oscilla­
tory for large |x|, thereby requiring a large number of sample points in the FFT to obtain accurate results. For n < 30 and x < 30, a 128-point transform is adequate to give about ten digit accuracy for values of J n(x). The following code implements the above ideas and plots a surface showing how Jn changes in terms of n and x.
MATLAB Example
Bessel Function Program plotjrun
f u n c t i o n p l o t j r u n % Example: p l o t j r u n %...........................................
% This program computes i n t e g e r o r d e r Bessel % f u n c t i o n s of t h e f i r s t k i n d by u s i n g t h e FFT. %
% User m f u n c t i o n s r e q u i r e d: j n f t
x = 0:.5:2 0; n=0:20; J = j n f t ( n,x ); s u r f ( x,n,J'); t i t l e ('S u r f a c e P l o t For J _ { n } ( x )'); y l a b e l ('o r d e r n'), x l a b e l ('a r g u m e n t x') z l a b e l ('f u n c t i o n v a l u e'), f i g u r e ( g c f ); p r i n t -deps p l o t j r u n
%==============================================
f u n c t i o n J = j n f t ( n,z,n f t )
%
% J = j n f t ( n,z,n f t )
%.....................................................
% I n t e g e r o r d e r Bessel f u n c t i o n s of t h e % f i r s t ki nd computed by use of t h e F as t % F o u r i e r Transform (FFT).
%
% n - i n t e g e r v e c t o r d e f i n i n g t h e f u n c t i o n % o r d e r s
% z - a v e c t o r of v a l u e s d e f i n i n g t h e
% arguments
% n f t - number of f u n c t i o n e v a l u a t i o n s used
% i n t h e FFT c a l c u l a t i o n. This v al u e
% s houl d be an i n t e g e r power of 2 and
% s houl d exceed t wi c e t h e l a r g e s t
% component of n. When n f t i s o m i t t e d
% from t h e argument l i s t, t h e n a v a l u e
% equal t o 512 i s used. More a c c u r a t e
% v a l u e s of J a r e computed as n f t i s
% i n c r e a s e d. For max(n) < 30 and
% max(z) < 30, nft=256 g i v e s about
% t e n d i g i t ac cura cy.
% J - a m a t r i x of v a l u e s f o r t h e i n t e g e r
41: %
42: %
43: %
44: %
45: %
46: %
47: %
48: %
49:
50: i f nar gi n< 3, nft =512; end;
51: J = e x p ( s i n ( ( 0:n f t - 1 )'* ...
52: (2 * p i/n f t ) ) * ( i * z (:).') )/n f t;
53: J = f f t ( J ); J = J ( 1 + n,:).';
54: i f s u m ( a b s ( i m a g ( z ) ) ) < m a x ( a b s ( z ) )/1 e 1 0 55: J = r e a l ( J );
56: end
6.2.2 Dynamic Response of a Mass on an Oscillating Foundation
Fourier series are often used to describe time dependent phenomena such as earth­
quake ground motion. Understanding the effects of foundation motions on an elastic structure is important in design. The model in
Figure 6.2 embodies rudimentary as­
pects of this type of system and consists of a concentrated mass connected by a spring and viscous damper to a base which oscillates with known displacement Y(t). The system is assumed to have arbitrary initial conditions y(0) = y 0 and y(0) = v0 when the base starts moving. The resulting displacement and acceleration of the mass are to be computed.
We assume that Y (t) can be represented well over some time interval p by a Four­
ier series of the form
Y(t) = £ , ωη = —
p
n= — o
where c—n = conj(cn) because Y is real valued. The differential equation governing this problem is
my + cy + ky = kY (t) + cY (t) = F (t) where the forcing function can be expressed as
OO / OO
F (t) = ^ 2 cn[k + icwn]e1Un 1 = kco + 2 r e a l l y f ne1Unt
n=—o \n=1
and
f n = cn(k + lc^n)·
The corresponding steady-state solution of the differential equation is representable
o r d e r B e s s e l f u n c t i o n of t h e f i r s t k i n d. Row p o s i t i o n ma t c h e s o r d e r s d e f i n e d by n, and col umn p o s i t i o n c o r r e s p o n d s t o a r g u me n t s d e f i n e d by c omponent s of z.
Us e r m f u n c t i o n s c a l l e d: n o n e.
y(t)
Y(t)
Figure 6.2: Mass System
as
ys(t) = Σ yne
n= —O
where y—n = conj(yn) since ys(t) is real valued. Substituting the series solution into the differential equation and comparing coefficients of e 1Unt on both sides leads to
cn(k + ic^n)
yn ~ i 2 i ■ k — mi^n + icwn
The displacement, velocity, and acceleration corresponding to the steady-state (also called particular) solution are
ys(t) = co + 2 real ^
yn e
ys(t) = 2 real ^ ^ iUnyneMntj
O
ys(t) = —2 real ( ^ yneMnt
The initial conditions satisfied by y s are
O O
ys (0) = co + 2 real ( ^ yrA , ys(0) = 2 real ( ^
nyn
n=1
n=1
Because these values usually will not match the desired initial conditions, the total solution consists of ys(t) and yh(t) which satisfies the homogeneous differential equation
myh + cyh + kyh = 0.
The solution is
yh = giesit + g2es2t
where si and s2 are roots satisfying
ms 2 + cs + k = 0.
The roots are
—c + %/e2 — 4 mk —c — %/e2 — 4 mk
Since the total solution is
y(t) = y.s(t) + yh (t) the constants g1 and g2 are obtained by solving the two simultaneous equations
gi + g 2 = y(0) — ys(0) , sigi + S2 g2 = y(0) — ys(0).
The roots si and s2 are equal when c = 2%/mk. Then the homogeneous solution assumes an alternate form given by (gi + g2t)est with s = —cj(2m). In this special case we find that
gi = y(0) — ys(0), g2 = y(0) — ys(0) — sgi.
It should be noted that even though roots s i and s2 will often be complex numbers, this causes no difficulty since MATLAB handles the complex arithmetic automat­
ically (just as it does when the FFT transforms real function values into complex Fourier coefficients).
The harmonic response solution works satisfactorily for a general forcing function as long as the damping coefficient c is nonzero. A special situation can occur when c = 0, because the forcing function may resonate with the natural frequency of the undamped system. If c is zero, and for some n we have \Jk/ηι = 2πη/ρ, a condition of harmonic resonance is produced and a value of zero in the denominator occurs when the corresponding y n is computed. In the undamped resonant case the particular solution grows like \telUnt], quickly becoming large. Even when c is small and y/k/m « 2πη/ρ, undesirably large values of y n can result. Readers interested in the important phenomenon of resonance can find more detail in Meirovitch [68].
This example concludes by using a base motion resembling an actual earthquake excitation. Seismograph output employing about 2700 points recorded during the Imperial Valley, California, earthquake of 1940 provided the displacement history for Figure 6.3.
The period used to describe the motion is 53.8 seconds. A program was written to analyze system response due to a simulated earthquake base excitation. The following program modules are used:
sets data values and generates graphical results generates Fourier series approximations for a general function
piecewise linear function approximating the Imperial Valley earthquake data
computes steady-state displacement and acceleration for a spring-mass-dashpot system subjected to base motion expandable in a Fourier series computes the homogeneous solution for the spring- mass-dashpot system subjected to general initial con­
ditions
Numerical results were obtained for a system having a natural period close to one second (2π/6 « 1.047) and a damping factor of 5 percent. The function imptp was employed as an alternative to the actual seismograph data to provide a concisely expressible function which still embodies characteristics of a realistic base motion. Figure 6.4 shows a plot of function imptp along with its approximation by a twenty- term Fourier series. The series representation is surprisingly good considering the fact that such a small number of terms is used. The use of two-hundred terms gives an approximation which graphically does not deviate perceptibly from the actual function. Results showing how rapidly the Fourier coefficients diminish in magni­
tude with increasing order appear in
Figure 6.5
. The dynamical analysis produced displacement and acceleration values for the mass.
Figure 6.6 shows both the total displacement as well as the displacement contributed from the homogeneous solution alone. Evidently, the steady-state harmonic response function captures well most of the motion, and the homogeneous part could probably be neglected without serious error.
Figure 6.7
also shows the total acceleration of the mass which is, of course, proportional to the resultant force on the mass due to the base motion.
Before proceeding to the next example, the reader should be sure to appreciate the following important fact. Once a truncated Fourier series expansion of the forcing function using some appropriate number of terms is chosen, the truncated series defines an input function for which the response is computed exactly. If the user takes enough terms in the truncated series so that he/she is well satisfied with the function it approximates, then the computed response value for y(t) will also be acceptable. This situation is distinctly different from the more complicated type of approximations occurring when finite difference or finite element methods produce discrete approximations for continuous field problems. Understanding the effects of grid size discretization error is more complex than understanding the effects of series truncation in the example given here.
unitized displacement displacement/gravity
Normalized Base Displacement
time, seconds
Figure 6.3: Normalized Base Displacement
Result from a 20-Term Fourier Series
time, seconds
Figure 6.4: Result from a 20-Term Fourier Series
displacement coefficient magnitude
Coefficient Magnitude in Base Motion Expansion
harmonic order
Figure 6.5: Coefficient Magnitude in Base Motion Expansion
Total and Homogeneous Response
time
Figure 6.6: Total and Homogeneous Response
Acceleration Due to Base Oscillation
Figure 6.7: Acceleration Due to Base Oscillation
MATLAB Example Program runimpv
i: f u n c t i o n r uni mpv 2: % Exampl e: r uni mpv
3: %...........................................................................
4: % T h i s i s a d r i v e r p r o g r a m f o r t h e 5: % e a r t h q u a k e exa mpl e.
6: %
7: % Us e r m f u n c t i o n s r e q u i r e d:
8: % f o u a p r o x, i mp t p, hsmck,
9: % s h k b f t s s, l i n t r p
10:
i i: % Make t h e undamped p e r i o d a b o u t one i 2: % s e c o n d l o n g i 3: m=1; k=36;
14:
i 5: % Use dampi ng e q u a l t o 5 p e r c e n t of c r i t i c a l i 6: c =.0 5 * ( 2 * s q r t ( m * k ) );
i 7:
i 8
i 9
20:
2 i:
22
23:
24
25
26
27:
28
29
30:
3 i
32
33
34
35
36
37
38
39
40:
4 i
42
43
44
45
46
47
48
49
50:
5 i:
52
53:
54
55
56
57:
58
59
60:
6 i:
62
% Choose a p e r i o d equal t o l e n g t h of % I m p e r i a l V a l l e y e a r t hquake d a t a prd=53.8;
nft =1024; tmin=0; tmax=prd; ntimes=200; nsum=80; % ntimes=501; nsum=200; t p l t = l i n s p a c e ( 0,p r d,n t i m e s ); y 2 0 t r m = f o u a p r o x ('i m p t p',p r d,t p l t,2 0 ); p l o t ( t p l t,y 2 0 t r m,'-',t p l t,i m p t p ( t p l t ),'—'); x l a b e l ('t i m e, s e c o n d s'); y l a b e l ('u n i t i z e d d i s p l a c e m e n t'); t i t l e ('R e s u l t from a 20-Term F o u r i e r S e r i e s') f i g u r e ( g c f );
d i s p ('P r e s s [Enter] t o c o n t i n u e'); d u m y = i n p u t ('','s');
% p r i n t -deps 20 t r mp l t
% Show how magnitudes of F o u r i e r c o e f f i c i e n t s % d e c r e a s e wi t h i n c r e a s i n g harmonic o r d e r
f c o f = f f t ( i m p t p ( ( 0:1 0 2 3 )/1 0 2 4,1 ) )/1 0 2 4; c l f; p l o t ( a b s ( f c o f ( 1:1 0 0 ) ) ); x l a b e l ('h a r m o n i c o r d e r'); y l a b e l ('c o e f f i c i e n t m a g n i t u d e'); t i t l e ( ['C o e f f i c i e n t Magnitude i n Base ' ...
'Motion E x p a n s i o n'] ); f i g u r e ( g c f ); d i s p ('P r e s s [Enter] t o c o n t i n u e'); d u m y = i n p u t ('','s');
% p r i n t -deps c o e f s i z e
% Compute f o r c e d r e s ponse [ t,y s,y s 0,v s 0,a s ] = ...
s h k b f t s s ( m,c,k,'i m p t p',p r d,n f t,n s u m, ... t m i n,t m a x,n t i m e s );
% Compute homogeneous s o l u t i o n [ t,y h,a h ] = ... h s m c k ( m,c,k,- y s 0,- v s 0,t m i n,t m a x,n t i m e s );
% Obtain t h e combined s o l u t i o n y = y s (:) + y h (:); a = a s (:) + a h (:); c l f; p l o t ( t,y,'-',t,y h,' ');
x l a b e l ('t i m e'); y l a b e l ('d i s p l a c e m e n t'); t i t l e ('T o t a l and Homogeneous R e s p o n s e'); l e g e n d ('T o t a l response','Homogeneous r e s p o n s e');
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
f i g u r e ( g c f );
d i s p ('P r e s s [Enter] t o c o n t i n u e');
d u m y = i n p u t ('','s');
p r i n t -deps d i s p l a c;
c l f; p l o t ( t,a,'-');
x l a b e l ('t i m e'); y l a b e l ('a c c e l e r a t i o n') t i t l e ('A c c e l e r a t i o n Due t o Base O s c i l l a t i o n') f i g u r e ( g c f ); p r i n t -deps a c c e l
%============================================
f u n c t i o n y = f o u a p r o x ( f u n c,p e r,t,n s u m,n f t )
%
% y = f o u a p r o x ( f u n c,p e r,t,n s u m,n f t )
%...............................................................................
% Approximation of a f u n c t i o n by a F o u r i e r % s e r i e s.
%
% func - f u n c t i o n b e i ng expanded % p e r - p e r i o d of t h e f u n c t i o n
% t - v e c t o r of t i me s a t which t h e s e r i e s
% i s t o be e v a l u a t e d
% nsum - number of terms summed i n t h e s e r i e s
% n f t - number of f u n c t i o n v a l u e s used t o
% compute F o u r i e r c o e f f i c i e n t s. This
% s houl d be an i n t e g e r power of 2.
% The d e f a u l t i s 1024
%
% User m f u n c t i o n s c a l l e d: none.
%-----------------------------------------------------------------------------
i f nar gi n< 5, nft=1024; end;
n s u m = m i n ( n s u m,f i x ( n f t/2 ) );
c = f f t ( f e v a l ( f u n c,p e r/n f t * ( 0:n f t - 1 ) ) )/n f t;
c ( 1 ) = c ( 1 )/2; c = c (:); c=c(1:nsum);
w=2*pi/per *(0:nsum- 1);
y = 2 * r e a l ( e x p ( i * t (:) * w ) * c );
%========================================
f u n c t i o n y b a s e = i m p t p ( t,p e r i o d )
%
% y b a s e = i m p t p ( t,p e r i o d )
%.....................................................
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
This f u n c t i o n d e f i n e s a p i e c e w i s e l i n e a r f u n c t i o n r e s embl i ng t h e ground motion of t h e ea r t h q u a k e which o c c u r r e d i n 1940 i n t h e I m p e r i a l Va l l ey of C a l i f o r n i a. The maximum ampl i tude of base motion i s normal i zed t o equal u n i t y.
p e r i o d - p e r i o d of t h e motion ( o p t i o n a l argument) t - v e c t o r of t i me s between
tmin and tmax ybase - p i e c e w i s e l i n e a r l y i n t e r p o l a t e d base motion
User m f u n c t i o n s c a l l e d: l i n t r p
t f t =
= [ ..·
0.
00
1.
26
2.
64
4.
01
5.
10
5.
.79
7.
• 74;
8.
65
9.
74
10.
77
13.
.06
15.
07
21.
60
25.
.49;
27.
38
31.
.56
34.
94
36.
66
38.
03
40.
67
41.
.87;
48.
40
51.
04
53.
80
0
0
0
0
]';
yft=
= [ ..·
0
0.
92
- 0.
25
1.
00
-0.
29
0.
46
-0.
.16;
- 0.
97
-0.
49
-0.
83
0.
95
0.
86
- 0.
76
0.
85;
-0.
55
0.
36
-0.
52
- 0.
38
0.
02
-0.
19
0.
.08;
-0.
26
0.
24
0.
00
0
0
0
0
]';
t f t =
t(
f
t
);
t
f
y
=yft(
::);
t f t = t f t ( 1:2 4 ); y f t = y f t ( 1:2 4 ); i f n a r g i n == 2
t f t = t f t * p e r i o d/m a x ( t f t );
end
y b a s e = l i n t r p ( t f t,y f t Jt );
%=
f u n c t i o n [ t Jy s Jy s 0 Jv s 0,a s ] =...
s h k b f t s s ( m,c Jk Jy b a s e Jp r d Jn f t,n s u m J ... t mi n j t ma x j n t i me s)
%
% [ t Jy s Jy s 0 Jv s 0,a s ] =...
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
% s h k b f t s s ( m,c,k,y b a s e,p r d,n f t,n s u m, ...
% t m i n,t ma x,n t i m e s )
%.......................................................................................................
% This f u n c t i o n de t e r mi ne s t h e s t e a d y - s t a t e % s o l u t i o n of t h e s c a l a r d i f f e r e n t i a l e q u a t i o n %
% m * y''( t ) + c * y'( t ) + k * y ( t ) =
% k * y b a s e ( t ) + c * y b a s e'( t )
%
% where ybase i s a f u n c t i o n of p e r i o d prd % which i s expandable i n a F o u r i e r s e r i e s
%
% m,c,k - Mass, damping c o e f f i c i e n t, and
% s p r i n g s t i f f n e s s
% ybase - F u nct i on or v e c t o r of
% d i s p l a c e me n t s e q u a l l y spaced i n
% ti me which d e s c r i b e s t h e base
% motion over a p e r i o d
% p r d - P e r i o d used t o expand xbase i n a
% F o u r i e r s e r i e s
% n f t - The number of components used
% i n t h e FFT (shoul d be a power
% of t wo). I f n f t i s i n p u t as
% z e r o, t h e n ybase must be a
% v e c t o r and n f t i s s e t t o
% l e n g t h ( y b a s e )
% nsum - The number of terms t o be used
% t o sum t h e F o u r i e r s e r i e s
% expansion of ybase. This s houl d
% not exceed n f t/2.
% t min,tmax - The minimum and maximum t i mes % f o r which t h e s o l u t i o n i s t o
% be computed
% t - A v e c t o r of t i mes a t which
% t h e s o l u t i o n i s computed
% ys - Vector of s t e a d y - s t a t e s o l u t i o n
% v a l u e s
% y s 0,v s 0 - P o s i t i o n and v e l o c i t y a t t=0 % as - A c c e l e r a t i o n y s''( t ), i f t h i s
% q u a n t i t y i s r e q u i r e d
%
% User m f u n c t i o n s c a l l e d: none.
%-------------------------------------------------------------
i f nft==0
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
n f t = l e n g t h ( y b a s e ); y b f t = y b a s e (:) e l s e
t b f t = p r d/n f t * ( 0:n f t - 1 ); y b f t = f f t ( f e v a l ( y b a s e,t b f t ) )/n f t; y b f t = y b f t (:);
end
ns u m = m i n ( n s u m,f i x ( n f t/2 ) ); y b f t = y b f t ( 1:n s u m ); w=2*pi/prd*(0:nsum-1);
t = t m i n + ( t m a x - t m i n )/( n t i m e s - 1 ) * ( 0:n t i m e s - 1 ) et w=exp(i*t*w); w=w(:); y s f t = y b f t.* ( k + i * c * w )./( k + w.* ( i * c - m * w ) ); y s f t ( 1 ) = y s f t ( 1 )/2;
y s = 2 * r e a l ( e t w * y s f t ); y s 0 = 2 * r e a l ( s u m ( y s f t ) );
v s 0 = 2 * r e a l ( s u m ( i * w.* y s f t ) );
i f n a r gout > 4
y s f t = - y s f t.* w.~ 2; a s = 2 * r e a l ( e t w * y s f t ); end
%=============================================
f u n c t i o n [ t,y h,a h ] = ...
h s m c k ( m,c,k,y 0,v 0,t m i n,t m a x,n t i m e s )
%
% [ t,y h,a h ] = h s m c k ( m,c,k,y 0,v 0,t m i n,t m a x,n t i m e s )
%....................................................................................................................
% S o l u t i o n of
% m * y h''( t ) + c * y h'( t ) + k * y h ( t ) = 0
% s u b j e c t t o i n i t i a l c o n d i t i o n s of % yh(0) = y0 and y h'( 0 ) = v0
%
k
c
m,
- mass, damping and s p r i n g
c o n s t a n t s
*<!
O
v
O
- i n i t i a l p o s i t i o n and v e l o c i t y
x
a
m
t
n,
i
m
t
- minimum and maximum t i mes
ntimes
- number of t i mes t o e v a l u a t e
s o l u t i o n
t
- v e c t o r of t i mes
yh
- d i s p l a c e me n t s f o r t h e
homogeneous s o l u t i o n
ah
- a c c e l e r a t i o n s f o r t h e
homogeneous s o l u t i o n
%
%
%
% User m f u n c t i o n s c a l l e d: none.
%-------------------------------------------------------------
%
%
2 4 3: t = t m i n + ( t m a x - t m i n )/( n t i m e s - 1 ) * ( 0:n t i m e s - 1 ) ;
2 4 4: r = s q r t ( c * c - 4 * m * k );
2 4 5: i f r ~ = 0
2 4 6: s 1 = ( - c + r )/( 2 * m ); s 2 = ( - c - r )/( 2 * m );
2 4 7: g = [ 1,1;s 1,s 2 ]\[ y 0;v 0 ];
2 4 8: y h = r e a l ( g ( 1 ) * e x p ( s 1 * t ) + g ( 2 ) * e x p ( s 2 * t ) );
2 4 9: i f n a r g o u t > 2
2 5 0: a h = r e a l ( s 1 * s 1 * g ( 1 ) * e x p ( s 1 * t ) + ...
2 5 1: s 2 * s 2 * g ( 2 ) * e x p ( s 2 * t ) );
2 5 2: end
2 5 3: e l s e
2 5 4: s = - c/( 2 * m );
2 5 5: g1=y0; g 2 =v 0 - s * g 1; y h = ( g 1 + g 2 * t ).* e x p ( s * t );
2 5 6: i f n a r g o u t > 2
2 5 7: a h = r e a l ( s * ( 2 * g 2 + s * g 1 + s * g 2 * t ).* e x p ( s * t ) );
2 5 8: end
2 5 9: end
2 6 0:
2 6 1: %=============================================
2 6 2:
2 6 3: % f u n c t i o n y = l i n t r p ( x d,y d,x )
2 6 4: % See Appe ndi x B
6.2.3 General Program to Plot Fourier Expansions
The final example in this chapter is a program to compute Fourier coefficients of general real valued functions and to display series with varying numbers of terms so that a user can see how rapidly such series converge. Since a truncated Fourier series is a continuous differentiable function, it cannot perfectly represent a discon­
tinuous function such as a square wave. Near points where jump discontinuities occur, Fourier series approximations oscillate [18]. The same kind of behavior oc­
curs less seriously near points of slope discontinuity. Adding more terms does not cure the problem at jump discontinuities. The behavior, known as Gibbs phenom­
enon, produces approximations which overshoot the function on either side of the discontinuity. Illustrations of this behavior appear below.
A program was written to expand real functions of arbitrary period using Fourier series approximations computed with the FFT. A piecewise linear function can be specified interactively by giving data points over a period. Alternatively, a function which is user defined can be employed. For instance, a function varying like a sine
curve with the bottom half cut off would be
f u n c t i o n y=chopsi ne(x,peri od) y = s i n ( p i * x/p e r i o d ).* ( x < p e r i o d )
The program consists of the following functions.
fouseris
main driver
sine
example for exact function input
lintrp
function for piecewise linear interpolation
fousum
sum a real valued Fourier series
read
reads several data items on one line
Comments within the program illustrate how to input data interactively. Details of different input options can be found by executing the program.
Let us see how well the FFT approximates a function of period 3 defined by piece­
wise linear interpolation through ( x,y ) values of (0,1), (1,1), (1,-1), (2,-1), (3,1), and (4,0). The function has jump discontinuities at x = 0, x = 1, and x = 4. A slope discontinuity also occurs at x = 3. Program results using a twenty-term approximation appear in Figure 6.8.
Results produced by 100- and 250-term series plotted near x = 1 are shown in Figures 6.9 and
6.10.
Clearly, adding more terms does not eliminate the oscillation. However, the oscillation at a jump discontinuity can be reduced with the Lanczos smoothing procedure. Results for a series of 250 terms smoothed over an interval equal to the period times 0.01 appear in
Figure 6.11
. The oscillation is reduced at the cost of replacing the infinite slope at a discontinuity point by a steep slope of fifty-to-one for this case.
Figure 6.12
shows a plot produced using an exact function definition as indicated in the second program execution. The reader may find it instructive to investigate how well Fourier series converge by run­
ning the program for other function choices.
y axis y axis
Fourier Series for Harmonics up to Order 20
x axis
Figure 6.8: Fourier Series for Harmonics up to Order 20
Fourier S e r ie s for Harmonics up to Order 100
Figure 6.9: Fourier Series for Harmonics up to Order 100
Fourier Series for Harmonics up to Order 250
Figure 6.10: Fourier Series for Harmonics up to Order 250
Smoothed Fourier S e r i e s for Harmonics up to Order 250
Figure 6.11: Smoothed Fourier Series for Harmonics up to Order 250
y axis
Fourier Series for Harmonics up to Order 250
x axis
Figure 6.12: Exact Function Example for Harmonics up to Order 20
Examples of Fourier Series Expansions Output for Piecewise Linear Example
>> f o u s e r i s
FOURIER SERIES EXPANSION FOR A PIECEWISE LINEAR OR ANALYTICALLY DEFINED FUNCTION
I n p u t t h e p e r i o d o f t h e f u n c t i o n ? > 4
I n p u t t h e number o f d a t a p o i n t s t o d e f i n e t h e f u n c t i o n by p i e c e w i s e l i n e a r i n t e r p o l a t i o n ( i n p u t a z e r o i f t h e f u n c t i o n i s d e f i n e d a n a l y t i c a l l y by t h e u s e r ).
? > 6
I n p u t t h e x,y v a l u e s one p a i r p e r l i n e ? > 0,1 ? > 1,1 ? > 1,- 1 ? > 2,- 1 ? > 3,1 ? > 4,0
To p l o t t h e s e r i e s i n p u t xmi n, xmax, and t h e h i g h e s t h a r moni c n o t e x c e e d i n g 255 ( i n p u t 0,0,0 t o s t o p )
(Use a n e g a t i v e har moni c number t o s a v e y o u r g r a p h )
? > 0,4,2 0
To p l o t t h e s e r i e s smoot hed o v e r a f r a c t i o n o f t h e p e r i o d, i n p u t t h e s moot hi ng f r a c t i o n ( g i v e 0.0 f o r no s m o o t h i n g ).
? > 0
P r e s s RETURN t o c o n t i n u e
To p l o t t h e s e r i e s i n p u t xmi n, xmax, and t h e h i g h e s t h a r moni c n o t e x c e e d i n g 255 ( i n p u t 0,0,0 t o s t o p )
(Use a n e g a t i v e har moni c number t o s a v e y o u r gr a ph)
? > 0,0,0
Output for Analytically Defined Example
>> f o u s e r i s
FOURIER SERIES EXPANSION FOR A PIECEWISE LINEAR OR ANALYTICALLY DEFINED FUNCTION
Input the p e r i o d of t he f u n c t i o n ? > p i/2
Input the number of d a t a p o i n t s t o d e f i n e t he f u n c t i o n by pi ece wi s e l i n e a r i n t e r p o l a t i o n ( i nput a zero i f the f u n c t i o n i s d e f i n e d a n a l y t i c a l l y by the u s e r ).
? > 0
S e l e c t t he method used f o r exa ct f u n c t i o n d e f i n i t i o n:
1 <=> Use an e x i s t i n g f u n c t i o n wi t h syntax d e f i n e d by the fol l owi ng example:
f u n c t i o n y = s i n e ( x,p e r i o d )
Ο,
%
% y = s i n e ( x,p e r i o d )
Ο, ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
%
% This f u n c t i o n s p e c i f i e s a l l or p a r t of % a s i n e wave.
Ο,
%
% x - v e c t o r of argument val ues
% p e r i o d - p e r i o d of t he f u n c t i o n
% y - v e c t o r of f u n c t i o n val ues
Ο,
%
% User m f u n c t i o n s c a l l e d: none
Ο,
%--------------------------------------------------------------------------------------
y = s i n ( r e m ( x,p e r i o d ) );
or
2 <=> Use a o n e - l i n e c h a r a c t e r s t r i n g d e f i n i t i o n i nv o l v i n g argument x and p e r i o d p. For example a s i n e wave wi t h t he bottom cut o f f would be d e f i n e d by: s i n ( x * 2 * p i/p ).* ( x < p/2 )
1 or 2 ? > 1
Ent er the name of your f u n c t i o n ? > s i n e
To p l o t t he s e r i e s i nput xmin, xmax, and t he h i g h e s t harmonic not exceeding 255 (i nput 0,0,0 t o stop)
(Use a n e g a t i v e harmonic number t o save your graph) ? > 0,p i,- 2 0
To p l o t t he s e r i e s smoothed over a f r a c t i o n of the p e r i o d, i n p u t t he smoothing f r a c t i o n (give 0.0 f o r no smoothing).
? > 0
Give a f i l e name t o save the c u r r e n t graph > e x a c t p l t
Press RETURN t o cont i nue
To p l o t t he s e r i e s i nput xmin, xmax, and t he h i g h e s t harmonic not exceeding 255 (i nput 0,0,0 t o stop)
(Use a n e g a t i v e harmonic number t o save your graph)
? > 0,0,0
Fourier Series Program fouseris
f u n c t i o n f o u s e r i s Example: f o u s e r i s
This program i l l u s t r a t e s t h e convergence r a t e of F o u r i e r s e r i e s appr oximati ons d e r i v e d by app l y i n g t h e FFT t o a g e n e r a l f u n c t i o n which may be s p e c i f i e d e i t h e r by p i e c e w i s e l i n e a r i n t e r p o l a t i o n i n a d a t a t a b l e or by a n a l y t i c a l d e f i n i t i o n i n a f u n c t i o n gi ven by t h e u s e r. The l i n e a r i n t e r p o l a t i o n model p e r m i t s i n c l u s i o n of jump d i s c o n t i n u i t i e s. S e r i e s havi ng v a r y i n g numbers of terms can be graphed t o demons t r at e Gibbs phenomenon and t o show how we ll t h e t r u n c a t e d F o u r i e r s e r i e s r e p r e s e n t s t h e o r i g i n a l f u n c t i o n. P r o v i s i o n i s made t o p l o t t h e F o u r i e r s e r i e s of t h e o r i g i n a l f u n c t i o n or a smoothed f u n c t i o n d e r i v e d by a v e r a g i n g t h e o r i g i n a l f u n c t i o n over an a r b i t r a r y f r a c t i o n of t h e t o t a l p e r i o d.
User m f u n c t i o n s r e q u i r e d:
fousum, l i n t r p, i n p u t v, s i n e
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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
% The f o l l o w i n g p a r ame t er s c o n t r o l t h e number % of f f t p o i n t s used and t h e number of p o i n t s % used f o r gr a phi ng.
nft =1024; ngph=1001; n m a x = i n t 2 s t r ( n f t/2 - 1 );
fpr int f('\nFOURIER SERIES EXPANSION FOR'); f p r i n t f (' A PIECEWISE LINEAR OR'); f p r i n t f ('\n ANALYTICALLY DEFINED ');
fpr int f('FUNCTION\n');
f p r i n t f ('\n I n p u t t h e p e r i o d of t h e f u n c t i o n\n'); p e r i o d = i n p u t ('? > '); x f c = ( p e r i o d/n f t ) * ( 0:n f t - 1 )' ;
f p r i n t f ('\n H o w many p o i n t s d e f i n e t h e f u n c t i o n'); f p r i n t f ('\n b y p i e c e w i s e l i n e a r i n t e r p o l a t i o n?'); f p r i n t f ('\n ( G i v e a z e ro f o r a n a l y t i c a l d e f i n i t i o n )\n') n d = i n p u t ('> ? '); i f nd > 0, x d = z e r o s ( n d,1 ); yd=xd;
f p r i n t f ('\n I n p u t t h e x,y v a l u e s one '); f p r i n t f ('p a i r p e r l i n e\n'); f o r j = 1:n d
[ x d ( j ),y d ( j ) ] = i n p u t v ('> ? '); end
% Use n f t i n t e r p o l a t e d d a t a p o i n t s t o % compute t h e f f t
y f c = l i n t r p ( x d,y d,x f c ); c = f f t ( y f c ); e l s e
f p r i n t f ('\n S e l e c t t h e method f o r '); f p r i n t f ('a n a l y t i c a l f u n c t i o n d e f i n i t i o n:\n'); f p r i n t f ('\n 1 <=> Use an e x i s t i n g f u n c t i o n '); f p r i n t f ('w i t h s ynt a x of t h e f o r m:'); f p r i n t f ('\n f u n c t i o n y = f u n c t ( x,p e r i o d ), or \n'); f p r i n t f ( ['\n 2 <=> Give a c h a r a c t e r s t r i n g ',...
'i n a r g u m e n t x a n d p e r i o d p.'] ) f p r i n t f ( ['\n ( S u c h a s: s i g n ( s i n ( 2 * p i * x/p ) ) '...
't o ma k e a s q u a r e w a v e )\n'] ) n o p t = i n p u t ('E n t e r 1 o r 2 ? > '); i f n o p t == 1
f p r i n t f ('\n E n t e r t h e n a me o f y o u r '); f p r i n t f ('f u n c t i o n\n'); f n a m = i n p u t ('> ? ','s'); y f c = f e v a l ( f n a m,x f c,p e r i o d ); c = f f t ( y f c ); e l s e
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
f p r i n t f ('\n I n p u t t h e o n e - l i n e d e f i n i t i o n'); f p r i n t f (' i n terms of x and p\n'); s t r n g = i n p u t ('> ? ','s'); x = x f c; p = p e r i o d; y f c = e v a l ( s t r n g ); c = f f t ( y f c ); end end
w h i l e 1
f p r i n t f ('\n T o p l o t t h e s e r i e s i n p u t x m i n,'); f p r i n t f (' xmax, and t h e h i g h e s t'); f p r i n t f ( ['\n h a r m o n i c n o t e x c e e d i n g ', ...
n ma x,' ( p r e s s [ E n t e r ] t o s t o p )'] ); f p r i n t f ('\n ( U s e a n e g a t i v e h a r mo n i c n u m b e r'); f p r i n t f (' t o s a v e y o u r g r a p h )\n'); [ x l,x u,n h ] = i n p u t v ('> ? '); i f i s n a n ( x l ), b r e a k; end p l t s a v = ( n h < 0 ); n h = a b s ( n h ); x t m p = x l + ( ( x u - x l )/n g p h ) * ( 0:n g p h ); f p r i n t f ('\n T o p l o t t h e s e r i e s s moot hed '); f p r i n t f ('o v e r a f r a c t i o n of t h e'); f p r i n t f ('\n p e r i o d, i n p u t t h e s mo o t h i n g '); f p r i n t f ('f r a c t i o n');
f p r i n t f ('\n ( g i v e 0.0 f o r no s m o o t h i n g ).\n'); a l p h a = i n p u t ('> ? '); y f o u = f o u s u m ( c,x t m p,p e r i o d,n h,a l p h a ); xxt mp=xt mp; i d n e g = f i n d ( x t m p < 0 ); x n g = a b s ( x t m p ( i d n e g ) ); x x t m p ( i d n e g ) = x x t m p ( i d n e g ) + ...
p e r i o d * c e i l ( x n g/p e r i o d );
i f nd>0
y e x a c = l i n t r p ( x d,y d,r e m ( x x t m p,p e r i o d ) );
e l s e
i f n o p t == 1
y e x a c = f e v a l ( f n a m,x t m p,p e r i o d );
e l s e
x=xxt mp; y e x a c = e v a l ( s t r n g ); end end
i n = i n t 2 s t r ( n h ); i f a l p h a == 0
t i t l = ['F o u r i e r S e r i e s f o r Har moni c s ' ... 'u p t o Or d e r ',i n ];
e l s e
t i t l = ['S m o o t h e d F o u r i e r S e r i e s f o r ' ...
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
'Harmonics up t o Order ',i n ];
end
c l f; p l o t ( x t m p,y f o u,'-',x t m p,y e x a c,'—'); y l a b e l ('y a x i s'); x l a b e l ('x a x i s'); zoom on t i t l e ( t i t l ); g r i d on; f i g u r e ( g c f ); d i s p (' '); d i s p ('Yo u c a n zoom i n w i t h t h e mouse b u t t o n.') i n p u t ('Y o u c a n p r e s s [ E n t e r ] t o c o n t i n u e. ','s'); i f p l t s a v d i s p (' ')
f i l n a m = i n p u t ( ['G i v e a f i l e name t o ' ...
's a v e t h e c u r r e n t g r a p h > ? '],'s'); i f l e n g t h ( f i l n a m ) > 0
e v a l ( ['p r i n t - d e p s ',f i l n a m ] ); end end end
%=============================================
f u n c t i o n y = s i n e ( x,p e r i o d )
% y = s i n e ( x,p e r i o d )
% F u n c t i o n f o r a l l o r p a r t of a s i n e wave.
% x,p e r i o d - v e c t o r ar g u me n t and p e r i o d % y - f u n c t i o n v a l u e
%
y=si n(rem(x,peri od));
%=============================================
f u n c t i o n y r e a l = f o u s u m ( c,x,p e r i o d,k,a l p h a )
%
% y r e a l = f o u s u m ( c,x,p e r i o d,k,a l p h a )
%.......................................................................................
% Sum t h e F o u r i e r s e r i e s o f a r e a l % v a l u e d f u n c t i o n.
%
% x - The v e c t o r of r e a l v a l u e s a t
% whi ch t h e s e r i e s i s e v a l u a t e d.
% c - A v e c t o r o f l e n g t h n c o n t a i n i n g
% F o u r i e r c o e f f i c i e n t s o u t p u t by
% t h e f f t f u n c t i o n
% p e r i o d - The p e r i o d of t h e f u n c t i o n
% k - The h i g h e s t h a r mo n i c u s e d i n
% t h e F o u r i e r sum. T h i s must
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
% not exceed n/2 - 1
% a l p h a - I f t h i s par amet e r i s nonzero,
% t h e F o u r i e r c o e f f i c i e n t s a r e
% r e p l a c e d by t h o s e of a f u n c t i o n
% o b t a i n e d by a v e r a g i n g t h e
% o r i g i n a l f u n c t i o n over a l p h a
% t i me s t h e p e r i o d
% y r e a l - The r e a l v a l u e d F o u r i e r sum
% f o r argument x
%
% The F o u r i e r c o e f f i c i e n t s c must have been % computed u s i n g t h e f f t f u n c t i o n which
% t r a n s f o r m s t h e v e c t o r [ y ( 1 ),...,y ( n ) ] i n t o
% an a r r a y of compl ex F o u r i e r c o e f f i c i e n t s % wh i c h h a ve b e e n m u l t i p l i e d by n and a r e % a r r a n g e d i n t h e o r d e r:
%
% [ c ( 0 ),c ( 1 ),...,c ( n/2 - 1 ),c ( n/2 ),
% c ( - n/2 + 1 ),...,c ( - 1 ) ].
%
% T h e c o e f f i c i e n t c ( n/2 ) c a n n o t be u s e d % s i n c e i t i s a c t u a l l y t h e sum o f c ( n/2 ) and
% c ( - n/2 ). For a p a r t i c u l a r v a l u e of n, t h e
% h i g h e s t u s a b l e h a r mo n i c i s n/2 - 1.
%
% Us e r m f u n c t i o n s c a l l e d: none
%-----------------------------------------------------------------------------------
x=x(:); n = l e n g t h ( c ); i f n a r g i n <4, k = n/2 - 1; a l p h a = 0; end i f n a r g i n <5, a l p h a = 0; end i f n a r g i n <3, p e r i o d = 2 * p i; end L = p e r i o d/2; k = m i n ( k,n/2 - 1 ); t h = ( p i/L ) * x; i = s q r t ( - 1 ); z = e x p ( i * t h ); y = c ( k + 1 ) * o n e s ( s i z e ( t h ) ); p a = p i * a l p h a; i f a l p h a > 0 j j = ( 1:k )';
c ( j j + 1 ) = c ( j j + 1 ).* s i n ( j j * p a )./( j j * p a ) ; end
f o r j = k:- 1:2, y = c ( j ) + y.* z; end y r e a l = r e a l ( c ( 1 ) + 2 * y.* z )/n;
%===========================================
% f u n c t i o n y = l i n t r p ( x d,y d,x )
204: % See Appe ndi x B
2 0 5:
2 0 6: %==================================
2 0 7:
2 0 8: % f u n c t i o n v a r a r g o u t = i n p u t v ( p r o m p t ) 209: % See Appe ndi x B
Chapiter 7
Dynamic Response of Linear Second Order Systems
7.1 Solving the Structural Dynamics Equations for Periodic Applied Forces
The dynamics of a linear structure subjected to periodic forces obeys the matrix differential equation
MX + CX + KX = F (t),
with initial conditions
X (0) = Do , X(0) = Vo.
The solution vector X (t) has dimension n and M, C, and K are real square matrices of order n. The mass matrix, M, the damping matrix, C, and the stiffness matrix, K, are all real. The forcing function F(t), assumed to be real and having period L, can be approximated by a finite trigonometric series as
N
F(t) = ^ ckelUkt where wk = 2nk/L k=-N
and i = V=T. The Fourier coefficients are vectors that can be computed using the FFT. The fact that F(t) is real also implies that c-k = conj (ck) and, therefore,
F(t) = co + 2 real j ChelWkt
\k = 1
The solution of the differential equation is naturally resolvable into two distinct parts. The first is the so called particular or forced response which is periodic and has the same general mathematical form as the forcing function. Hence, we write
n / n
Xp = Σ Xk elWkt = Xo + 2 real ^ X ke ^ kt
k = - n \k = 1
Substituting this series into the differential equation and matching coefficients of eliJkt on both sides yields
Xk = (K — ω^Μ + i^k C ) 1ck.
The particular solution satisfies initial conditions given by
Xp(0) = X 0 + 2 real ( ck \ and X p(0) = 2 real i
lωkCk
\k=1
\k=1
Since these conditions usually will not equal the desired values, the particular so­
lution must be combined with what is called the homogeneous or transient solution X h, where
MX h + cXh + K X h = 0,
with
Xh(0) = Do — Xp(0) , Xh(0) = Vo — Xp(0).
The homogeneous solution can be constructed by reducing the original differential equation to first order form. Let Z be the vector of dimension 2n which is the concatenation of X and X = V. Hence, Z = [X; V] and the original equation of motion is
^ = AZ + P( t )
where
A
dt
0 I
- M - 1K - M - 1C
and P
- 1F
The homogeneous differential equation resulting when P = 0 can be solved in terms of the eigenvalues and eigenvectors of matrix A. If we know the eigenvalues Λ j and eigenvectors Uj satisfying
AUj = Λ0 Uj , 1 < j < 2n, then the homogeneous solution can be written as
2n
Z = Σ zjU0e1^.
3=1
The weighting coefficients z3 are computed to satisfy the desired initial conditions which require
[U1, U2, · · · , U2n]
We solve this system of equations for z 1, · · ·, z2n and replace each U3 by z3U3. Then the homogeneous solution is
z1
'Xo — Xp(0)'
Vo — Xp(0) _
z2n
Xh = Σ Uj(l: n)
3=1
n)eXjt
0
n
where U3(l : n) means we take only the first n elements of column j.
In most practical situations, the matrix C is nonzero and the eigenvalues Λ1, · · ·, Λ2η have negative real parts. Then the exponential terms e X]t all decay with increas­
ing time, which is why Xh is often known as the transient solution . In other cases, where the damping matrix C is zero, the eigenvalues Λ 3 are typically purely imagi­
nary, and the homogeneous solution does not die out. In either instance, it is often customary in practical situations to ignore the homogeneous solution because it is usually small when compared to the contribution of the particular solution.
7.1.1 Application to Oscillations of a Vertically Suspended Cable
Let us solve the problem of small transverse vibrations of a vertically suspended cable. This system illustrates how the natural frequencies and mode shapes of a linear system can be combined to satisfy general initial conditions on position and velocity.
The cable in
Figure 7.1 is idealized as a series of n rigid links connected at fric- tionless joints. Two vectors, consisting of link lengths [i 1,i 2, · · · ,i n] and masses [m1,m2, · · · , mn] lumped at the joints, characterize the system properties. The ac­
celerations in the vertical direction will be negligibly small compared to transverse accelerations, because the transverse displacements are small. Consequently, the ten­
sion in the chain will remain close to the static equilibrium value. This means the tension in link i is
We assume that the transverse displacement yt for mass mt is small compared to the total length of the cable. A free body diagram for mass i is shown in Fig­
ure 7.2. The small deflection angles are related to the transverse deflections by θι + 1 = (yl + 1 — yl) i + 1 and θι = (yt — y - ) /i %. Summation of forces shows that the horizontal acceleration is governed by
mlyl = g(bi+ 1/i i +1 ) (yi+ 1 — yt ) — g(bl/i l ) (yt — y i - 1 )
where M is a diagonal matrix of mass coefficients and K is a symmetric tridiagonal matrix. The natural modes of free vibration are dynamical states where each element of the system simultaneously moves with harmonic motion of the same frequency. This means we seek motions of the form Y = U cos(ut), or equivalently Y = U sin(ut), which implies
n
g(bi/i i)yi-1 — g(bi/i i + bi+1/i i+\)y% + g{^%+1/i %+\)y%+1.
In matrix form this equation is
MY + K Y =
0
KU3 = Λ3MU3 where Λ3 = for l < j < n.
Figure 7.1: Transverse Cable Vibration
Solving the eigenvalue problem ( M- 1K) U = XU gives the natural frequencies ω1, · ·· ,ωη and the modal vectors U1, · ·· ,Un. The response to general initial con­
ditions is then obtained by superposition of the component modes. We write
n
Y = cos^3t)U3c3 + sin(w3 t)U3d3/^ ’3
3=1
where the coefficients c1, · · · ,cn and d1, · · · ,dn (not to be confused with Fourier coefficients) are determined from the initial conditions as
[ U1, · · · , Un]
c1
Y (0) , c = U- 1Y (0),
[ U1, · · · , Un]
d1
dn
y (0) , d = u - 1y(0)
The following program determines the cable response for general initial conditions. The natural frequencies and mode shapes are computed along with an animation of the motion.
The cable motion produced when an initially vertical system is given the same initial transverse velocity for all masses was studied. Graphical results of the analysis appear in Figures 7.3 through 7.6. The surface plot in Figure 7.3 shows the cable deflection pattern in terms of longitudinal position and time. Figure 7.4 shows the deflection pattern at two times.
Figure 7.5 traces the motion of the middle and the
c
n
Ti = gbi
Ti+1 = gbi+1
mig
Figure 7.2: Forces on i’th Mass
free end. At t = 1, the wave propagating downward from the support point is about halfway down the cable. By t = 2, the wave has reached the free end and the cable is about to swing back. Finally, traces of cable positions during successive stages of motion appear in
Figure 7.6
.
distance from bottom transverse deflection
Surface Showing Cable Deflection
y axis
Figure 7.3: Surface Showing Cable Deflection
Cable Transverse Deflection at t = 1 and t = 2
transverse displacement
Figure 7.4: Cable Transverse Deflection at t = 1 and t = 2
transverse displacement
Position versus Time for the Cable Middle and End
dimensionless time
Figure 7.5: Position Versus Time for the Cable Middle and End
Trace of Linearized Cable Motion
Figure 7.6: Trace of Cable Motion
MATLAB Example Program cablinea
i: f u n c t i o n c a b l i n e a 2: % Example: c a b l i n e a
3: %...........................................................................
4: % T h i s p r o g r a m u s e s modal s u p e r p o s i t i o n t o 5: % compute t h e dynamic r e s p o n s e o f a c a b l e 6: % s u s p e n d e d a t one end and f r e e a t t h e o t h e r.
7: % The c a b l e i s g i v e n a u n i f o r m i n i t i a l
8: % v e l o c i t y. Time h i s t o r y p l o t s and a n i m a t i o n
9: % o f t h e m o t i o n a r e p r o v i d e d.
10: %
11: % U s e r m f u n c t i o n s r e q u i r e d: i 2: % c a b le m k, u d f r e v i b, c a n i m a t e
13:
i 4: % I n i t i a l i z e g r a p h i c s
i 5: h o l d o f f; a x i s ('n o r m a l'); c l o s e;
16:
i 7: % S e t p h y s i c a l p a r a m e t e r s
i 8: n=30; g r a v t y = 1.; m a s s e s = o n e s ( n,1 )/n;
i 9: l e n g t h s = o n e s ( n,1 )/n;
20:
2 i: % O b t a i n mass and s t i f f n e s s m a t r i c e s 2 2: [ m,k ] = c a b l e m k ( m a s s e s,l e n g t h s,g r a v t y );
23:
24: % A s s i g n i n i t i a l c o n d i t i o n s & t i m e l i m i t
25: % f o r s o l u t i o n
2 6: d s p = z e r o s ( n,1 ); v e l = o n e s ( n,1 );
27: tm i n = 0; tmax=10; n t i m = 3 0;
28:
29: % Compute t h e s o l u t i o n by modal s u p e r p o s i t i o n 30: [ t,u,m o d v c,n a t f r q ] = ...
3 i: u d f r e v i b ( m,k,d s p,v e l,t m i n,t m a x,n t i m ) ;
32:
33: % I n t e r p r e t r e s u l t s g r a p h i c a l l y 34: n t 1 = s u m ( t < = t m i n ); n t 2 = s u m ( t < = t m a x );
35: u = [ z e r o s ( n t i m,1 ),u ];
36: y = c u m s u m ( l e n g t h s ); y = [ 0;y (:) ];
37:
38: % P l o t d e f l e c t i o n s u r f a c e
3 9: d i s p (' '), disp('TRANSVERSE MOTION OF A CABLE') 40: s u r f ( y,t,u ); x l a b e l ('y a x i s'); y l a b e l ('t i m e');
4 i
42:
43
44
45
46:
47:
48:
49
50:
5 i:
52:
53:
54
55
56:
57:
58:
59
60:
6 i
62:
63
64
65
66:
67:
68:
69
70:
7 i
72
73
74
75
76
77:
78
79
80:
8 i
82
83
84
85
z l a b e l ('t r a n s v e r s e d e f l e c t i o n'); t i t l e ('S u r f a c e Showing C a b l e D e f l e c t i o n'); c o l o r m a p ('d e f a u l t'), v i e w ( [ 3 0,3 0 ] ); f i g u r e ( g c f ); d i s p ( ['P r e s s [ E n t e r ] t o s e e t h e c a b l e ',...
'p o s i t i o n a t two t i m e s'] ) p a u s e, % p r i n t - d e p s s u r f a c e
% Show d e f l e c t i o n c o n f i g u r a t i o n a t two t i m e s % Use c l o s e r t i m e i n c r e m e n t t h a n was u s e d % f o r t h e s u r f a c e p l o t s. mtim=4*ntim;
[ t t,u u,m o d v c,n a t f r q ] =...
u d f r e v i b ( m,k,d s p,v e l,t m i n,t m a x,m t i m ); u u = [ z e r o s ( m t i m,1 ),u u ]; t p 1 =.1 * t m a x; t p 2 =.2 * t m a x; s 1 = n u m 2 s t r ( t p 1 ); s 2 = n u m 2 s t r ( t p 2 ); n p 1 = s u m ( t t < = t p 1 ); n p 2 = s u m ( t t < = t p 2 ); u 1 = u u ( n p 1,:); u 2 = u u ( n p 2,:); y p = f l i p u d ( y (:) ); ym=max(yp); p l o t ( u 1,y p,'-',u 2,y p,' ');
y l a b e l ('d i s t a n c e f r o m b o t t o m'); x l a b e l ('t r a n s v e r s e d i s p l a c e m e n t'); t i t l e ( ['C a b l e T r a n s v e r s e D e f l e c t i o n ' ...
'a t t = ',s 1,' and t = ',s 2 ] ); l e g e n d ('t = 1', 't = 2');
x m =.2 * m a x ( [ u 1 (:);u 2 (:) ] ); n t x t = i n t 2 s t r ( n ); n 2 = 1 + f i x ( n/2 ); s t r = s t r v c a t (...
'T h e c a b l e was i n i t i a l l y v e r t i c a l and w a s',... 'g i v e n a u n i f o r m t r a n s v e r s e v e l o c i t y.',...
['A ',n t x t,' l i n k model was u s e d.'] ); t e x t ( x m,.9 * y m,s t r ), f i g u r e ( g c f ); d i s p ( ['P r e s s [ E n t e r ] t o show t h e t i m e ',... 'r e s p o n s e a t t h e m i d d l e and f r e e e n d'] ) p a u s e, % p r i n t - d e p s twoposn
% P l o t t i m e h i s t o r y f o r t h e m i d d l e and t h e end c l f; p l o t ( t t,u u (:,n 2 ),'—',t t,u u (:,n + 1 ),'-'); x l a b e l ('d i m e n s i o n l e s s t i m e'); y l a b e l ('t r a n s v e r s e d i s p l a c e m e n t'); t i t l e ( ['P o s i t i o n v e r s u s Time f o r t h e ' ...
'C a b l e M i ddl e and E n d'] ) l e g e n d ('M i d p o i n t','L o w e r e n d'); f i g u r e ( g c f );
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
d i s p ('P r e s s [ E n t e r ] f o r a m o t i o n t r a c e') p a u s e, % p r i n t - d e p s 2 t i m h i s t
% P l o t a n i m a t i o n o f m o t i o n h i s t o r y c l f; c a n i m a t e ( y,u,t,0,.5 * m a x ( t ),1 );
% p r i n t - d e p s m o t n t r a c
d i s p ('P r e s s [ E n t e r ] t o f i n i s h'), p a u s e, c l o s e; %=============================================
f u n c t i o n [ m,k ] = c a b l e m k ( m a s s e s,l n g t h s,g r a v t y )
%
% [ m,k ] = c a b l e m k ( m a s s e s,l n g t h s,g r a v t y )
%..........................................................................................
% Form t h e mass and s t i f f n e s s m a t r i c e s f o r % t h e c a b l e.
%
% m a s s e s - v e c t o r o f m a s s e s
% l n g t h s - v e c t o r o f l i n k l e n g t h s
% g r a v t y - g r a v i t y c o n s t a n t
% m,k - mass and s t i f f n e s s m a t r i c e s
%
% U s er m f u n c t i o n s c a l l e d: n o n e.
%-----------------------------------------------------------------------------------------
m = d i a g ( m a s s e s );
b = f l i p u d ( c u m s u m ( f l i p u d ( m a s s e s (:) ) ) ) * ...
g r a v t y./l n g t h s; n = l e n g t h ( m a s s e s ); k = z e r o s ( n,n ); k ( n,n ) = b ( n ); f o r i = 1:n - 1
k ( i,i ) = b ( i ) + b ( i + 1 ); k ( i,i + 1 ) = - b ( i + 1 ); k ( i + 1,i ) = k ( i,i + 1 ); end
%=============================================
f u n c t i o n [ t,u,m d v c,n a t f r q ] =...
u d f r e v i b ( m,k,u 0,v 0,t m i n,t m a x,n t )
%
% [ t,u,m d v c,n a t f r q ] = ...
% u d f r e v i b ( m,k,u 0,v 0,t m i n,t m a x,n t )
%....................................................................................................................
% T h i s f u n c t i o n computes undamped n a t u r a l % f r e q u e n c i e s, modal v e c t o r s, and t i m e r e s p o n s e % by modal s u p e r p o s i t i o n. The m a t r i x
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
% d i f f e r e n t i a l e q u a t i o n and i n i t i a l c o n d i t i o n s % a r e %
% m u'' + k u = 0, u ( 0 ) = u 0, u'( 0 ) = v0
%
% m,k - mass and s t i f f n e s s m a t r i c e s
% u 0,v 0 - i n i t i a l p o s i t i o n and v e l o c i t y
% v e c t o r s
% t m i n,t m a x - t i m e l i m i t s f o r s o l u t i o n
% e v a l u a t i o n
% n t - number o f t i m e s f o r s o l u t i o n
% t - v e c t o r o f s o l u t i o n t i m e s
% u - m a t r i x w i t h row j g i v i n g t h e
% s y s t e m r e s p o n s e a t t i m e t ( j )
% mdvc - m a t r i x w i t h columns w h i ch a r e
% modal v e c t o r s
% n a t f r q - v e c t o r o f n a t u r a l f r e q u e n c i e s
%
% U s e r m f u n c t i o n s c a l l e d: n o n e.
%-----------------------------------------------------------------------------------
% C a l l f u n c t i o n e i g t o compute modal v e c t o r s
% and f r e q u e n c i e s
[ m d v c,w ] = e i g ( m\k );
[ w,i d ] = s o r t ( d i a g ( w ) ); w = s q r t ( w );
% A r r a n g e f r e q u e n c i e s i n a s c e n d i n g o r d e r m d v c = m d v c (:,i d ); z = m d v c\[ u 0 (:),v 0 (:) ];
% G e n e r a t e v e c t o r o f e q u i d i s t a n t t i m e s t = l i n s p a c e ( t m i n,t m a x,n t );
% E v a l u a t e t h e d i s p l a c e m e n t a s a % f u n c t i o n o f t i m e u = ( m d v c * d i a g ( z (:,1 ) ) ) * c o s ( w * t ) +...
( m d v c * d i a g ( z (:,2 )./w ) ) * s i n ( w * t ); t = t (:); u = u'; n a t f r q = w;
%===========================================
f u n c t i o n c a n i m a t e ( y,u,t,t m i n,t m a x,n o r u b )
%
% c a n i m a t e ( y,u,t,t m i n,t m a x,n o r u b )
%...............................................................................
% T h i s f u n c t i o n draws an a n i m a t e d p l o t of
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
% d a t a v a l u e s s t o r e d i n a r r a y u. The % d i f f e r e n t columns o f u c o r r e s p o n d t o p o s i t i o n % v a l u e s i n v e c t o r y. The s u c c e s s i v e rows o f u % c o r r e s p o n d t o d i f f e r e n t t i m e s. P a r a m e t e r % t p a u s e c o n t r o l s t h e s p e e d o f t h e a n i m a t i o n.
%
% u - m a t r i x o f v a l u e s f o r which
% a n i m a t e d p l o t s o f u v e r s u s y
% a r e r e q u i r e d
% y - s p a t i a l p o s i t i o n s f o r d i f f e r e n t
% columns o f u
% t - t i m e v e c t o r a t whi ch p o s i t i o n s
% a r e known
% t m i n,t m a x - t i m e l i m i t s f o r g r a p h i n g o f t h e % s o l u t i o n
% n o r u b - p a r a m e t e r whi ch makes a l l
% p o s i t i o n i mages r e m a i n on t h e
% s c r e e n. Only one image a t a
% t i m e shows i f n o r u b i s l e f t o u t.
% A new c a b l e p o s i t i o n a p p e a r s e a c h
% t i m e t h e u s e r p r e s s e s any key
%
% U s er m f u n c t i o n s c a l l e d: n o n e.
%-----------------------------------------------------------------------------------------
% I f n o r u b i s i n p u t,
% a l l images a r e l e f t on t h e s c r e e n i f n a r g i n < 6 r u b o u t = 1; e l s e
r u b o u t = 0; end
% D e t e r m i n e window l i m i t s
u m i n = m i n ( u (:) ); u m a x = m a x ( u (:) ); u d i f = u m a x - u m i n; uav g =.5 * (u m i n + u m ax );
y m i n = m in ( y ); ymax=max(y); y d i f = y m a x - y m i n; yav g =.5 * (y m i n + y m ax );
y w m i n = y a v g -.5 5 * y d i f; ywm ax=yavg+.55*ydif; u w m i n = u a v g -.5 5 * u d i f; uwm ax=uavg+.55*udif; n 1 = s u m ( t < = t m i n ); n 2 = s u m ( t < = t m ax ); t = t ( n 1:n 2 ); u = u ( n 1:n 2,:); u = f l i p l r ( u ); [ n t i m e,n x p t s ] = s i z e ( u );
h o l d o f f; c l a; ey=0; eu=0; a x i s ('s q u a r e');
2 2 1: axis([uwmin,uwmax,ywmin,ywmax] );
2 2 2: a x i s o f f; h o l d on;
2 2 3: t i t l e ('T r a c e o f L i n e a r i z e d C a b l e M o t i o n');
224:
225: % P l o t s u c c e s s i v e p o s i t i o n s
2 2 6: f o r j = 1:n t i m e
2 2 7: u t = u ( j,:); p l o t ( u t,y,'-');
2 2 8: f i g u r e ( g c f ); p a u s e (.5 );
229:
230: % E r a s e image b e f o r e n e x t one a p p e a r s
231: i f r u b o u t & j < n t i m e, c l a, end
232: end
7.2 Direct Integration Methods
Using stepwise integration methods to solve the structural dynamics equation pro­
vides an alternative to frequency analysis methods. If we invert the mass matrix and save the result for later use, the n degree-of-freedom system can be expressed con­
cisely as a first order system in 2 n unknowns for a vector z = [x; v], where v is the time derivative of x. The system can be solved by applying the variable step-size differential equation integrator ode45 as indicated in the following function:
f u n c t i o n [ t,x ] = s t r d y n r k ( t,x 0,v 0,m,c,k,f u n c t i m ) % [ t,x ] = s t r d y n r k ( t,x 0,v 0,m,c,k,f u n c t i m ) g l o b a l Mi C K F n n1 n2 Mi=inv(m); C=c; K=k; F = f u n c t i m; n = s i z e ( m,1 ); n 1 = 1:n; n2=n+1:2*n; [ t,z ] = o d e 4 5 ( @ s d e,t,[ x 0 (:);v 0 (:) ] ); x = z (:,n 1 );
Q______________________________________
%================================
f u n c t i o n z p = s d e ( t,z )
g l o b a l Mi C K F n n1 n2
z p = [ z ( n 2 ); M i * ( f e v a l ( F,t ) - C * z ( n 2 ) - K * z ( n 1 ) ) ];
Q______________________________________
%================================
f u n c t i o n f = f u n c ( t )
% m = e y e ( 3,3 ); k = [ 2,- 1,0;- 1,2,- 1;0,- 1,2 ];
% c=.0 5 * k;
f = [ - 1;0;1 ] * s i n ( 1.4 1 3 * t );
In this function, the inverted mass matrix is stored in a global variable Mi, the damping and stiffness matrices are in C and K, and the forcing function name is stored in a character string called functim. Although this approach is easy to im­
plement, the resulting analysis can be very time consuming for systems involving several hundred degrees of freedom. Variable step integrators make adjustments to control stability and accuracy which can require very small integration steps. Con­
sequently, less sophisticated formulations employing fixed step-size are often em­
ployed in finite element programs. We will investigate two such algorithms derived from trapezoidal integration rules [7, 113]. The two fundamental integration formu­
las [26] needed are:
i'b h h 3
and
/
b h h2 hb
f (t )dt = - [ f ( a) + f ( b )] + — [/ '(a) - f '(&)] + ^/(4)(e2 )
720J
where a < <b and h = b — a. The first formula, called the trapezoidal rule, gives a zero truncation error term when applied to a linear function. Similarly, the second formula, called the trapezoidal rule with end correction , has a zero final term for a cubic integrand.
The idea is to multiply the differential equation by dt, integrate from t to (t + h), and employ numerical integration formulas while observing that M, C, and K are constant matrices, or
/
t + h p t + h p t + h p t+h
V dt + C J X dt + K J X dt = J P(t ) dt
a n d
t+h
t+h
X dt
V dt.
F o r b r e v i t y we u t i l i z e a n o t a t i o n c h a r a c t e r i z e d b y X( t ) = X ο, X( t + h) = Xi, X = X i — X 0. The trapezoidal rule immediately leads to
h h 2
M + - C + - K
t+h
V
P( t) dt — h
h
CV0 + K (Xo + - Vo)
+ O(h3).
Th e l a s t e q u a t i o n i s a b a l a n c e o f i mp u l s e a n d mo me n t u m c h a n g e i n v o l v i n g t h e e f f e c ­
t i v e ma s s ma t r i x
h h2
Me = M + - C + —K
_ 2 4 _
which can be inverted once and used repeatedly i f the step-size is not changed.
To integrate the forcing function we can use the midpoint rule [26] which states that
rb r a + 6'
~2
J b P{t) dt = hP + 0 (h3).
V
Solving for V yields
h h 2 M + - C + — K 2 4
i
P ( t + ^ - CVo - Κ ( x 0 + ^Vo
+ O(h3 ).
Th e v e l o c i t y a n d p o s i t i o n a t (t + h) are then computed as
h
V1 = V0 + V, Xi = Xo + - [Vo + V i ] + O (/? ).
A more accurate formula with truncation error of order h 5 can be developed from the extended trapezoidal rule. This leads to
MV + CX + K
h ~ h 2 ~
^ X + 2 X o ) - - V
t+h
P (t)dt + O(h5)
a n d
h h2 X = - [ V + 2V0] + Y^\Vo- Vi] + Q(h5).
Mu l t i p l y i n g t h e l a s t e q u a t i o n b y M and employing the differential equation to reduce the V0 — Vi terms gives
h h 2
MX = —M[V + 2V0] + - 1 - P + CV + KX] + 0( h5).
Th e s e r e s u l t s c a n b e a r r a n g e d i n t o a s i n g l e ma t r i x e q u a t i o n t o b e s o l v e d f o r X and
V:
- ( | M + ^ C ) ( M - ^ K ) ( M - \\k ) (C + %K)
'V'
X
hMVo + ^ ( P o - P i ) J Pdt — h KX 0
+ O(h5).
A Gauss two-point formula [26] evaluates the force integral consistent with the de­
sired error order so that
/■ t+h h
P(t)dt = - [P(t + ah) + P(t + [3h )] + 0( h5)
Jt 2
where a. = 3 ^ and β = 3+6v/3.
h
7.2.1 Example on Cable Response by Direct Integration
Functions implementing the last two algorithms appear in the following program which solves the previously considered cable dynamics example by direct integra­
tion. Questions of computational efficiency and numerical accuracy are examined for two different step-sizes.
Figures 7.7 and
7.8 present solution times as multiples of the times needed for a modal response solution. The accuracy measures employed
Solution Error For Implicit 2nd Order Integrator
time
Figure 7.7: Solution Error for Implicit 2nd Order Integrator
are described next. Note that the displacement response matrix has rows describ­
ing system positions at successive times. Consequently, a measure of the difference between approximate and exact solutions is given by the vector
e r r o r _ v e c t o r = \b s q r t (\b s u m ( ( ( x _ a p r o x - x _ e x a c t ).~ 2 )') );
Typically this vector has small initial components (near t = 0) and larger compo­
nents (near the final time). The error measure is compared for different integrators and time steps in the figures. Note that the fourth order integrator is more efficient than the second order integrator because a larger integration step can be taken with­
out excessive loss in accuracy. Using h = 0.4 for mckde4i achieved nearly the same accuracy as that given by mckde2i with h = 0.067. However, the computation time for mckde2i was several times as large as that for mckde4i.
In the past it has been traditional to use only second order methods for solving the structural dynamics equation. This may have been dictated by considerations on computer memory. Since workstations widely available today have relatively large memories and can invert a matrix of order two hundred in about half a second, it appears that use of high order integrators may gain in popularity.
The following computer program concludes our chapter on the solution of linear,
solution error measure
Solution Error For Implicit 4th Order Integrator
time
Figure 7.8: Solution Error for Implicit 4th Order Integrator
constant-coefficient matrix differential equations. Then we will study, in the next chapter, the Runge-Kutta method for integrating nonlinear problems.
MATLAB Example Program deislner
i: s f u n c t i o n d e i s l n e r 2: %
3: % Example: d e i s l n e r
4: %................................................................................
5: % S o l u t i o n e r r o r f o r s i m u l a t i o n o f c a b l e 6: % m o t i o n u s i n g a s e c o n d o r a f o u r t h o r d e r 7: % i m p l i c i t i n t e g r a t o r.
8: %
9: % T h i s p r o g r a m u s e s i m p l i c i t s e c o n d o r f o u r t h i o: % o r d e r i n t e g r a t o r s t o compute t h e d y n a m i c a l 11: % r e s p o n s e o f a c a b l e w h i ch i s s u s p e n d e d a t i 2: % one end and i s f r e e a t t h e o t h e r e n d. The i 3: % c a b l e i s g i v e n a u n i f o r m i n i t i a l v e l o c i t y. i 4: % A p l o t o f t h e s o l u t i o n e r r o r i s g i v e n f o r i 5: % two c a s e s where a p p r o x i m a t e s o l u t i o n s a r e i 6: % g e n e r a t e d u s i n g n u m e r i c a l i n t e g r a t i o n r a t h e r i 7: % t h a n modal r e s p o n s e whi ch i s e x a c t.
i 8: %
i 9: % U s er m f u n c t i o n s r e q u i r e d:
2 0: % m c k d e 2 i, m c k d e 4 i, c a b l e m k, u d f r e v i b,
2i: % p l t e r r o r
22:
23: % Choose a model h a v i n g t w e n t y l i n k s o f 24: % e q u a l l e n g t h
25:
26: f p r i n t f (...
27: '\n P l e a s e w a i t: s o l u t i o n t a k e s a w h i l e\n')
2 8: c l e a r a l l
29: n=20; g r a v t y = 1.; n 2 = 1 + f i x ( n/2 );
30: m a s s e s = o n e s ( n,1 )/n; l e n g t h s = o n e s ( n,1 )/n;
3 i:
3 2: % F i r s t g e n e r a t e t h e e x a c t s o l u t i o n by
33: % modal s u p e r p o s i t i o n
34: [ m,k ] = c a b l e m k ( m a s s e s,l e n g t h s,g r a v t y );
35: c = z e r o s ( s i z e ( m ) );
36: d s p = z e r o s ( n,1 ); v e l = o n e s ( n,1 );
37: t 0 = 0; t f i n = 5 0; n t i m = 1 2 6; h = ( t f i n - t 0 )/( n t i m - 1 );
38:
3 9: % Numbers o f r e p e t i t i o n s e a c h s o l u t i o n i s 40: % p e r f o r m e d t o g e t a c c u r a t e cpu t i m e s f o r
4 i
42
43
44
45:
46
47
48
49
50:
5 i
52
53
54
55:
56
57
58
59
60:
6 i:
62
63:
64
65:
66
67:
68
69
70:
7 i
72
73
74
75:
76
77
78
79
80:
8 i
82
83
84
85:
% t h e c h o s e n s t e p s i z e s a r e shown b e l o w.
% P a r a m e t e r j m r may n e e d t o be i n c r e a s e d t o % g i v e r e l i a b l e cpu t i m e s on f a s t c o m p u t e r s
jmr=500;
j 2 = f i x ( j m r/5 0 ); J 2 = f i x ( j m r/2 5 ); j 4 = f i x ( j m r/2 0 ); J 4 = f i x ( j m r/1 0 );
% Loop t h r o u g h a l l s o l u t i o n s r e p e a t e d l y t o % o b t a i n more r e l i a b l e t i m i n g v a l u e s on f a s t % c o m p u t e r s t i c;
f o r j = 1:j m r;
[ t m r,x m r ] = u d f r e v i b ( m,k,d s p,v e l,t 0,t f i n,n t i m );
end
t c p m r = t o c/j m r;
% Second o r d e r i m p l i c i t r e s u l t s i 2 = 1 0; h 2 = h/i 2; t i c; f o r j = 1:j 2
[ t 2,x 2 ] = m c k d e 2 i ( m,c,k,t 0,d s p,v e l,t f i n,h 2,i 2 );
end
t c p 2 = t o c/j 2; t r 2 = t c p 2/t c p m r;
I 2 = 5; H 2 = h/I 2; t i c; f o r j = 1:J 2
[ T 2,X 2 ] = m c k d e 2 i ( m,c,k,t 0,d s p,v e l,t f i n,H 2,I 2 ); end
T c p 2 = t o c/J 2; T r 2 = T c p 2/t c p m r;
% F o u r t h o r d e r i m p l i c i t r e s u l t s i 4 = 2; h 4 = h/i 4; t i c; f o r j = 1:j 4
[ t 4,x 4 ] = m c k d e 4 i ( m,c,k,t 0,d s p,v e l,t f i n,h 4,i 4 ); end
t c p 4 = t o c/j 4; t r 4 = t c p 4/t c p m r;
I 4 = 1; H 4 = h/I 4; t i c; f o r j = 1:J 4
[ T 4,X 4 ] = m c k d e 4 i ( m,c,k,t 0,d s p,v e l,t f i n,H 4,I 4 ); end
T c p 4 = t o c/J 4; T r 4 = T c p 4/t c p m r;
% P l o t e r r o r m e a s u r e s f o r e a c h s o l u t i o n p l t e r r o r ( x m r,t 2,h 2,x 2,T 2,H 2,X 2,...
86: t 4,h 4,x 4,T 4,H 4,X 4,t r 2,T r 2,t r 4,T r 4 )
87:
88: % ========================= = === === ===== === === = =
89:
90: f u n c t i o n [ t,x,t c p ] = ...
9 i: m c k d e 2 i ( m,c,k,t 0,x 0,v 0,t m a x,h,i n c o u t,f o r c )
92: %
93: % [ t,x,t c p ] = ...
94: % m c k d e 2 i ( m,c,k,t 0,x 0,v 0,t m a x,h,i n c o u t,f o r c )
95: %
96: % T h i s f u n c t i o n u s e s a s e c o n d o r d e r i m p l i c i t 97: % i n t e g r a t o r % t o s o l v e t h e m a t r i x d i f f e r e n t i a l 98: % e q u a t i o n
99: % m x''+ c x'+ k x = f o r c ( t )
i o o: % where m,c, and k a r e c o n s t a n t m a t r i c e s and i o i: % f o r c i s an e x t e r n a l l y d e f i n e d f u n c t i o n.
i 0 2: %
i o 3: % I n p u t:
i 0 4: % -------------------
i o 5: % m,c,k m a s s, damping and s t i f f n e s s m a t r i c e s
i o 6: % t 0 s t a r t i n g t i m e
i o 7: % x 0,v 0 i n i t i a l d i s p l a c e m e n t and v e l o c i t y
i o 8: % tmax maximum t i m e f o r s o l u t i o n e v a l u a t i o n
i o 9: % h i n t e g r a t i o n s t e p s i z e
i i o: % i n c o u t number o f i n t e g r a t i o n s t e p s b e t w e e n
i i i: % s u c c e s s i v e v a l u e s o f o u t p u t
i i 2: % f o r c e x t e r n a l l y d e f i n e d t i m e d e p e n d e n t
i i 3: % f o r c i n g f u n c t i o n. T h i s p a r a m e t e r
i i 4: % s h o u l d be o m i t t e d i f no f o r c i n g
i i 5: % f u n c t i o n i s u s e d.
i i 6: %
i i 7: % O u t p u t:
i i 8: % -------------
i i 9: % t t i m e v e c t o r g o i n g f r o m t 0 t o tmax
i 2 o: % i n s t e p s of
i 2 i: % x h * i n c o u t t o y i e l d a m a t r i x of
i 2 2: % s o l u t i o n v a l u e s s u c h t h a t row j
i 2 3: % i s t h e s o l u t i o n v e c t o r a t t i m e t ( j )
i 2 4: % t c p c o m p u t er t i m e f o r t h e c o m p u t a t i o n
i 2 5: %
i 2 6: % U s er m f u n c t i o n s c a l l e d: n o n e.
i 2 7: %-----------------------------------------------------------------------------------------
i 2 8:
i 2 9: i f ( n a r g i n > 9 ); f o r c e = 1; e l s e, f o r c e = 0; end i 3 0: i f n a r g o u t ==3, t c p = c l o c k; end
i 3 i: h b i g = h * i n c o u t;
i 3 2: t = ( t 0:h b i g:t m a x )'; n = l e n g t h ( t ); i 3 3: n s = ( n - 1 ) * i n c o u t; t s = t 0 + h * ( 0:n s )'; i 3 4: x n o w = x 0 (:); v n o w = v 0 (:); i 3 5: n v a r = l e n g t h ( x 0 ); i 3 6: j r o w = 1; j s t e p = 0; h 2 = h/2;
i 3 7:
i 3 8: % Form t h e i n v e r s e o f t h e e f f e c t i v e
i 3 9: % s t i f f n e s s m a t r i x
i 4 0: mnv=h*i nv(m +h2*(c +h2*k));
i 4 i:
i 4 2: % I n i t i a l i z e t h e o u t p u t m a t r i x f o r x i 4 3: x = z e r o s ( n,n v a r ); x ( 1,:) = x n o w'; i 4 4: z r o f o r c = z e r o s ( l e n g t h ( x 0 ),1 ) ;
i 4 5:
i 4 6: % Main i n t e g r a t i o n l o o p
i 4 7: f o r j = 1:n s
i 4 8: t j = t s ( j );t j h = t j + h 2;
i 4 9: i f f o r c e
i 5 0: d v = f e v a l ( f o r c,t j h );
i 5 i: e l s e
i 5 2: d v = z r o f o r c;
i 5 3: end
i 5 4: dv=mnv*(dv-c*vnow-k*(xnow+h2*vnow));
i 5 5: vnext=vnow+dv;xnext=xnow+h2* (vnow+vnext) ;
i 5 6: j s t e p = j s t e p + 1;
i 5 7: i f j s t e p == i n c o u t
i 5 8: j s t e p = 0; j r o w = j r o w + 1; x ( j r o w,:) = x n e x t';
i 5 9: end
i 6 0: xnow=xnext; vnow=vnext;
i 6 i: end
i 6 2: i f n a r g o u t ==3
i 6 3: t c p = e t i m e ( c l o c k,t c p );
i 6 4: e l s e
i 6 5: t c p = [ ];
i 6 6: end
i 6 7:
i 6 8: %=============================================
i 6 9:
i 7 0: f u n c t i o n [ t,x,t c p ] = ...
i 7 i: m c k d e 4 i ( m,c,k,t 0,x 0,v 0,t m a x,h,i n c o u t,f o r c )
i 7 2: %
i 7 3: % [ t,x,t c p ] = ...
i 7 4: % m c k d e 4 i ( m,c,k,t 0,x 0,v 0,t m a x,h,i n c o u t,f o r c )
i 7 5: %
i 7 6:
i 7 7:
i 7 8:
i 7 9:
i 8 0:
i 8 i:
i 8 2
i 8 3:
i 8 4:
i 8 5:
i 8 6
i 8 7:
i 8 8:
i 8 9
i 9 0:
i 9 i:
i 9 2:
i 9 3:
i 9 4:
i 9 5:
i 9 6:
i 9 7:
i 9 8:
i 9 9:
200:
2 0 i:
202
203
204 205: 206
207
208 209 2 i 0: 2 i i: 2 i 2: 2 i 3: 2 i 4: 2 i 5: 2 i 6: 2 i 7: 2 i 8: 2 i 9: 220:
T h i s f u n c t i o n u s e s a f o u r t h o r d e r i m p l i c i t i n t e g r a t o r w i t h f i x e d s t e p s i z e t o s o l v e t h e m a t r i x d i f f e r e n t i a l e q u a t i o n
m x'' + c x' + k x = f o r c ( t ) where m,c, and k a r e c o n s t a n t m a t r i c e s and f o r c i s an e x t e r n a l l y d e f i n e d f u n c t i o n.
I n p u t:
m,c,k m a s s, damping and s t i f f n e s s m a t r i c e s
t 0 s t a r t i n g t i m e
x 0,v 0 i n i t i a l d i s p l a c e m e n t and v e l o c i t y
tmax maximum t i m e f o r s o l u t i o n e v a l u a t i o n
h i n t e g r a t i o n s t e p s i z e
i n c o u t number o f i n t e g r a t i o n s t e p s b e t w e e n
s u c c e s s i v e v a l u e s o f o u t p u t f o r c e x t e r n a l l y d e f i n e d t i m e d e p e n d e n t
f o r c i n g f u n c t i o n. T h i s p a r a m e t e r s h o u l d be o m i t t e d i f no f o r c i n g f u n c t i o n i s u s e d.
O u t p u t:
t c p
t i m e v e c t o r g o i n g f r o m t 0 t o tmax i n s t e p s o f h * i n c o u t m a t r i x o f s o l u t i o n v a l u e s s u c h t h a t row j i s t h e s o l u t i o n v e c t o r a t t i m e t ( j )
c o m p u t er t i m e f o r t h e c o m p u t a t i o n
U s er m f u n c t i o n s c a l l e d: no n e.
t
x
i f n a r g i n > 9, f o r c e = 1; e l s e, f o r c e = 0; end i f n a r g o u t ==3, t c p = c l o c k; end h b i g = h * i n c o u t; t = ( t 0:h b i g:t m a x )'; n = l e n g t h ( t ); n s = ( n - 1 ) * i n c o u t; n v a r = l e n g t h ( x 0 ); j r o w = 1; j s t e p = 0; h 2 = h/2; h 1 2 = h * h/1 2;
% Form t h e i n v e r s e o f t h e e f f e c t i v e s t i f f n e s s % m a t r i x f o r l a t e r u s e.
m12=m-h12*k;
m n v = i n v ( [ [ ( - h 2 * m - h 1 2 * c ),m 1 2 ];
[ m 1 2,( c + h 2 * k ) ] ] );
2 2 i:
222:
223:
224:
225:
226:
227:
228:
229:
230:
2 3 i:
232:
233:
234:
235:
236:
237:
238:
239:
240:
2 4 i:
242
243:
244:
245:
246
247:
248:
249
250:
2 5 i:
252:
253:
254
255:
256:
257:
258
259:
260:
2 6 i:
262:
263:
264:
265:
% The f o r c i n g f u n c t i o n i s i n t e g r a t e d u s i n g a % 2 p o i n t Gauss r u l e
r 3 = s q r t ( 3 ); b 1 = h * ( 3 - r 3 )/6; b 2 = h * ( 3 + r 3 )/6;
% I n i t i a l i z e o u t p u t m a t r i x f o r x and o t h e r % v a r i a b l e s
x n o w = x 0 (:); v n o w = v 0 (:);
t n o w = t 0; z r o f o r c = z e r o s ( l e n g t h ( x 0 ),1 );
i f f o r c e
f n o w = f e v a l ( f o r c,t n o w );
e l s e
f n o w = z r o f o r c;
end
x = z e r o s ( n,n v a r ); x ( 1,:) = x n o w'; f n e x t = f n o w;
% Main i n t e g r a t i o n l o o p f o r j = 1:n s
t n o w = t 0 + ( j - 1 ) * h; t n e x t = t n o w + h; i f f o r c e
f n e x t = f e v a l ( f o r c,t n e x t ); d i 1 = h 1 2 * ( f n o w - f n e x t ); d i 2 = h 2 * ( f e v a l ( f o r c,t n o w + b 1 ) + ...
f e v a l ( f o r c,t n o w + b 2 ) ); z=mnv*[ (di 1+m*(h*vnow)); ( d i 2 - k * ( h * x n o w ) ) ]; f n o w = f n e x t; e l s e
z=mnv*[m*(h*vnow); - k * ( h * x n o w ) ]; end
vnext=vnow + z ( 1:n v a r ); xnext=xnow + z ( ( n v a r + 1 ):2 * n v a r ); j s t e p = j s t e p + 1;
% S ave r e s u l t s e v e r y i n c o u t s t e p s i f j s t e p == i n c o u t
j s t e p = 0; j r o w = j r o w + 1; x ( j r o w,:) = x n e x t'; end
% U p d a te q u a n t i t i e s f o r n e x t s t e p xnow=xnext; vnow=vnext; f n o w = f n e x t; end
i f n a r g o u t = = 3
t c p = e t i m e ( c l o c k,t c p );
e l s e
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
t c p = [ ];
end
%============================================
f u n c t i o n [ m,k ] = c a b l e m k ( m a s s e s,l n g t h s,g r a v t y )
%
% [ m,k ] = c a b l e m k ( m a s s e s,l n g t h s,g r a v t y )
%..........................................................................................
% Form t h e mass and s t i f f n e s s m a t r i c e s f o r % t h e c a b l e.
%
% m a s s e s - v e c t o r o f m a s s e s
% l n g t h s - v e c t o r o f l i n k l e n g t h s
% g r a v t y - g r a v i t y c o n s t a n t
% m,k - mass and s t i f f n e s s m a t r i c e s
%
% U s er m f u n c t i o n s c a l l e d: n o n e.
%-------------------------------------------------------------------------------------
m = d i a g ( m a s s e s );
b = f l i p u d ( c u m s u m ( f l i p u d ( m a s s e s (:) ) ) ) * ...
g r a v t y./l n g t h s; n = l e n g t h ( m a s s e s ); k = z e r o s ( n,n ); k ( n,n ) = b ( n ); f o r i = 1:n - 1
k ( i,i ) = b ( i ) + b ( i + 1 ); k ( i,i + 1 ) = - b ( i + 1 ); k ( i + 1,i ) = k ( i,i + 1 ); end
%============================================
f u n c t i o n p l t e r r o r ( x m r,t 2,h 2,x 2,T 2,H 2,X 2,...
t 4,h 4,x 4,T 4,H 4,X 4,t r 2,T r 2,t r 4,T r 4 )
% p l t e r r o r ( x m r,t 2,h 2,x 2,T 2,H 2,X 2,...
%.......................................................................................
% t 4,h 4,x 4,T 4,H 4,X 4,t r 2,T r 2,t r 4,T r 4 )
%.....................................................................
% P l o t s e r r o r m e a s u r e s showi ng how d i f f e r e n t % i n t e g r a t o r s and t i m e s t e p s compare w i t h % t h e e x a c t s o l u t i o n u s i n g modal r e s p o n s e.
%
% U s er m f u n c t i o n s c a l l e d: none
%-------------------------------------------------------------------------------------
% Compare t h e maximum e r r o r i n any component
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
% a t e a c h t i m e w i t h t h e l a r g e s t d e f l e c t i o n
% o c c u r r i n g d u r i n g t h e c o m p l e t e t i m e h i s t o r y
m a x d = m a x ( a b s ( x m r (:) ) );
e r 2 = m a x ( a b s ( x 2 - x m r )')/m a x d;
E r 2 = m a x ( a b s ( X 2 - x m r )')/m a x d;
e r 4 = m a x ( a b s ( x 4 - x m r )')/m a x d;
E r 4 = m a x ( a b s ( X 4 - x m r )')/m a x d;
p l o t ( t 2,e r 2,'-',T 2,E r 2,'—'); t i t l e ( ['S o l u t i o n E r r o r F o r I m p l i c i t ',...
'2 n d O r d e r I n t e g r a t o r'] ); x l a b e l ('t i m e');
y l a b e l ('s o l u t i o n e r r o r m e a s u r e'); l g 1 = ['h = ', n u m 2 s t r ( h 2 ), ...
', r e l a t i v e cp u t i m e = ', n u m 2 s t r ( t r 2 ) ]; l g 2 = ['h = ', n u m 2 s t r ( H 2 ), ...
', r e l a t i v e cp u t i m e = ', n u m 2 s t r ( T r 2 ) ]; l e g e n d ( l g 1,l g 2,2 ); f i g u r e ( g c f ); d i s p ('P r e s s [ E n t e r ] t o c o n t i n u e'); p a u s e % p r i n t - d e p s d e i s l n e 2
p l o t ( t 4,e r 4,'-',T 4,E r 4,'—'); t i t l e ( ['S o l u t i o n E r r o r F o r I m p l i c i t ',...
'4 t h O r d e r I n t e g r a t o r'] ); x l a b e l ('t i m e');
y l a b e l ('s o l u t i o n e r r o r m e a s u r e'); l g 1 = ['h = ', n u m 2 s t r ( h 4 ), ...
', r e l a t i v e cp u t i m e = ', n u m 2 s t r ( t r 4 ) ]; l g 2 = ['h = ', n u m 2 s t r ( H 4 ), ...
', r e l a t i v e cp u t i m e = ', n u m 2 s t r ( T r 4 ) ]; l e g e n d ( l g 1,l g 2,2 ); f i g u r e ( g c f );
% p r i n t - d e p s d e i s l n e 4 d i s p (' '), d i s p ('A l l D o n e')
%=============================================
% f u n c t i o n [ t,u,m d v c,n a t f r q ] =...
% u d f r e v i b ( m,k,u 0,v 0,t m i n,t m a x,n t )
% See Appe ndix B
Chapiter 8
Integration of Nonlinear Initial Value Problems
8.1 General Concepts on Numerical Integration of Nonlinear Ma­
trix Differential Equations
Methods for solving differential equations numerically are one of the most valu­
able analysis tools now available. Inexpensive computer power and user friendly software are stimulating wider use of digital simulation methods. At the same time, intelligent use of numerically integrated solutions requires appreciation of inherent limitations of the techniques employed. The present chapter discusses the widely used Runge-Kutta method and applies it to some specific examples.
When physical systems are described by mathematical models, it is common that various system parameters are only known approximately. For example, to predict the response of a building undergoing earthquake excitation, simplified formulations may be necessary to handle the elastic and frictional characteristics of the soil and the building. Our observation that simple models are used often to investigate behavior of complex systems does not necessarily amount to a rejection of such procedures. In fact, good engineering analysis depends critically on development of reliable mod­
els which can capture salient features of a process without employing unnecessary complexity. At the same time, analysts need to maintain proper caution regarding trustworthiness of answers produced with computer models. Nonlinear system re­
sponse sometimes changes greatly when only small changes are made in the physical parameters. Scientists today realize that, in dealing with highly nonlinear phenom­
ena such as weather prediction, it is simply impossible to make reliable long term forecasts [45] because of various unalterable factors. Among these are a) uncertainty about initial conditions, b) uncertainty about the adequacy of mathematical mod­
els describing relevant physical processes, c) uncertainty about error contributions arising from use of spatial and time discretizations in construction of approximate numerical solutions, and d) uncertainty about effects of arithmetic roundoff error. In light of the criticism and cautions being stated about the dangers of using numerical solutions, the thrust of the discussion is that idealized models must not be regarded as infallible, and no numerical solution should be accepted as credible without ad­
equately investigating effects of parameter perturbation within uncertainty limits of the parameters. To illustrate how sensitive a system can be to initial conditions, we
might consider a very simple model concerning motion of a pendulum of length t given an initial velocity v0 starting from a vertically downward position. If v 0 ex­
ceeds 2 yfgl, the pendulum will reach a vertically upward position and will go over the top. If vq is less than 2y/gl, the vertically upward position is never reached. Instead, the pendulum oscillates about the bottom position. Consequently, initial velocities of 1.999i f gl and 2.001 yfgi produce quite different system behavior with only a tiny change in initial velocity. Other examples illustrating the difficulties of computing the response of nonlinear systems are cited below. These examples are not chosen to discourage use of the powerful tools now available for numerical in­
tegration of differential equations. Instead, the intent is to encourage users of these methods to exercise proper caution so that confidence in the reliability of results is fully justified.
Many important physical processes are governed by differential equations. Typical cases include dynamics of rigid and flexible bodies, heat conduction, and electrical current flow. Solving a system of differential equations subject to known initial con­
ditions allows us to predict the future behavior of the related physical system. Since very few important differential equations can be solved in closed form, approxima­
tions which are directly or indirectly founded on series expansion methods have been developed. The basic problem addressed is that of accurately computing Y( t + h) when Y(t ) is known, along with a differential equation governing system behavior from time t to (t + h). Recursive application of a satisfactory numerical approx­
imation procedure, with possible adjustment of step-size to maintain accuracy and stability, allows approximate prediction of system response subsequent to the starting time.
Numerical methods for solving differential equations are important tools for an­
alyzing engineering systems. Although valuable algorithms have been developed which facilitate construction of approximate solutions, all available methods are vulnerable to limitations inherent in the underlying approximation processes. The essence of the difficulty lies in the fact that, as long as a finite integration step-size is used, integration error occurs at each time step. These errors sometimes have an accumulative effect which grows exponentially and eventually destroys solution va­
lidity. To some extent, accuracy problems can be limited by regulating step-size to keep local error within a desired tolerance. Typically, decreasing an integration tol­
erance increases the time span over which a numerical solution is valid. However, high costs for supercomputer time to analyze large and complex systems sometimes preclude generation of long time histories which may be more expensive than is practically justifiable.
8.2 Runge-Kutta Methods and the ODE45 Integrator Provided in MATLAB
Formulation of one method to solve differential equations is discussed in this sec­
tion. Suppose a function y(x) satisfies a differential equation of the form y '(x) = f (x, y), subject to y( x0 ) = yo, where f is a known differentiable function. We would like to compute an approximation of y(x 0 + h) which agrees with a Taylor’s series expansion up to a certain order of error. Hence,
y(xo + h) = y(xo, h) + O(hn+ 1 )
wh e r e O(hn+ 1 ) denotes a quantity which decreases at least as fast as hn+1 for small h. Taylor’s theorem allows us to write
y(x 0 + h) = y( x0) + y'(xo)h + ^y"{ x 0 )h2 + 0 (h3)
= yo + f ( xo,yo) h+ ^[fx(xo,yo) + f y(xo,yo)fo]h 2 + 0 (h3)
wh e r e f 0 = f (x0, y0 ). The last formula can be used to compute a second order approximation y( x0 + h), provided the partial derivatives f x and f y can be evaluated. However, this may be quite difficult since the function f (x, y) may not even be known explicitly.
The idea leading to Runge-Kutta integration is to compute y(x 0 + h) by making several evaluations of function f instead of having to differentiate that function. Let us seek an approximation in the form
y(x 0 + h) = y0 + h[kif0 + k i f (x0 + ah, y0 + phfe)].
We c h o o s e k
0
, k
1
, a,
and β
to make y( x
0
+ h)
match the series expansion of y(x)
as well as possible. Since
f (x 0 + ah,y0 + f i hf 0 ) = f + [fx(x0,y0 )a + fy (x0,y0 ) ^ ] h + O( h2 ), we must have
y(x 0 + h) = y0 + h[(k0 + h ) f 0 + h ( f x ( x 0, y0 )a + f y( x 0, yo)βfo)]h + O(h 2 )
= yo + (ko + h ) f o h + [fx(xo, yo)ak 1 + fy(xo, 'μ0 ) ^ β ^ ] Η,2 + O(h3 ).
Th e l a s t r e l a t i o n s h ows t h a t
y(xo + h) = y(xo + h) + O(h3)
p r o v i d e d
k 0 + k i = 1 , a k i = - , /3/ci =
This system of three equations in four unknowns has an infinite number of solutions; one of these is ko = k-ι = a = β = 1. This implies that
y(x 0 + h) = y( x0) + ^[/o + f ( x o + h,y0 + h f 0)]h + 0( h3).
Ne g l e c t i n g t h e t r u n c a t i o n e r r o r O( h3) gives a difference approximation known as Heun’s method [61], which is classified as a second order Runge-Kutta method. Re­
ducing the step-size by h reduces the truncation error by about a factor of ( ^)3 = Of course, the formula can be used recursively to compute approximations to y( x0 + h), y( x 0 + 2h), y( x 0 + 3h),.... In most instances, the solution accuracy de­
creases as the number of integration steps is increased and results eventually become unreliable. Decreasing h and taking more steps within a fixed time span helps, but this also has practical limits governed by computational time and arithmetic roundoff error.
The idea leading to Heun’s method can be extended further to develop higher order formulas. One of the best known is the fourth order Runge-Kutta method described as follows
y(xo + h) = y(xo) + h[k 1 + 2 k2 + 2 k3 + k4 ]/6
where
h h
h = f(xo,yo) , k2 = f(x o + -,yo +
h h
h = f ( x o + 2 >yo + k2~) , k4 = f ( x 0 + h,y 0 + k3 h).
Th e t r u n c a t i o n e r r o r f o r t h i s f o r mu l a i s o r d e r h 5; so, the error is reduced by about a factor of ^ when the step-size is halved. The development of the fourth order Runge-Kutta method is algebraically quite complicated [43]. We note that accuracy of order four is achieved with four evaluations of f
for each integration step. This situation does not extend to higher orders. For instance, an eighth order formula may require twelve evaluations per step. This price of more function evaluations may be worthwhile provided the resulting truncation error is small enough to permit much larger integration steps than could be achieved with formulas of lower order. MATLAB provides the function ode45 which uses variable step-size and employs formulas of order four and five. (Note: In MATLAB 6.x the integrators can output results for an arbitrary time vector using, for instance, even time increments.)
8.3 Step-size Limits Necessary to Maintain Numerical Stability
It can be shown that, for many numerical integration methods, taking too large a step-size produces absurdly large results that increase exponentially with successive
time steps. This phenomenon, known as numerical instability, can be illustrated with the simple differential equation
y'(t) = f (t,y) = Xy
which has the solution y = cext. If the real part of X is positive, the solution becomes unbounded with increasing time. However, a pure imaginary X produces a bounded oscillatory solution, whereas the solution decays exponentially for real(X) < 0. Applying Heun’s method [43] gives
y(t + h)= y(t)
2
This shows that at each integration step the next value of y is obtained by multiplying the previous value by a factor
„ = 1 + (A/,) + (A'*)2
2
which agrees with the first three Taylor series terms of exh. Clearly, the difference relation leads to
yn = yopn.
As n increases, yn will approach infinity unless \p\ < 1. This stability condition can be interpreted geometrically by regarding Xh as a complex variable z and solving for all values of z such that
z 2
1 + Z+ — = ζβτθ , ICI < 1 , ο < θ < 2tt.
Taking ζ = 1 identifies the boundary of the stability region, which is normally a closed curve lying in the left half of the complex plane. Of course, h is assumed to be positive and the real part of X is nonpositive. Otherwise, even the exact solution would grow exponentially. For a given X, the step-size h must be taken small enough to make \ Xh\ lie within the stability zone. The larger \X\ is, the smaller h must be to prevent numerical instability.
The idea illustrated by Heun’s method can be easily extended to a Runge-Kutta method of arbitrary order. A Runge-Kutta method of order n reproduces the exact solution through terms of order n in the Taylor series expansion. The differential equation y' = Xy implies
y(t + h) = y(t)exh
a n d
= + 0 ( ^ + 1 ). k= 0
Consequently, points on the boundary of the stability region for a Runge-Kutta method of order n are found by solving the polynomial
n k
1 - β%θ + Σ 77 = 0 ^ k\
k= 1
2
for a dense set of 0-values ranging from0 to 2π. Using MATLAB’s intrinsic function roots allows easy calculation of the polynomial roots which may be plotted to show the stability boundary. The following short program accomplishes the task. Program output for integrators of order four and six is shown in Figures 8.1 and 8.2. Note that the region for order 4 resembles a semicircle with radius close to 2.8. Using \Xh\ > 2.8, with Runge-Kutta of order 4, would give results which rapidly become unstable. The figures also show that the stability region for Runge-Kutta of order 6 extends farther out on the negative real axis than Runge-Kutta of order 4 does. The root finding process also introduces some meaningless stability zones in the right half plane which should be ignored.
Stability Zone for Explicit Integrator of Order 4
real part of !ι*λ
Figure 8.1: Stability Zone for Explicit Integrator of Order 4
imaginary part of ^ι*λ
Stability Zone for Explicit Integrator of Order 6
real part of Ιι*λ
Figure 8.2: Stability Zone for Explicit Integrator of Order 6
MATLAB Example Program rkdestab
% Example: r k d e s t a b
%.............................................
% T h i s p r o g r a m p l o t s t h e b o u n d a r y o f t h e r e g i o n % o f t h e complex p l a n e g o v e r n i n g t h e maximum % s t e p s i z e whi ch may be u s e d f o r s t a b i l i t y of % a R u n g e - K u t t a i n t e g r a t o r o f a r b i t r a r y o r d e r.
%
% n p t s - a v a l u e d e t e r m i n i n g t h e number of % p o i n t s computed on t h e s t a b i l i t y
% b o u n d a r y o f an e x p l i c i t R u n g e - K u t t a
% i n t e g r a t o r.
% x r a n g - c o n t r o l s t h e s q u a r e window w i t h i n % whi ch t h e d i a g r a m i s drawn.
% [ - 3, 3, - 3, 3] i s a p p r o p r i a t e f o r
% t h e f o u r t h o r d e r i n t e g r a t o r.
%
% U s e r m f u n c t i o n s r e q u i r e d: none
h o l d o f f; c l f; c l o s e;
f p r i n t f ('\n S T A B I L I T Y REGION FOR AN ');
f p r i n t f ('E X P L I C I T RUNGE-KUTTA');
f p r i n t f ('\n INTEGRATOR OF ARBITRARY ');
f p r i n t f ('O R D E R\n\n');
w h i l e 1
d i s p (' ')
n o r d r = i n p u t ('G i v e t h e i n t e g r a t o r o r d e r ? > '); i f i s e m p t y ( n o r d r ) | n o r d r = = 0, b r e a k; end % f p r i n t f ('\n I n p u t t h e number o f p o i n t s ');
% f p r i n t f ('u s e d t o d e f i n e\n');
% n p t s = i n p u t ('t h e b o u n d a r y (100 i s t y p i c a l ) ? > '); n p t s = 1 0 0;
r = z e r o s ( n p t s,n o r d r ); v = 1./g a m m a ( n o r d r + 1:- 1:2 ); d = 2 * p i/( n p t s - 1 ); i = s q r t ( - 1 );
% G e n e r a t e p o l y n o m i a l r o o t s t o d e f i n e t h e % s t a b i l i t y b o u n d a r y f o r j = 1:n p t s
% p o l y n o m i a l c o e f f i c i e n t s v ( n o r d r + 1 ) = 1 - e x p ( i * ( j - 1 ) * d );
% complex r o o t s
41: t = r o o t s ( v ); r ( j,:) = t (:).';
42: end
43:
44: % P l o t t h e b o u n d a r y
45: r e l = r e a l ( r (:) ); i m g = i m a g ( r (:) );
46: w = 1.1 * m a x ( a b s ( [ r e l;i m g ] ) );
47: zoom on; p l o t ( r e l,i m g,'.');
48: a x i s ( [ - w,w,- w,w ] ); a x i s ('s q u a r e');
49: x l a b e l ('r e a l p a r t o f h *\l a m b d a');
50: y l a b e l ('i m a g i n a r y p a r t o f h *\l a m b d a'); 51: n s = i n t 2 s t r ( n o r d r );
5 2: s t = ['S t a b i l i t y Zone f o r E x p l i c i t ' ... 53: 'I n t e g r a t o r o f O r d e r ',n s ];
54: t i t l e ( s t ); g r i d on; f i g u r e ( g c f );
55: % p r i n t - d e p s r k d e s t a b
56: end
57:
58: d i s p (' '); d i s p ('A l l D o n e');
8.4 Discussion of Procedures to Maintain Accuracy by Varying Integration Step-size
When we solve a differential equation numerically, our first inclination is to seek output at even increments of the independent variable. However, this is not the most natural form of output appropriate to maintain integration accuracy. Whenever so­
lution components are changing rapidly, a small time step may be needed, whereas using a small time step might be quite inefficient at times where the solution remains smooth. Most modern ODE programs employ variable step-size algorithms which decrease the integration step-size whenever some local error tolerance is violated and conversely increase the step-size when the increase can be performed without loss of accuracy. If results at even time increments are needed, these can be determined by interpolation of the non-equidistant values. The differential equation integrators pro­
vide the capability to output results at an arbitrary vector of times over the integration interval.
Although the derivation of algorithms to regulate step-size is an important topic, development of these methods is not presented here. Several references [43, 46, 51, 61] discuss this topic with adequate detail. The primary objective in regulating step-size is to gain computational efficiency by taking as large a step-size as possible while maintaining accuracy and minimizing the number of function evaluations.
Practical problems involving a single first order differential equation are rarely encountered. More commonly, a system of second order equations occurs which is then transformed into a system involving twice as many first order equations. Several hundred, or even several thousand dependent variables may be involved. Evaluating the necessary time derivatives at a single time step may require computationally in­
tensive tasks such as matrix inversion. Furthermore, performing this fundamental calculation several thousand times may be necessary in order to construct time re­
sponses over time intervals of practical interest. Integrating large systems of nonlin­
ear differential equations is one of the most important and most resource intensive aspects of scientific computing.
Instead of deriving the algorithms used for step-size control in ode45, we will outline briefly the ideas employed to integrate y '(t) = f (t, y) from t to (t + h). It is helpful to think of y as a vector. For a given time step and y value, the program makes six evaluations of f. These values allow evaluation of two Runge-Kutta for­
mulas, each having different truncation errors. These formulas permit estimation of the actual truncation error and proper step-size adjustment to control accuracy. If the estimated error is too large, the step-size is decreased until the error tolerance is sat­
isfied or an error condition occurs because the necessary step-size has fallen below a set limit. If the estimated error is found to be smaller than necessary, the integra­
tion result is accepted and the step-size is increased for the next pass. Even though this type of process may not be extremely interesting to discuss, it is nevertheless an essential part of any well designed program for integrating differential equations nu­
merically. Readers should become familiar with the error control features employed by ODE solvers. Printing and studying the code for ode45 is worthwhile. Studying the convergence tolerance used in connection with function odeset is also instructive. It should be remembered that solutions generated with tools such as ode45 are vul­
nerable to accumulated errors from roundoff and arithmetic truncation. Such errors usually render unreliable the results obtained sufficiently far from the starting time.
This chapter concludes with the analysis of several realistic nonlinear problems having certain properties of their exact solutions known. These known properties are compared with numerical results to assess error growth. The first problem involves an inverted pendulum for which the loading function produces a simple exact dis­
placement function. Examples concerning top dynamics, a projectile trajectory, and a falling chain are presented.
8.5 Example on Forced Oscillations of an Inverted Pendulum
The inverted pendulum in
Figure 8.3 involves a weightless rigid rod of length l which has a mass m attached to the end. Attached to the mass is a spring with stiffness constant k and an unstretched length of γΐ. The spring has length l when the pendulum is in the vertical position. Externally applied loads consist of a driv­
ing moment M(t ), the particle weight, and a viscous damping moment cl 2θ. The differential equation governing the motion of this system is
θ = -(c/m ) 0 + (g/l) sin(0) + M( t )/( ml 2) — (2 k/m) sin(0)(1 — α/λ)
Figure 8.3: Forced Vibration of an Inverted Pendulum
where
Λ = λ/5 — 4cos(0).
This system can be changed to a more convenient form by introducing dimensionless variables. We let t = ( y/Tfg)r where r is dimensionless time. Then
θ = —αθ + 8Ϊη(θ) + P ( τ) — β βΐη(θ)(1 — γ/λ)
wh e r e
a = (c/m)\JT[g = viscous damping factor, β = 2 ( k/m)/(g/l ),
A = s/5 — 4 c o s ( 0 ), γ = (unstretched spring length)/l,
P(τ) = M/(mgl) = dimensionless driving moment.
It is interesting to test how well a numerical method can reconstruct a known exact solution for a nonlinear function. Let us assume that the driving moment M ( τ ) produces a motion having the equation
for arbitrary θ0 and ω. Then
and
θε(τ) = θ 0 βίη(ωτ)
θε( τ) = ωθ0 €θβ(ωτ)
e ( τ) = —ω2θ£
Co ns e q ue nt l y, t h e n e c e s s a r y d r i v i n g mo me n t i s
Ρ( τ) = —ω2θ& — sin(0e) + γωθ$ cos(wr) + β sin(0e) 1 — 7/ v^5^Tcos(^)
Applying this forcing function, along with the initial conditions
θ(
0
) =
0
, θ(
0
) = θ0ω
s h o u l d r e t u r n t h e s o l u t i o n θ = θε( τ). For a specific numerical example we choose θ0 = π/8, ω = 0.5, and four different combinations of β, γ, and tol. The second order differential equation has the form θ = f (τ, θ, θ). This is expressed as a first order matrix system by letting y \ = θ, y 2 = θ, which gives
yi = y 2 , y 2 = f (j,y i,y2 ).
A f u n c t i o n d e s c r i b i n g t h e s y s t e m f o r s o l u t i o n b y o d e 4 5 i s p r o v i d e d a t t h e e n d o f t hi s s e c t i on. P a r a me t e r s θ0, ω0, α, ζ, and β are passed as global variables.
We can examine how well the numerically integrated θ match θ e by using the error measure
\θ(τ ) - θβ(τ ^.
Furthermore, the exact solution satisfies
θ2 + (θε/ω) 2 = θ2.
P l o t t i n g θ/(θ0 ω) on a horizontal axis and θ/θ0 on a vertical axis should produce a unit circle. Violation of that condition signals loss of solution accuracy.
How certain physical parameters and numerical tolerances affect terms in this problem can be demonstrated by the following four data cases:
1. The spring is soft and initially unstretched. A liberal integration tolerance is used.
2. The spring is soft and initially unstretched. A stringent integration tolerance is used.
3. The spring is stiff and initially stretched. A liberal integration tolerance is used.
4. The spring is stiff and initially stretched. A stringent integration tolerance is used.
The curves in
Figure 8.4 show the following facts:
1. When the spring is unstretched initially, the numerical solution goes unstable quickly.
2. Stretching the spring initially and increasing the spring constant improves nu­
merical stability of the solution.
3. Decreasing the integration tolerance increases the time period over which the solution is valid.
An additional curve illustrating the numerical inaccuracy of results for Case 1 ap­
pears in Figure 8.5
. A plot of θ( τ) versus θ(τ)/ω should produce a circle. However, solution points quickly depart from the desired locus.
error measure
Error Growth in Numerical Solution
dimensionless time
Figure 8.4: Error Growth in Numerical Solution
θ
θ v e rs u s ( θ’(τ) / ω ) for C a s e One
θ’(τ)/ω
Figure 8.5: θ versus (θ'(τ )/ω) for Case One
MATLAB Example Program prun
i: f u n c t i o n p r u n 2: % Example: p r u n
4: % Dynamics o f an i n v e r t e d pendulum i n t e g r a t e d 5: % by u s e o f od e4 5.
6: %
7: % U s er m f u n c t i o n s r e q u i r e d: p i n v e r t, mom
8:
9: g l o b a l n c a l
i o: t h 0 = p i/8; w=.5; tmax=30; n c a l = 0;
11:
i 2: f p r i n t f ('\n F O R C E D OSCILLATION OF AN '); i 2: f p r i n t f ('I N V E R T E D PENDULUM\n'); i 4: f p r i n t f ('\n N o t e: G e n e r a t i n g f o u r s e t s o f\n'); i 5: f p r i n t f ('n u m e r i c a l r e s u l t s t a k e s a w h i l e.\n');
i6:
i 7: % l o o s e s p r i n g w i t h l i b e r a l t o l e r a n c e i 8: a l p = 0.1; b e t = 1.0; gam=1.0; t o l = 1.e - 4; i 9: a 1 = n u m 2 s t r ( a l p ); b 1 = n u m 2 s t r ( b e t );
2 0: g 1 = n u m 2 s t r ( g a m ); e 1 = n u m 2 s t r ( t o l );
2 i: o p t i o n s = o d e s e t ('R e l T o l',t o l );
2 2: [ t 1,z 1 ] = ...
2 2: o d e 4 5 ( @ p i n v e r t,[ 0,t m a x ],[ 0;w * t h 0 ],...
24: o p t i o n s,a l p,b e t,g a m,t h 0,w ) ;
25: n 1 = n c a l; n c a l = 0;
26:
27: % l o o s e s p r i n g w i t h s t r i n g e n t t o l e r a n c e 2 8: a l p = 0.1; b e t = 1.0; gam=1.0; t o l = 1.e - 1 0;
29: a 2 = n u m 2 s t r ( a l p ); b 2 = n u m 2 s t r ( b e t );
2 0: g 2 = n u m 2 s t r ( g a m ); e 2 = n u m 2 s t r ( t o l );
2 i: o p t i o n s = o d e s e t ('R e l T o l',t o l );
2 2: [ t 2,z 2 ] = ...
2 2: o d e 4 5 ( @ p i n v e r t,[ 0,t m a x ],[ 0;w * t h 0 ],...
24: o p t i o n s,a l p,b e t,g a m,t h 0,w ) ;
25: n 2 = n c a l; n c a l = 0;
26:
2 7: % t i g h t s p r i n g w i t h l i b e r a l t o l e r a n c e 2 8: a l p = 0.1; b e t = 4.0; gam=0.5; t o l = 1.e - 4;
29: a 3 = n u m 2 s t r ( a l p ); b 3 = n u m 2 s t r ( b e t );
40: g 3 = n u m 2 s t r ( g a m ); e 3 = n u m 2 s t r ( t o l );
4 i
42:
42
44
45
46:
47
48
49
50:
5 i:
52:
52
54
55
56:
57:
58
59
60:
6 i
62:
62
64
65
66:
67
68
69
70:
7 i
72:
72
74
75
76:
77
78
79
80:
8 i
82:
82
84
85
o p t i o n s = o d e s e t ('R e l T o l',t o l );
[ t 3,z 3 ] = ... o d e 4 5 ( @ p i n v e r t,[ 0,t m a x ],[ 0;w * t h 0 ],... o p t i o n s,a l p,b e t,g a m,t h 0,w ); n 3 = n c a l; n c a l = 0;
% t i g h t s p r i n g w i t h s t r i n g e n t t o l e r a n c e a l p = 0.1; b e t = 4.0; gam=0.5; t o l = 1.e - 1 0; a 4 = n u m 2 s t r ( a l p ); b 4 = n u m 2 s t r ( b e t ); g 4 = n u m 2 s t r ( g a m ); e 4 = n u m 2 s t r ( t o l ); o p t i o n s = o d e s e t ('R e l T o l',t o l );
[ t 4,z 4 ] = ... o d e 4 5 ( @ p i n v e r t,[ 0,t m a x ],[ 0;w * t h 0 ],... o p t i o n s,a l p,b e t,g a m,t h 0,w ); n 4 = n c a l; n c a l = 0; s a v e p i n v e r t.m a t;
% P l o t r e s u l t s c l f; s e m i l o g y ( ...
t 1,a b s ( z 1 (:,1 )/t h 0 - s i n ( w * t 1 ) ),'- r',... t 2,a b s ( z 2 (:,1 )/t h 0 - s i n ( w * t 2 ) ),'—g',... t 3,a b s ( z 3 (:,1 )/t h 0 - s i n ( w * t 3 ) ),'-.b',... t 4,a b s ( z 4 (:,1 )/t h 0 - s i n ( w * t 4 ) ),':m'); t i t l e ('E r r o r Growth i n N u m e r i c a l S o l u t i o n') x l a b e l ('d i m e n s i o n l e s s t i m e'); y l a b e l ('e r r o r m e a s u r e');
c 1 = ['C a s e 1: a l p =',a 1,', b e t =',b 1,', g a m =', ...
g 1,', t o l =',e 1 ]; c 2 = ['C a s e 2: a l p =',a 2,', b e t =',b 2,', g a m =', ...
g 2,', t o l =',e 2 ]; c 3 = ['C a s e 3: a l p =',a 3,', b e t =',b 3,', g a m =', ...
g 3,', t o l =',e 3 ]; c 4 = ['C a s e 4: a l p =',a 4,', b e t =',b 4,', g a m =', ...
g 4,', t o l =',e 4 ]; l e g e n d ( c 1,c 2,c 3,c 4,4 ); s h g
d u m = i n p u t ('\n P r e s s [ E n t e r ] t o c o n t i n u e\n','s'); % p r i n t - d e p s p i n v e r t
% p l o t a p h a s e d i a g r a m f o r c a s e 1 c l f; p l o t ( z 1 (:,2 )/w,z 1 (:,1 ) ); a x i s ('s q u a r e'); a x i s ( [ - 1,1,- 1,1 ] ); x l a b e l ('\t h e t a''(\t a u )/\o m e g a'); y l a b e l ('\t h e t a'); t i t l e ( ['\t h e t a v e r s u s ( \t h e t a''(\t a u ) / ' ...
'\o m e g a ) f o r Case O n e'] ); f i g u r e ( g c f ); % p r i n t - d e p s c r c l p l t d i s p (' '); d i s p ('A l l D o n e');
87: % ========================= = === === ===== === ===
88:
89: f u n c t i o n z d o t = p i n v e r t ( t,z,a l p,b e t,g a m,t h 0,w )
90: %
9 i: % z d o t = p i n v e r t ( t,z,a l p,b e t,g a m,t h 0,w )
92: %
9 2: % E q u a t i o n o f m o t i o n f o r t h e pendulum
94: %
95: % t - t i m e v a l u e
96: % z - v e c t o r [ t h e t a ; t h e t a d o t ]
97: % a l p,b e t,g a m,t h 0,w 98: % - p h y s i c a l p a r a m e t e r s i n t h e
99: % d i f f e r e n t i a l e q u a t i o n
i 0 0: % z d o t - t i m e d e r i v a t i v e o f z
i 0 i: %
i 0 2: % U s er m f u n c t i o n s c a l l e d: mom
i 0 2: %-------------------------------------------------------------------------------------------------------------------------------------------------
i 0 4:
i 0 5: g l o b a l n c a l
i 0 6: n c a l = n c a l + 1; t h = z ( 1 ); t h d = z ( 2 ); i 0 7: c = c o s ( t h ); s = s i n ( t h ); l a m = s q r t ( 5 - 4 * c ); i 0 8: z d o t = [ t h d; m o m ( t,a l p,b e t,g a m,t h 0,w ) + ... i 0 9: s - a l p * t h d - b e t * s * ( 1 - g a m/l a m ) ];
i i 0:
i i i: %===========================================
i i 2:
i i 2: f u n c t i o n m e = m o m ( t,a l p,b e t,g a m,t h 0,w )
i i 4: %
i i 5: % m e = m o m ( t,a l p,b e t,g a m,t h 0,w )
i i 6: %
i i 7: % t - t i m e
i i 8: % a l p,b e t,g a m,t h 0,w
i i 9: % - p h y s i c a l p a r a m e t e r s i n t h e
i 2 0: % d i f f e r e n t i a l e q u a t i o n
i 2 i: % me - d r i v i n g moment n e e d e d t o p r o d u c e
i 2 2: % e x a c t s o l u t i o n
i 2 2: %
i 2 4: % U s er m f u n c t i o n s c a l l e d: n o n e.
i 2 5: %-----------------------------------------------------------------------------------
i 2 6:
i 2 7: t h = t h 0 * s i n ( w * t );
i 2 8: t h d = w * t h 0 * c o s ( w * t ); t h d d = - t h * w ~ 2; i 2 9: s = s i n ( t h ); c = c o s ( t h ); l a m = s q r t ( 5 - 4 * c ); i 2 0: m e = t h d d - s + a l p * t h d + b e t * s * ( 1 - g a m/l a m );
86:
8.6 Dynamics of a Spinning Top
The dynamics of a symmetrical spinning top can be analyzed simply by computing the path followed by the gravity center in Cartesian coordinates. Consider a top spinning with its apex (or tip) constrained to remain at the origin. The gravity center lies at position r along the axis of symmetry and the only applied forces are the weight —mgk through the gravity center and the support reaction at the tip of the top. The inertial properties involve a moment of inertia J a about the symmetry axis and a transverse inertial moment J t relative to an axis normal to the symmetry axis and passing through the apex of the top. The velocity of the gravity center and the angular velocity Ω are related by1
v = r = Ω x r.
Thi s i mp l i e s t h a t Ω c a n b e e x p r e s s e d i n t e r ms o f r a d i a l a n d t r a n s v e r s e c o mp o n e n t s as
Ω = i - 2 rv x v + i - l war
wh e r e i = |r| and ωα is the magnitude of the angular velocity component in the radial direction. The angular momentum with respect to the origin is therefore
H = Jti- 2 r x v + Jai - 1^ ar and the potential plus kinetic energy is given by
K = mgz +
Jti 2V ■ V + Jg^g 2
where z is the height of the gravity center above the origin.
The equations of motion can be found using the principle that the moment of all applied forces about the origin must equal the time rate of change of the correspond­
ing angular momentum. Hence
M = Jti- 2 r x a + Jai - 1 l^aV + ωar]
wh e r e a = V = r is the total acceleration of the gravity center. The radial component of the last equation is obtainable by a dot product with r to give
r · M = JaiiOa
wh e r e s i mpl i f i c a t i o n s r e s u l t b e c a u s e r · (r x a) = 0 and r · v = 0. The remaining components of M for the transverse direction result by taking r x M and noting that
r x (r x a) = (r · a)r — i2a = - i 2at
1In this section the quantities v, r, Ω, H, M, and a all represent vector quantities.
where at is the vector component of total acceleration normal to the direction of r. This leads to
r x M = —Jtat + Jai- 1ωa r x v.
Si n c e t h e g r a v i t y c e n t e r mo ve s o n a s p h e r i c a l s u r f a c e o f r a d i u s i centered at the origin, the radial acceleration is given by
ar = —v · v i-2r
and the total acceleration equation becomes
r x M Jai- a is—2
a = ------ -------1------- r x v — v ■ v (' r.
Jt Jt
I n t h e c a s e s t u d i e d h e r e, o n l y t h e b o d y we i g h t —mgk causes a moment about the origin so
M = —mg r x k , r · M = 0
and
r x M = —mg
zr — i 2k
Th e r a d i a l c o mp o n e n t o f t h e mo me n t e q u a t i o n s i mp l y gi ve s ω a = 0, so the axial component of angular velocity retains its initial value throughout the motion. Integrating the differential equations
numerically subject to appropriate initial conditions produces a trajectory of the grav­
ity center motion. The simple formulation presented here treats x, y, and z as if they were independent variables even though
x 2 + y 2 + z 2 = i 2 , xvx + yvy + zvz = 0
are implied. The type of analysis traditionally used in advanced dynamics books [48] would employ Euler angles, thereby assuring exact satisfaction of | r | = i. The accu­
racy of the solution method proposed here can be checked by finding a) whether the total energy of the system remains constant and b) whether the component of angu­
lar momentum in the z -direction remains constant. However, even when constraint conditions are satisfied exactly, reliability of numerical simulations of nonlinear sys­
tems over long time periods becomes questionable due to accumulated inaccuracies caused by arithmetic roundoff and the approximate nature of integration formulas.
The program toprun integrates the equations of motion and interprets the results. This program reads data to specify properties of a conical top along with the initial position and the angular velocity. Intrinsic function ode45 is employed to integrate the motion equation defined in function topde. The path followed by the gravity center is plotted and error measures regarding conservation of energy and angular momentum are computed.
Figures 8.6
and
8.7 show results for a top having prop­
erties given by the test case suggested in the interactive data input. A top which
Path of the Top Gravity Center
Figure 8.6: Path of the Top Gravity Center
has its symmetry axis initially horizontal along the y-axis is given an angular veloc­
ity of [0,10, 2]. Integrating the equation of motion with an error tolerance of 10 - 8 leads to the response shown in the Figure 8.6. Error measures computed regarding the fluctuation in predicted values of total energy and angular momentum about the z-axis (Figure 8.7
) fluctuate about one part in 100,000. It appears that the analysis employing Cartesian coordinates does produce good results.
percent variation
time
Figure 8.7: Variation in Total Energy and z-axis Angular Momentum
Program Output and Code Program Toprun
f u n c t i o n t o p r u n % Example: t o p r u n
%......................................
%
% Example t h a t a n a l y z e s t h e r e s p o n s e o f a % s p i n n i n g c o n i c a l t o p.
%
% U s er m f u n c t i o n s r e q u i r e d:
% t o p d e, c u b r a n g e, i n p u t v
d i s p (' ');
d i s p ( ['* * * Dynamics o f a Homogeneous ', ...
'C o n i c a l Top * * *'] ); d i s p (' '); d i s p ( ['I n p u t t h e g r a v i t y c o n s t a n t and t h e ', ...
'b o d y w e i g h t ( t r y 3 2.2,5 )'] ); [ g r a v,w t ] = i n p u t v ('? '); m a s s = w t/g r a v; t m p = z e r o s ( 3,1 ); d i s p (' ');
d i s p ( ['I n p u t t h e h e i g h t and b a s e r a d i u s ', ...
'( t r y 1,.5 )'] );
[ h t,r b ] = i n p u t v ('? '); l e n =.7 5 * h t; j t r a n s = 3 * m a s s/2 0 * ( r b * r b + 4 * h t * h t ); j a x i a l = 3 * m a s s * r b * r b/1 0; d i s p (' ');
d i s p ( ['I n p u t a v e c t o r a l o n g t h e i n i t i a l ', ...
'a x i s d i r e c t i o n ( t r y 0,1,0 )'] ); [ t m p ( 1 ),t m p ( 2 ),t m p ( 3 ) ] = i n p u t v ('? '); e 3 = t m p (:)/n o r m ( t m p ); r 0 = l e n * e 3; d i s p (' ');
d i s p ( ['I n p u t t h e i n i t i a l a n g u l a r v e l o c i t y ', ...
'( t r y 0,1 0,2 )'] ); [ t m p ( 1 ),t m p ( 2 ),t m p ( 3 ) ] = i n p u t v ('? '); omega0=tmp; o m e g a x = e 3'* o m e g a 0 (:); r d o t 0 = c r o s s ( o m e g a 0,r 0 ); z 0 = [ r 0 (:);r d o t 0 (:) ]; u z = [ 0;0;1 ]; c 1 = w t * l e n ~ 2/j t r a n s; c 2 = o m e g a x * j a x i a l/j t r a n s; d i s p (' ');
d i s p ( ['I n p u t t f i n a l,a n d t h e i n t e g r a t i o n ', ...
't o l e r a n c e ( t r y 4.2, 1 e - 8 )'] ); [ t f i n l,t o l ] = i n p u t v ('? '); d i s p (' '); f p r i n t f ( ...
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:
74
75
76
77:
78
79
80:
81:
82:
83:
84:
85:
% I n t e g r a t e t h e e q u a t i o n s o f m o t i o n o d e o p t n = o d e s e t ('R e l T o l',t o l ); [ t o u t,z o u t ] = o d e 4 5 ( @ t o p d e,[ 0,t f i n l ],z 0,...
o d e o p t n,u z,c 1,c 2 ); t = t o u t; x = z o u t (:,1 ); y = z o u t (:,2 ); z = z o u t (:,3 ); v x = z o u t (:,4 ); v y = z o u t (:,5 ); v z = z o u t (:,6 );
% Compute t o t a l e n e r g y and a n g u l a r momentum c 3 = j t r a n s/( l e n * l e n ); t a x i a l = j a x i a l/2 * o m e g a x ~ 2; r = z o u t (:,1:3 )'; v = z o u t (:,4:6 )'; e t o t a l = ( w t * r ( 3,:) + t a x i a l + c 3/2 * s u m ( v.* v ) )'; h = ( j a x i a l * o m e g a x/l e n * r + c 3 * c r o s s ( r,v ) )';
% P l o t t h e p a t h o f t h e g r a v i t y c e n t e r c l f; a x i s ('e q u a l');
a x i s ( c u b r a n g e ( [ x (:),y (:),z (:) ] ) ); p l o t 3 ( x,y,z ); t i t l e ('P a t h o f t h e Top G r a v i t y C e n t e r'); x l a b e l ('x a x i s'); y l a b e l ('y a x i s'); z l a b e l ('z a x i s'); g r i d on; f i g u r e ( g c f ); d i s p (' '); d i s p (...
'P r e s s [ E n t e r ] t o p l o t e r r o r m e a s u r e s'), p a u s e
% p r i n t - d e p s t o p p a t h
n = 2:l e n g t h ( t );
% Compute e n e r g y and a n g u l a r momentum e r r o r % q u a n t i t i e s and p l o t r e s u l t s
e t = e t o t a l ( 1 ); e n r g e r = a b s ( 1 0 0 * ( e t o t a l ( n ) - e t )/e t ); h z s = a b s ( h ( 1,3 ) );
a n g m z e r = a b s ( 1 0 0 * ( h ( n,3 ) - h z s )/h z s ); v e c = [ e n r g e r (:);a n g m z e r (:) ]; m i n v = m i n ( v e c ); maxv=max(vec);
c l f;
s e m i l o g y ( t ( n ),e n r g e r,'- r',t ( n ),a n g m z e r,':m'); a x i s ('n o r m a l'); x l a b e l ('t i m e'); y l a b e l ('p e r c e n t v a r i a t i o n');
t i t l e ( ['P e r c e n t V a r i a t i o n i n T o t a l E ner gy ', ...
'a n d z - a x i s A n g u l a r Momentum']); l e g e n d (' E ner gy (Upper C u r v e )', ...
' Ang. Mom. (Bottom C u r v e )',4 ); f i g u r e ( g c f ), p a u s e % p r i n t - d e p s t o p v a r
'P l e a s e w a i t f o r s o l u t i o n o f e q u a t i o n s.\n');
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
d i s p (' '), d i s p ('A l l D o n e') %==========================
f u n c t i o n z d o t = t o p d e ( t,z,u z,c 1,c 2 )
%
% z d o t = t o p d e ( t,z,u z,c 1,c 2 )
%% ~~~~~~~~~~~~~~~
% T h i s f u n c t i o n d e f i n e s t h e e q u a t i o n o f m o t i o n % f o r a s y m m e t r i c a l t o p. The v e c t o r z e q u a l s % [ r (:);v (:) ] whi ch c o n t a i n s t h e C a r t e s i a n % components o f t h e g r a v i t y c e n t e r r a d i u s and % i t s v e l o c i t y.
%
% t - t h e t i m e v a r i a b l e
% z - t h e v e c t o r [x; y; z; v x; v y; vz]
% uz - t h e v e c t o r [ 0;0;1 ]
% c1 - w t * l e n ~ 2/j t r a n s
% c2 - o m e g a x * j a x i a l/j t r a n s
%
% z d o t - t h e t i m e d e r i v a t i v e o f z %
% U s er m f u n c t i o n s c a l l e d: none
%-----------------------------------------------------------------------------------------
z = z (:); r = z ( 1:3 ); l e n = n o r m ( r ); u r = r/l e n;
% Make c e r t a i n t h e i n p u t v e l o c i t y i s % p e r p e n d i c u l a r t o r v = z ( 4:6 ); v = v - ( u r'* v ) * u r; v d o t = - c 1 * ( u z - u r * u r ( 3 ) ) + c 2 * c r o s s ( u r,v ) - ...
( ( v'* v )/l e n ) * u r;
z d o t = [ v;v d o t ];
%=
% f u n c t i o n v a r a r g o u t = i n p u t v ( p r o m p t )
% See Appe ndix B
% ===================================
% f u n c t i o n r a n g e = c u b r a n g e ( x y z,o v r s i z ) % See Appe ndix B
8.7 Motion of a Projectile
The problem of aiming a projectile to strike a distant target involves integrating a system of differential equations governing the motion and adjusting the initial incli­
nation angle to achieve the desired hit [101]. A reasonable model for the projectile motion assumes atmospheric drag proportional to the square of the velocity. Conse­
quently, the equations of motion are
vx = -cvvx , vy = —g — cvvy , x =
y = vy
where g is the gravity constant and c is a ballistic coefficient depending on such physical properties as the projectile shape and air density.
The natural independent variable in the equations of motion is time. However, horizontal position x is a more desirable independent variable, since the target will be located at some distant point ( xf ,y f ) relative to the initial position (0,0 ) where the projectile is launched. We can formulate the differential equations in terms of x by using the relationship
dt
1
dx = vr dt or = —.
Then
dvy
dy_ _ Vy_ ___
dx vx dt
and the equations of motion become
dy_
dx
dt
dx
1
dvx
dx
dx
dvy dvx
dx dt
dv
___y_
dx
dvx
dx
— (g + cvvy )
Taking a vector z defined by
ή y;t]
leads to a first order matrix differential equation
dz
dx
[—cvvx; —(g + <
,; i]
where
v = \ vx + v
y
The reader should note that an ill-posed problem can occur if the initial velocity of the projectile is not large enough so that the maximum desired value of x is reached before vx is reduced to zero from atmospheric drag. Consequently, error checking is needed to handle such a circumstance. The functions traject and projcteq em­
ploy intrinsic function ode45 to compute the projectile trajectory. Graphical results
v
x
v
x
v
v
v
y
cv
v
v
v
x
x
x
z v
v
x
v
y
v
x
Projectile Trajectory f o r Velocity Squared Drag
x axis
Figure 8.8: Projectile Trajectory for v 2 Drag Condition
produced by the default data case appear in Figure 8.8. The function traject will be employed again in Chapter 12 for an optimization problem where a search procedure is used to compute the initial inclination angle needed to hit a target at some speci­
fied distant position. In this section we simply provide the functions to integrate the equations of motion.
Program Output and Code Function traject
i: f u n c t i o n [ y,x,t ] = t r a j e c t ...
2: ( a n g l e,v i n i t,g r a v t y,c d r a g,x f i n l,n o p l o t )
3: % [ y,x,t ] = t r a j e c t ...
4: % ( a n g l e,v i n i t,g r a v t y,c d r a g,x f i n l,n o p l o t )
5: %....................................................................................................................
6: %
7: % T h i s f u n c t i o n i n t e g r a t e s t h e d y n a m i c a l 8: % e q u a t i o n s f o r a p r o j e c t i l e s u b j e c t e d t o 9: % g r a v i t y l o a d i n g and a t m o s p h e r i c d r a g i o: % p r o p o r t i o n a l t o t h e s q u a r e o f t h e v e l o c i t y.
i i:
12
i 3:
14
15
16
17
18
19
2o:
21:
22
23:
24
25:
26
27:
28
29
3o:
31:
32
33
34
35:
36
37
38
39
4o:
41:
42
43
44
45:
46
47
48
49
5o:
51:
52
53
54
55:
% a n g l e - i n i t i a l i n c l i n a t i o n o f t h e % p r o j e c t i l e i n d e g r e e s
% v i n i t - i n i t i a l v e l o c i t y o f t h e p r o j e c t i l e % (m uzz l e v e l o c i t y )
% g r a v t y - t h e g r a v i t a t i o n a l c o n s t a n t % c d r a g - d r a g c o e f f i c i e n t s p e c i f y i n g t h e d r a g % f o r c e p e r u n i t mass whi ch e q u a l s
% c d r a g * v e l o c i t y ~ 2.
% x f i n l - t h e p r o j e c t i l e i s f i r e d t o w a r d t h e % r i g h t f r o m x=0. x f i n l i s t h e
% l a r g e s t x v a l u e f o r whi ch t h e
% s o l u t i o n i s computed. The i n i t i a l
% v e l o c i t y must be l a r g e enough t h a t
% a t m o s p h e r i c damping d o e s n o t r e d u c e
% t h e h o r i z o n t a l v e l o c i t y t o z e r o
% b e f o r e x f i n l i s r e a c h e d. O t h e r w i s e
% an e r r o r t e r m i n a t i o n w i l l o c c u r.
% n o p l o t - p l o t t i n g o f t h e t r a j e c t o r y i s % o m i t t e d when t h i s p a r a m e t e r i s
% g i v e n an i n p u t v a l u e
% y,x,t - t h e y, x and t i m e v e c t o r s p r o d u c e d % by i n t e g r a t i n g t h e e q u a t i o n s o f
% m o t i o n
% G l o b a l v a r i a b l e s:
% g r a v, - two c o n s t a n t s r e p l i c a t i n g g r a v t y and % d r a g c c d r a g, f o r u s e i n f u n c t i o n p r o j c t e q % v t o l - e q u a l t o v i n i t/1 e 6, u s e d i n p r o j c t e q % t o c h e c k w h e t h e r t h e h o r i z o n t a l
% v e l o c i t y h a s b e e n r e d u c e d t o z e r o
% U s er m f u n c t i o n s c a l l e d: p r o j c t e q
g l o b a l g r a v d r a g c v t o l
% D e f a u l t d a t a c a s e g e n e r a t e d when i n p u t i s n u l l i f n a r g i n ==0
a n g l e = 4 5; v i n i t = 6 0 0; g r a v t y = 3 2.2; c d r a g = 0.0 0 2; x f i n l = 1 0 0 0; en d;
% A s s i g n g l o b a l v a r i a b l e s and e v a l u a t e
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
% i n i t i a l v e l o c i t y
g r a v = g r a v t y; d r a g c = c d r a g; a n g = p i/1 8 0 * a n g l e; v t o l = v i n i t/1 e 6;
z 0 = [ v i n i t * c o s ( a n g ); v i n i t * s i n ( a n g ); 0; 0 ];
% I n t e g r a t e t h e e q u a t i o n s o f m o t i o n d e f i n e d % i n f u n c t i o n p r o j c t e q d e o p t n = o d e s e t ('R e l T o l',1 e - 6 ); [ x,z ] = o d e 4 5 ( @ p r o j c t e q,[ 0,x f i n l ],z 0,d e o p t n );
y = z (:,3 ); t = z (:,4 ); n = l e n g t h ( x ); x f = x ( n ); y f = y ( n );
% P l o t t h e t r a j e c t o r y c u r v e i f n a r g i n < 6
p l o t ( x,y,'-',x f,y f,'o');
x l a b e l ('x a x i s'); y l a b e l ('y a x i s');
t i t l e ( ['P r o j e c t i l e T r a j e c t o r y f o r ', ...
'V e l o c i t y S q u a r e d D r a g'] ); a x i s ('e q u a l'); g r i d on; f i g u r e ( g c f );
% p r i n t - d e p s t r a j p l o t end
% T h i s f u n c t i o n d e f i n e s t h e e q u a t i o n o f m o t i o n % f o r a p r o j e c t i l e l o a d e d by g r a v i t y and % a t m o s p h e r i c d r a g p r o p o r t i o n a l t o t h e s q u a r e % o f t h e v e l o c i t y.
% g r a v - t h e g r a v i t y c o n s t a n t % d r a g c - t h e d r a g c o e f f i c i e n t d i v i d e d by
%
% z p = p r o j c t e q ( x,z )
%% ~~~~~~~~~~~~~~~~
%
% x
% z
%
t h e h o r i z o n t a l s p a t i a l v a r i a b l e a v e c t o r c o n t a i n i n g [vx; v y; y; t ];
% zp
t h e d e r i v a t i v e d z/d x whi ch e q u a l s [ v x'( x ); v y'( x ); y'( x ); t'( x ) ];
%
%
%
%
G l o b a l v a r i a b l e s:
102
103
104
105
106
107
108
109
110 111 112
113
114
115
116
117
118
119
120 121 122
123
124
125
126
101
% g r a v i t y
% v t o l - a g l o b a l v a r i a b l e u s e d t o ch e c k % w h e t h e r vx i s z e r o
%
% U s er m f u n c t i o n s c a l l e d: none
%-----------------------------------------------------------------------------------------
g l o b a l g r a v d r a g c v t o l
v x = z ( 1 ); v y = z ( 2 ); v = s q r t ( v x ~ 2 + v y ~ 2 );
% Check t o s e e w h e t h e r d r a g r e d u c e d t h e % h o r i z o n t a l v e l o c i t y t o z e r o b e f o r e t h e % x f i n l was r e a c h e d. i f a b s ( v x ) < v t o l d i s p (' ');
disp('ERROR i n f u n c t i o n p r o j c t e q. The '); d i s p (' i n i t i a l v e l o c i t y o f t h e p r o j e c t i l e'); d i s p (' was n o t l a r g e enough f o r x f i n a l t o'); d i s p (' be r e a c h e d.'); disp('EXECUTION IS TERMINATED.');
d i s p (' '),e r r o r (' '); end
z p = [ - d r a g c * v; - ( g r a v + d r a g c * v * v y )/v x; ... v y/v x; 1/v x ];
8.8 Example on Dynamics of a Chain with Specified End Motion
The dynamics of flexible cables is often modeled using a chain of rigid links con­
nected by frictionless joints. A chain having specified end motions illustrates the behavior of a system governed by nonlinear equations of motion and auxiliary al­
gebraic constraints. In particular, we will study a gravity loaded cable fixed at both ends. The total cable length exceeds the distance between supports, so that the static deflection configuration resembles a catenary.
A simple derivation of the equations of motion employing principles of rigid body dynamics is given next. Readers not versed in principles of rigid body dynamics [48] may nevertheless understand the subsequent programs by analyzing the equations of motion which have a concise mathematical form. The numerical solutions vividly illustrate some numerical difficulties typically encountered in multibody dynamical studies. Such problems are both computationally intensive, as well as highly sensi­
tive to accumulated effects of numerical error.
The mathematical model of interest is the two-dimensional motion of a cable (or chain) having n rigid links connected by frictionless joints. A typical link i has its
F
Figure 8.9: Chain with Specified End Motion
mass mi concentrated at one end. The geometry is depicted in Figure 8.9. The chain ends undergo specified motions R o(t) = [Xo(t) ; Yo(t)] for the first link and R n(t) = [Xn(t) ; Yn(t)] for the last link. The direction vector along link i is described by r i = [xi ; yi] = ί ι [οοβ(θι ) ; s i n ^ ) ]. We assume that each joint i is subjected to a force F i = [fxi ; f yi] where 0 < i < n. Index values i = 0 and i = n denote unknown constraint forces which must act at the outer ends of the first and last links to achieve the required end displacements. The forces applied at the interior joints are arbitrary. It is convenient to characterize the dynamics of each link in terms of its direction angle. Thus
rt = rfli , rt = rfii + r% θ 2 = rf i i - r ^\
wh e r e p r i me s a n d d ot s d e n o t e d i f f e r e n t i a t i o n wi t h r e s p e c t t o θ i and t, respectively. Therefore
ri [ yi ; : ri [ yi ; Xifli [xi ; y^]θ^ ·
The global position vector of joint i is
%
n
Ri = Ro + } r 3 = Ro + < i - j > r3
3=1
3=1
where the symbol < k >= 1 for k > 0, and 0 for k < 0. Consequently, the velocity and acceleration of joint i are
n
Ri = Ro + Σ <i - J> r3Θ 3,
3 = 1
Ri = Ro + ^ <i - j > r'3 Θ3 - ^ <i - J > r3 θ2.
3=1 3=1
n
n
The ends of the chain each have specified motions; so not all of the inclination angles are independent. Consequently,
n
^ ^ r 3 R n
3=1
n
^ ' r 3 θ] = R n — Ro,
3=1
n n
Σ 3 r 3θ3 - Σ< r 3®23 = R n - R 0.
3=1 3=1
Co mb i n i n g t h e l a s t c o n s t r a i n t e q u a t i o n wi t h e q u a t i o n s o f mo t i o n wr i t t e n f o r ma s s e s m 1, · ·· , mn yields a complete system of (n + 2 ) equations determining θ1, · ·· ,0 n and the components of F n. The fact that all masses are concentrated at frictionless joints shows that link i is a two-force member carrying an internal load directed along ri. Consequently, the D’Alembert principle [48] implies that the sum of all external and inertial loads from joints i,i + 1, · ·· ,n must give a resultant passing through joint i in the direction of r i. Since r i and r i are perpendicular, requiring a vector to be in the direction of ri is equivalent to making it normal to r i. Therefore
n
n
■3=1
<j - i > {F3 - m3R3 j
0 , 1 < i < n.
Th e l a s t n equations involve θι and two end force components f xn and f yn. Some algebraic rearrangement results in a matrix differential equation of concise form con­
taining several auxiliary coefficients defined as follows:
bi = ^ 2 mk , mt 3 = m3i = bt , 1 < i < n , 1 < j < i,
r
t
n
ai3 = mi 3 (xix3 + yiy3) , 1 < i < n , 1 < j < n
bi3 = mn (xiy3 - X3 yi) , 1 < i < n , 1 < j < n
n— 1 n— 1
Pxi ^ ^ f xi , Vyi ^ ^ f yi , 1 < i < n.
3=1 3=1
F o r i = n, the last two sums mean pxn = Pyn = 0. Furthermore, we denote the ac­
celeration components of the chain ends as Ro = [axo ; ayo] and Rn = [axn ; ayn].
Us i n g t h e v a r i o u s qu a n t i t i e s j u s t de f i ne d, t h e e q u a t i o n s o f mo t i o n b e c o me
n n
'S^ ^ J a i $3 + yif xn xi f yn ^ ^ bi3 θj + x i (pyi biay0 ) yi (pxi biax0 )
3=1 3=1
ei , 1 < i < n.
The remaining two components of the constraint equations completing the system are
n n
^ y3 θ 3 = ^ \Χ3 θ j axn + ax0 = en+1,
3=1 3=1
n n
Y x3 θ3 Y, y3 + ayn — ay0 = en+ 2 ·
3=1 3=1
Co ns e q ue nt l y, we g e t t h e f o l l o wi n g s y mme t r i c ma t r i x e q u a t i o n t o s ol v e f o r θ1, · ·· , 0n,
fxn and fyn
"A X Y
θ'
X T 0 0
f xn
Y T 0 0
— f yn
where X, Y, E and θ are column matrices, and the matrix A = [a i 3 ] is symmetric. Because most numerical integrators for differential equations solve first order sys­
tems, it is convenient to employ the vector Z = [θ ; θ] having 2n components. Then the differential equation Z = H (t, Z ) is completely defined when θ has been com­
puted for known Z. The system is integrated numerically to give θ and θ as functions of time. These quantities can then be used to compute the global Cartesian coordi­
nates of the link configurations, thereby completely describing the time history of the chain.
The general equations of motion simplify somewhat when the chain ends are fixed and the external forces only involve gravity loads. Then p xl = 0 andpyi = - g( bl — bn) which gives
n
^ ^ mi3 (xix3 + νιν3 ~)θ3 x i f yn + Vif xn =
3=1
n
g(bi — b n ) + ^ j m%3 (xi V3 — X3 y%)$3 , 1 < I < n.
3 = 1
Th e l a s t t wo e q u a t i o n s t o c o mp l e t e t h e s e t ar e:
n n n n
Σ x3 θ3 = Σ ν3θ3 ,Σ ν3θ3 = — Σ Χ3θ3 .
3=1 3=1 3=1 3=1
A program was written to simulate motion of a cable fixed at both ends and released from rest. The cable falls under the influence of gravity from an initially elevated position. Function ode45 is used to perform the numerical integration. The program consists of three functions cablenl, plotmotn, and equamo. Function cablenl cre­
ates the data, calls ode45 to perform the integration, and displays the output from the simulation. Function plotmotn plots the motion for specified time limits. Results can be shown using animation or plots superimposing successive positions of the cable. Most of the analysis in the program is performed in function equamo which forms the equations of motion which are passed to ode45 for integration.
A configuration with eight identical links was specified. For simplicity, the total mass, total cable length, and gravity constant were all normalized to equal unity. The numerical integration error was controlled using a relative tolerance of 1e-6 and an absolute error tolerance of 1e-8. Results of the simulation appear below. Fig­
ure 8.10 shows cable positions during the early stages of motion when results of the numerical integration are reliable. However, the numerical solution eventually becomes worthless due to accumulated numerical inaccuracies yielding the motion predictions indicated in
Figure 8.11
. The nature of the error growth can be seen clearly in
Figure 8.12
which plots the x-coordinate of the chain midpoint as a func­
tion of time. Since the chosen mass distribution and initial deflection is symmetrical about the middle, the subsequent motion will remain symmetrical unless the numer­
ical solution becomes invalid. The x coordinate of the midpoint should remain at a constant value of %/2~/4, but it appears to abruptly go unstable near t = 18. More careful examination indicates that this numerical instability does not actually occur suddenly. Instead, it grows exponentially from the outset of the simulation. The error is caused by the accumulation of truncation errors intrinsic to the numerical integra­
tion process allowing errors at each step which are regulated within a small but finite tolerance. A global measure of symmetry loss of the y deflection pattern is plotted on a semilog scale in
Figure 8.13
. Note that the error curve has a nearly linear slope until the solution degenerates completely near t =18. The reader can verify that choosing less stringent error tolerances produces solutions which become inaccurate sooner than t = 18. It should also be observed that this dynamical model exhibits another important characteristic of highly nonlinear systems, namely, extreme sen­
sitivity to physical properties. Note that shortening the last link by only one part in ten thousand makes the system deflection quickly lose all appearance of symme­
try by t = 6. Hence, two systems having nearly identical physical parameters and initial conditions may behave very differently a short time after motion is initiated. The conclusion implied is that analysts should thoroughly explore how parameter variations affect response predictions in nonlinear models.
y axis y axis
MOTION OF A FALLING CABLE
Figure 8.10: Motion During Initial Phase
MOTION OF A FALLING CABLE
0.3-
0.2
0.1
-0.1
-0.2
-0.3
-0.4
-0.1
0.1
0.2
0.3 0.4
x axis
0.5 0.6
0.7
0.8
0
0
Figure 8.11: Motion After Solution Degenerates
asymmetry error x coordinate
Horizontal Position of the Cable Midpoint
time
Figure 8.12: Horizontal Position of the Cable Midpoint
time
Figure 8.13: Growing Loss of Symmetry in Vertical Deflection
Example on Nonlinear Cable Motion Program cablenl
f u n c t i o n [ t,x,y,t h e t a,c p t i m ] = c a b l e n l % [ t,x,y,t h e t a,c p t i m ] = c a b l e n l % Example: c a b l e n l %........................................
% N u m e r i c a l i n t e g r a t i o n o f t h e m a t r i x % d i f f e r e n t i a l e q u a t i o n s f o r t h e n o n l i n e a r % dynami cs o f a c a b l e o f r i g i d l i n k s w i t h % t h e o u t e r e n d s o f t h e c a b l e f i x e d.
%
% t - t i m e v e c t o r f o r t h e s o l u t i o n
% x,y - m a t r i c e s w i t h n o d a l c o o r d i n a t e s
% s t o r e d i n t h e co l u m n s. The t i m e
% h i s t o r y o f p o i n t j i s i n x (:,j )
% and y (:,j )
% t h e t a - m a t r i x w i t h i n c l i n a t i o n a n g l e s
% s t o r e d i n t h e columns
% c p t i m - number o f s e c o n d s t o i n t e g r a t e
% t h e e q u a t i o n s o f m o t i o n
%
% U s er m f u n c t i o n s r e q u i r e d:
% p l o t m o t n, equamo
c l e a r a l l; c l o s e;
% Make v a r i a b l e s g l o b a l f o r u s e by % f u n c t i o n equamo
g l o b a l f i r s t _ n_ m_ l e n _ g r a v _ b_ mas_ py_
f p r in t f ('\n N O N L I N E A R DYNAMICS OF A ') f p r i n t f ('F A L L I N G CABLE\n') f p r i n t f (...
'\n N o t e: The c a l c u l a t i o n s t a k e a w h i l e\n')
% S e t up d a t a f o r a c a b l e o f n_ l i n k s,
% i n i t i a l l y a r r a n g e d i n a t r i a n g u l a r % d e f l e c t i o n c o n f i g u r a t i o n.
% p a r a m e t e r c o n t r o l l i n g i n i t i a l i z a t i o n of % a u x i l i a r y p a r a m e t e r s u s e d i n f u n c t i o n % equamo
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
74
75
76
77
78
79
80
81
82
83
84
85
f i r s t _ = 1;
% number o f l i n k s i n t h e c a b l e n_=8; n=n_; n h = n _/2;
% v e c t o r o f l e n g t h s and g r a v i t y c o n s t a n t l e n _ = 1/n * o n e s ( n,1 ); g r a v _ = 1;
% v e c t o r o f mass c o n s t a n t s m _ = o n e s ( 1,n _ )/n _;
% i n i t i a l p o s i t i o n a n g l e s t h 0 = p i/4 * [ o n e s ( n h,1 );- o n e s ( n h,1 ) ]; t d 0 = z e r o s ( s i z e ( t h 0 ) ); z 0 = [ t h 0;t d 0 ];
% t i m e l i m i t s, i n t e g r a t i o n t o l e r a n c e s,
% and t h e number o f s o l u t i o n p o i n t s tm i n = 0; tmax=25; n t = 2 0 1; t = l i n s p a c e ( 0,t m a x,n t )'; t o l r e l = 1 e - 6; t o l a b s = 1 e - 8; l e n = l e n _;
% P e r f o r m t h e n u m e r i c a l i n t e g r a t i o n u s i n g a % v a r i a b l e s t e p s i z e R u n g e - K u t t a i n t e g r a t o r t i c;
o d e t o l = o d e s e t ('R e l T o l',t o l r e l,'A b s T o l',t o l a b s ); [ t,w ] = o d e 4 5 ( @ e q u a m o,t,z 0,o d e t o l ); t h e t a = w (:,1:n ); c p t i m = t o c;
% Compute node p o i n t c o o r d i n a t e s Z = [ z e r o s ( n t,1 ),r e p m a t ( l e n',n t,1 ).* e x p ( i * t h e t a ) ]; Z = c u m s u m ( Z.').'; x = r e a l ( Z ); y = i m a g ( Z );
% P l o t t h e h o r i z o n t a l p o s i t i o n o f t h e m i d p o i n t c l f; p l o t ( t,x (:,1 + n _ /2 ) ); y l a b e l ('x c o o r d i n a t e'); x l a b e l ('t i m e') t i t l e ( ['H o r i z o n t a l P o s i t i o n o f t h e ' ...
'C a b l e M i d p o i n t'] ) g r i d on; f i g u r e ( g c f );
% p r i n t - d e p s x m i d l
d i s p (' '), d i s p (...
'P r e s s [ E n t e r ] t o s e e t h e e r r o r g r o w t h c u r v e'); p a u s e, c l o s e
% Show e r r o r g r o w t h i n d i c a t e d by symmetry % l o s s o f t h e v e r t i c a l d e f l e c t i o n symmetry.
% An a p p r o x i m a t e l y l i n e a r t r e n d on t h e s e m i l o g % p l o t i n d i c a t e s e x p o n e n t i a l g r o w t h o f t h e e r r o r.
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
u n s y m e r = s q r t ( s u m ( ( y - y (:,e n d:- 1:1 ) ).~ 2,2 ) ); h o l d o f f; a x i s ('n o r m a l'); c l f; s e m i l o g y ( t,u n s y m e r );
x l a b e l ('t i m e'); y l a b e l ('a s y m m e t r y e r r o r'); t i t l e ( ['G r o w i n g Loss o f Symmetry i n ' ...
'V e r t i c a l D e f l e c t i o n'] ); g r i d on; f i g u r e ( g c f );
% p r i n t - d e p s u n s y m e r r
d i s p (' '), d i s p (...
'P r e s s [ E n t e r ] t o s e e t h e r e s p o n s e a n i m a t i o n');
% Show a n i m a t i o n o f t h e c a b l e r e s p o n s e d i s p (' ')
d i s p ('T h e m o t i o n c a n be a n i m a t e d o r a t r a c e') d i s p ('c a n be shown f o r s u c c e s s i v e p o s i t i o n s') d i s p ( ['b e t w e e n t = ',n u m 2 s t r ( t m i n ),...
' and t = ',n u m 2 s t r ( t m a x ) ] )
% P l o t t h e p o s i t i o n f o r d i f f e r e n t t i m e s l i m i t s t i t l ='C A B L E MOTION FOR T = '; w h i l e 1
d i s p (' '), d i s p (...
['C h o o s e a p l o t o p t i o n (1 <=> a n i m a t e, ',...
' 2 < = > t r a c e,'] ) o p t = i n p u t ('3 < = > s t o p ) > ? '); i f o p t = = 3, b r e a k, e n d d i s p (' '), d i s p (...
'G i v e a t i m e v e c t o r s u c h a s 0:.1:1 5') T p = i n p u t ('T i m e v e c t o r > ? ','s'); i f i s e m p t y ( T p ), b r e a k, end t p = e v a l ( T p ); t p = t p (:); T = [ t i t l,T p ]; x p = i n t e r p 1 q ( t,x,t p ); y p = i n t e r p 1 q ( t,y,t p ); i f o p t ==1, p l o t m o t n ( x p,y p,T ) e l s e, p l o t m o t n ( x p,y p,T,1 ), end end
f p r i n t f ('\n A l l D o n e\n') %=============================================
f u n c t i o n p l o t m o t n ( x,y,t i t l,i s a v e )
%
% p l o t m o t n ( x,y,t i t l,i s a v e )
%~~~~~~~~~~~~~~~~~~~~
% T h i s f u n c t i o n p l o t s t h e c a b l e t i m e
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
% h i s t o r y d e s c r i b e d by c o o r d i n a t e v a l u e s % s t o r e d i n t h e rows o f m a t r i c e s x and y.
%
% x,y %
%
% t i t l % i s a v e %
%
%
%
%
%
%
%
% U s er m f u n c t i o n s c a l l e d: none
%-------------------------------------------------------------------------------------
% S e t a s q u a r e window t o c o n t a i n a l l % p o s s i b l e p o s i t i o n s [ n t,n ] = s i z e ( x );
i f n a r g i n = = 4, s a v e =1; e l s e, s a v e = 0; end x m i n = m i n ( x (:) ); x m a x = m a x ( x (:) ); y m i n = m i n ( y (:) ); y m a x = m a x ( y (:) ); w=max(xmax-xmin,ymax-ymin)/2; xmd=(xmin+xmax)/2; ymd=(ymin+ymax)/2; h o l d o f f; c l f; a x i s ('n o r m a l'); a x i s ('e q u a l'); range=[xmd-w,xmd+w,ymd-w,ymd+w]; t i t l e ( t i t l )
x l a b e l ('x a x i s'); y l a b e l ('y a x i s') i f save==0 f o r j = 1:n t
xj=x(j,:); yj=y(j,:);
p l o t ( x j,y j,'- k',x j,y j,'o k'); a x i s ( r a n g e ), a x i s o f f t i t l e ( t i t l )
f i g u r e ( g c f ), drawnow, p a u s e (.1 ) end
p a u s e ( 2 )
e l s e
h o l d o f f; c l o s e f o r j = 1:n t
xj=x(j,:); yj=y(j,:);
p l o t ( x j,y j,'- k',x j,y j,'o k');
- m a t r i c e s h a v i n g s u c c e s s i v e rows whi ch d e s c r i b e p o s i t i o n c o n f i g u r a t i o n s f o r t h e c a b l e
- a t i t l e shown on t h e p l o t s
- p a r a m e t e r c o n t r o l l i n g t h e for m
o f o u t p u t. When i s a v e i s n o t i n p u t, o n l y one p o s i t i o n a t a t i m e i s shown i n r a p i d s u c c e s s i o n t o a n i m a t e t h e m o t i o n. I f i s a v e i s g i v e n a v a l u e, t h e n s u c c e s s i v e a r e a l l shown a t once t o i l l u s t r a t e a k i n e m a t i c t r a c e o f t h e m o t i o n h i s t o r y.
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
a x i s ( r a n g e ), a x i s o f f, h o l d on end
t i t l e ( t i t l )
figure(gcf), drawnow, h o l d o f f, p a u s e ( 2 ) end
% Save p l o t h i s t o r y f o r s u b s e q u e n t p r i n t i n g % p r i n t - d e p s p l o t m o t n
% E q u a t i o n o f m o t i o n f o r a c a b l e f i x e d a t % b o t h e n d s and l o a d e d by g r a v i t y f o r c e s o n l y
% V a l u e s a c c e s s e d a s g l o b a l v a r i a b l e s g l o b a l f i r s t _ n_ m_ l e n _ g r a v _ b_ mas_ py_
% I n i t i a l i z e p a r a m e t e r s f i r s t t i m e % f u n c t i o n i s c a l l e d i f f i r s t _ = = 1, f i r s t _ = 0;
% m a s s p a r a m e t e r s
m_=m_(:); b _ = f l i p u d ( c u m s u m ( f l i p u d ( m _ ) ) ); ma s _ = b _ (:,o n e s ( n _,1 ) ); m a s _ = t r i l ( m a s _ ) + t r i l ( m a s _,- 1 )';
% l o a d e f f e c t s f r om g r a v i t y f o r c e s p y _ = - g r a v _ * ( b _ - b _ ( n _ ) );
%
%
% t
% z
%
c u r r e n t t i m e v a l u e c o l u m n v e c t o r d e f i n e d b y [ t h e t ( t );t h e t a'( t ) ] column v e c t o r d e f i n e d by t h e c o n c a t e n a t i o n
% z d o t
%
%
%
z'( t ) = [ t h e t a'( t );t h e t a''( t ) ]
% User
U s er m f u n c t i o n s c a l l e d: n o n e.
%
end
% S o l v e f o r z d o t = [ t h e t a'( t ); t h e t a''( t ) ]; n=n_; l e n = l e n _;
th=z(1:n); td=z(n+1:2*n); td2=td.*td;
2 2 1: x = l e n.* c o s ( t h ); y = l e n.* s i n ( t h );
2 2 2:
2 2 3: % M a t r i x o f mass c o e f f i c i e n t s and
2 2 4: % c o n s t r a i n t c o n d i t i o n s
2 2 5: a m a t = [ [ m a s _.* ( x * x'+ y * y'),x,y ];
2 2 6: [ x,y;z e r o s ( 2,2 ) ]'];
2 2 7:
2 2 8: % R i g h t s i d e v e c t o r i n v o l v e s a p p l i e d f o r c e s
2 2 9: % and i n e r t i a l t e r m s
2 3 0: b ma t = x * y'; b m a t = m a s _.* ( b m a t - b m a t');
2 3 1:
2 3 2: % S o l v e f o r a n g u l a r a c c e l e r a t i o n.
2 3 3: % Most c o m p u t a t i o n o c c u r s h e r e.
2 3 4: s o l n = a m a t\[ x.* p y _ + b m a t * t d 2; y'* t d 2; - x'* t d 2 ];
2 3 5:
2 3 6: % F i n a l r e s u l t n e e d e d f o r u s e by t h e 237: % n u m e r i c a l i n t e g r a t o r 238: z d o t = [ t d; s o l n ( 1:n ) ];
8.9 Dynamics of an Elastic Chain
The preceding article analyzed a chain of rigid links requiring only one rotation angle per link. Next we study a similar model of an elastic chain involving sev­
eral point masses connected by elastic springs which can only support tension. The equations of motion are easy to formulate in terms of the horizontal and vertical coor­
dinates of each mass. The dimensionality needed to handle the elastic chain is twice that needed for a similar rigid link model. It is natural to utilize a three-dimensional model that easily simplifies for two dimensional motion.
Consider a chain having n mass particles
mj, 1 < j < n
connected by n + 1 springs having unstretched lengths
lj, 1 < j < n +1.
The position of particle mj is denoted by vector r j with r 0(t) and r n+1(t) signi­
fying the outer end positions of the first and last springs, which are assumed to be known functions of time. Furthermore, concentrated forces P j (t ) are applied to the particles. The tensile force in spring number j is
Tj = kj (1 — lj /Lj ) (Lj > lj ) R j
wher e
Rj = r j+i — r j, Lj = \ Rj j,
rj (t) = vj , vj (t) = (pj + Tj - Tj-i - CjVj) /mj , 1 < j < n
where viscous drag forces defined by the particle velocities times damping coeffi­
cients Cj are included. These equations are easy to form using array operations. Furthermore, the two-dimensional case can be simplified further by using complex numbers to represent the particle positions.
A program was written to compute the response of a chain released from at rest in a horizontal position with the springs unstretched. The chain is subjected to gravity loading and the ends of the chain are rotated at constant speed around circular paths. The left and right ends rotate counterclockwise and clockwise respectively. A special case where the right end of the chain is free is provided by setting the last spring constant to zero. Another case where the chain ends do not move occurs when the radii of the end path motions are set to zero.
The following program called sprnchan computes the response of a chain with an arbitrary number of identical masses connected by identical springs. The radii and the rotation rate of the end motions, as well as the amount of viscous damping can be changed easily. Function sprnchan reads data from function chaindata and calls ode45 to integrate the equations of motion which are formed with functions spreq- mof and endmo. Using the output from ode45, function plotmotn provides visual descriptions of the response. The motion can be presented using either animation or by superimposing plots of successive positions of the chain in chosen time intervals. To run a different problem, the sample data function chaindata can be saved using a different name; and the variables n, tmax, nt, fixorfree, rend, omega, and cdamp can be changed appropriately. Furthermore, modifying the program to handle dif­
ferent variations of stiffness and mass, as well as different end conditions would be straightforward.
Figures 8.14 an
d 8.15 show program results where 1) the left end of the chain was rotated and the right end was detached and 2) both ends of the chain were rotated simultaneously in opposite directions. The time response was computed for a maximum time value of 20, but the chosen time traces only show small subin­
tervals chosen so that successive positions do not overlap excessively. Readers may find it interesting to observe the animation responses resulting from different data choices.
and kj denotes a spring constant. Then the equations of motion are given by
ELASTIC CHAIN MOTION FOR [cdamp,omega] = [1 , 6 ] and T = 0:.08:1.5
[cdamp,omega] = [1 , 6 ] , 0 < t < 0.6
Figure 8.15: Chain with Both Ends Rotating
Program for Elastic Chain Dynamics Program sprnchan
i: f u n c t i o n [ t,z,c p t i m ] = s p r n c h a n 2: %
3: % [ t,z,c p t i m ] = s p r n c h a n
4: %
5: % DYNAMIC SIMULATION OF AN ELASTIC CHAIN
6: % T h i s p r o g r a m s i m u l a t e s t h e dyna mi c s o f an e l a s t i c 7: % c h a i n mode l e d by a s e r i e s of mass p a r t i c l e s j o i n e d 8: % by e l a s t i c s p r i n g s. The o u t e r s p r i n g s a t e a c h end 9: % a r e c o n n e c t e d t o f o u n d a t i o n s movi ng on c i r c u l a r i o: % p a t h s a t c o n s t a n t s p e e d. The s y s t e m i s r e l e a s e d f r om i i: % r e s t i n a h o r i z o n t a l p o s i t i o n. F o r c e s on t h e s y s t e m i 2: % i n c l u d e g r a v i t y, l i n e a r v i s c o u s d r a g, a nd f o u n d a t i o n i 3: % m o t i o n. I f t h e l a s t s p r i n g i n t h e c h a i n i s a s s i g n e d i 4: % z e r o s t i f f n e s s, t h e n t h e l a s t p a r t i c l e i s f r e e d f r om i 5: % t h e f o u n d a t i o n and a s w i n g i n g c h a i n w i t h t h e u p p e r i 6: % end s h a k e n i s a n a l y z e d. The p r i n c i p a l v a r i a b l e s f o r i 7: % t h e p r o b l e m a r e l i s t e d be l o w. D i f f e r e n t d a t a c h o i c e s i 8: % c a n be made by c h a n g i n g f u n c t i o n c h a i n d a t a.
i 9: %
2 0: % t l i m - v e c t o r o f t i m e v a l u e s a t whi c h t h e 2 i: % s o l u t i o n i s comput ed
2 2: % m - v e c t o r o f mass v a l u e s f o r t h e p a r t i c l e s
2 3: % k - v e c t o r o f s t i f f n e s s v a l u e s f o r s p r i n g s
2 4: % c o n n e c t i n g t h e p a r t i c l e s. I f t h e l a s t
2 5: % s p r i n g c o n s t a n t i s s e t t o z e r o, t h e n t h e
2 6: % r i g h t end c o n s t r a i n t i s r emoved
2 7: % L - v e c t o r o f u n s t r e t c h e d s p r i n g l e n g t h s
2 8: % z e n d - compl ex p o s i t i o n c o o r d i n a t e o f t h e o u t e r
2 9: % end of t h e l a s t s p r i n g ( a s s u mi n g t h e o u t e r
3 0: % end of t h e f i r s t s p r i n g i s h e l d a t z=0)
3 i: % z i n i t - v e c t o r o f compl ex i n i t i a l d i s p l a c e m e n t 3 2: % v a l u e s f o r e a c h mass p a r t i c l e. I n i t i a l
3 3: % v e l o c i t y v a l u e s a r e z e r o.
3 4: % f e x t - v e c t o r o f c o n s t a n t compl ex f o r c e component s 35: % a p p l i e d t o t h e i n d i v i d u a l ma s s e s
3 6: % c - v e c t o r o f dampi ng c o e f f i c i e n t s s p e c i f y i n g
3 7: % d r a g on e a c h p a r t i c l e l i n e a r l y p r o p o r t i o n a l
3 8: % t o t h e p a r t i c l e v e l o c i t y
3 9: % t o l r e l - r e l a t i v e e r r o r t o l e r a n c e f o r f u n c t i o n ode45 40: % t o l a b s - a b s o l u t e e r r o r t o l e r a n c e f o r f u n c t i o n ode45
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
74
75
76
77
78
79
80
81
82
83
84
85
% t - v e c t o r of t i me s r e t u r n e d by ode45
% z - m a t r i x of complex p o s i t i o n and v e l o c i t y
% v a l u e s r e t u r n e d by ode45. A t y p i c a l row
% z ( j,:) g i v e s t h e system p o s i t i o n and
% v e l o c i t y f o r t ime t ( j ). The f i r s t h a l f of
% t h e row c o n t a i n s complex p o s i t i o n v a l u e s
% and t h e l a s t h a l f c o n t a i n s v e l o c i t y v a l u e s
% omega - fr equenc y a t which t h e ends of t h e c ha in % a r e shaken
% yend - ampl i tude of t h e v e r t i c a l motion of t h e
% ch a i n ends. I f t h i s i s s e t t o z e r o t h e n
% t h e ch a i n ends do not move
% endmo - t h e f u n c t i o n d e f i n i n g t h e end motion of % t h e cha in
% spreqmof - t h e f u n c t i o n d e f i n i n g t h e e q u a t i o n of % motion t o be i n t e g r a t e d u s i n g ode45
%
% User m f u n c t i o n s c a l l e d: c h a i n d a t a, spreqmof,
% endmo, plot mot n
%-----------------------------------------------------------------------------------------
g l o b a l zend omega Rend
fprintf('\nDYNAMICS OF A FALLING ELASTIC CHAIN\n\n') d i s p ('G i v e a f i l e name t o d e f i n e t h e d a t a. T r y') d a t n a m e = i n p u t ('c h a i n d a t a as an example > ? ','s'); e v a l ( ['[ n,t m a x,n t,f i x o r f r e e,r e n d,o m e g a,c d a m p ] =',... d a t n a m e,';'] );
% The f o l l o w i n g d a t a v a l u e s a r e s c a l e d i n terms of % t h e par a m e t e r s r e t u r n e d by t h e d a t a i n p u t f u n c t i o n
% Time v e c t o r f o r s o l u t i o n o u t p u t tmin=0; t l i m = l i n s p a c e ( t m i n,t m a x,n t )';
% Number of masses, g r a v i t y c o n s t a n t, mass v e c t o r g=32.2; len0=1; mas=1/g; m=mas*ones(n,1);
% Spri ng l e n g t h s and s p r i n g c o n s t a n t s L=l en0*ones(n+1,1); ksp=5*mas*g*(n+1)/(2*len0); k=ksp*ones(n+1,1);
% I f t h e f a r end of t h e ch a i n i s f r e e, t h e n t h e % l a s t s p r i n g c o n s t a n t i s s e t equal t o zero k ( n + 1 ) = f i x o r f r e e * k ( n + 1 );
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
% Viscous damping c o e f f i c i e n t s c= c d a m p *s qr t ( mas *ks p)/40*one s ( n,1);
% Chain end p o s i t i o n and i n i t i a l p o s i t i o n of % each mass. Para me t ers c onc erni ng t h e end % p o s i t i o n s a r e p as s e d as g l o b a l v a r i a b l e s.
% g l o b a l zend omega Rend zend=len0*(n+1); zi ni t =c ums um( L( 1:n) ); Rend=rend*zend;
% Funct i on name g i v i n g end p o s i t i o n of t h e cha in re=@endmo;
% Gr a v i t y f o r c e s and i n t e g r a t i o n t o l e r a n c e fext=-i *g*m; t o l r e l = 1 e - 6; t o l a b s = 1 e - 8;
% I n i t i a l c o n d i t i o n s f o r t h e ode45 i n t e g r a t o r n=l engt h(m); r 0 = [ z i n i t;z e r o s ( n,1 ) ];
% I n t e g r a t e e q u a t i o n s of motion
o p t i o n s = o d e s e t ('r e l t o l',t o l r e l,'a b s t o l',t o l a b s ); f p r i n t f ('\n P l e a s e Wait While t h e E q u a t i o n s\n') f p r i n t f ('o f Motion Are Being I n t e g r a t e d\n') p a u s e ( 1 ), t i c;
[ t,r ] = o d e 4 5 ( @ s p r e q m o f,t l i m,r 0,o p t i o n s,...
m,k,L,r e,f e x t,c );
cpt i m=toc; c p t = n u m 2 s t r ( f i x ( 1 0 * c p t i m )/1 0 ); f p r i n t f (...
['\n C omput a t i on time was ',c p t,' s e c o n d s\n'] )
% E x t r a c t d i s pl a ce me nt h i s t o r y and add % end p o s i t i o n s
R=endmo(t); z = [ R (:,1 ),r (:,1:n ) ]; i f k(n+1)~=0, z = [ z,R (:,2 ) ]; end X = r e a l ( z ); Y=imag(z);
% Show ani mat i on or motion t r a c e of t h e r e s p o n s e.
% d i s p ('P r e s s [Enter] t o c o n t i n u e'), pause d i s p (' ')
d i s p ('T h e motion can be animated or a t r a c e') d i s p ('c a n be shown f o r s u c c e s s i v e p o s i t i o n s') d i s p ( ['b e t w e e n t = ',n u m 2 s t r ( t m i n ),...
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
' and t = ',n u m 2 s t r ( t m a x ) ] ) t i tl =['ELASTIC CHAIN MOTION FOR ',...
'[cdamp,omega] = [',n u m 2 s t r ( c d a m p ),' , ',... num2s t r ( omega ),' ] and T = '];
% P l o t t h e p o s i t i o n f o r d i f f e r e n t t i mes l i m i t s whi l e 1
d i s p (' '), d i s p (...
['Choose a p l o t o p t i o n (1 <=> ani mat e, ',...
' 2 <=> t r a c e,'] ) o p t = i n p u t ('3 <=> s t o p ) > ? '); i f opt==3, b r e a k, end d i s p (' '), d i s p (...
'Give a time v e c t o r such as 0:.1:1 5') Tp=i nput ('Ti me v e c t o r > ? ','s'); i f i sempt y(Tp), b r e a k, end t p = e v a l ( T p ); t p = t p (:); T = [ t i t l,T p ]; x p = i n t e r p 1 q ( t,X,t p ); y p = i n t e r p 1 q ( t,Y,t p ); i f opt ==1, pl o t mo t n ( x p,y p,T ) e l s e, p l o t m o t n ( x p,y p,T,1 ), end end
% Save p l o t h i s t o r y f o r s ubsequent p r i n t i n g % p r i n t -deps plot mot n
f p r i n t f ('\n A l l Done\n')
%=====================================
f u n c t i o n [ n,t m a x,n t,f i x o r f r e e,r e n d,o m e g a,...
cdamp]=chaindata
%
% [ n,t m a x,n t,f i x o r f r e e,r e n d,o m e g a,...
% cdamp]=chaindata
%............................................................................................................
% This example f u n c t i o n c r e a t e s d a t a d e f i n i n g % t h e c h a i n. The f u n c t i o n can be renamed and % modi fi ed t o handl e d i f f e r e n t problems.
n=8; % Number or p o i n t masses
tmax=20; % Maximum time f o r t h e s o l u t i o n
nt=401; % Number of time v a l u e s from 0 t o tmax
f i x o r f r e e = 0; % Determines whether t h e r i g h t end
% p o s i t i o n i s c o n t r o l l e d or f r e e. Use % ze ro f o r f r e e or one f o r c o n t r o l l e d.
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
rend=0.05; % Amplitude f a c t o r f o r end motion. This
% can be z e r o i f t h e ends a r e f i x e d. omega=6; % Frequency a t which t h e ends a r e
% r o t a t e d.
cdamp=1; % C o e f f i c i e n t r e g u l a t i n g t h e amount of
% v i s c o u s damping. Reduce cdamp t o gi ve % l e s s damping.
f u n c t i o n r d o t = s p r e q m o f ( t,r,m,k,L,r e,f e x t,c ) % r d o t = s p r e q m o f ( t,r,m,k,L,r e,f e x t,c )
% This f u n c t i o n forms t h e t wo-di mensi onal e q u a t i o n % of motion f o r a c h a i n of s p r i n g - c o n n e c t e d p a r t i c l e s. % The p o s i t i o n s of t h e ends of t h e ch a i n may be time % dependent and a r e computed from a f u n c t i o n named i n % t h e i n p u t par amet er r e. The a p p l i e d e x t e r n a l l o a d i n g % c o n s i s t s of c o n s t a n t l o a d s on t h e p a r t i c l e s and % l i n e a r v i s c o u s damping p r o p o r t i o n a l t o t h e p a r t i c l e % v e l o c i t i e s. Data p a r amet er s f o r t h e problem a r e % d e f i n e d i n a f u n c t i o n f i l e s p e c i f i e d by t h e u s e r.
% Funct i on c h a i n d a t a g i v e s a t y p i c a l example.
% t - c u r r e n t v a l u e of time
% r - v e c t o r c o n t a i n i n g complex d i s p l a c e me n t s i n
% t h e t o p h a l f and complex v e l o c i t y components
% i n t h e bottom h a l f
% m - v e c t o r of p a r t i c l e masses
% k - v e c t o r of s p r i n g c o n s t a n t v a l u e s
% L - v e c t o r of u n s t r e t c h e d s p r i n g l e n g t h s
% r e - name of a f u n c t i o n which r e t u r n s t h e time
% dependent complex p o s i t i o n c o o r d i n a t e f o r
% t h e ends of t h e cha in
% f e x t - v e c t o r of c o n s t a n t f o r c e components a p p l i e d
% t o t h e s p r i n g
% c - v e c t o r of v i s c o u s damping c o e f f i c i e n t s f o r
% t h e p a r t i c l e s
N = l e n g t h ( r ); n=N/2; z = r ( 1:n ); v=r(n+1:N); R = f e v a l ( r e,t );
z d i f = d i f f ( [ R ( 1 );z;R ( 2 ) ] ); l e n = a b s ( z d i f ); f s p = z d i f./l e n.* ( ( l e n - L ).* ( l e n - L > 0 ) ).* k; fdamp=-c.*v; a c c e l = ( f e x t + f d a m p + f s p ( 2:n + 1 ) - f s p ( 1:n ) )./m;
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
r d o t = [ v;a c c e l ];
%=====================================
f u n c t i o n rends=endmo(t)
%
% rends=endmo(t)
% This f u n c t i o n s p e c i f i e s t h e v a r y i n g end p o s i t i o n s. % I n t h i s example t h e ends r o t a t e a t fr equenc y omega % around c i r c l e s of r a d i u s Rend.
%
% User m f u n c t i o n s c a l l e d: none
%-----------------------------------------------------------------------------------------
g l o b a l zend Rend omega
s=Rend*exp(i*omega*t); r e n d s = [ s,z e n d - c o n j ( s ) ]; %=============================================
% f u n c t i o n p l o t m o t n ( x,y,t i t l,i s a v e )
% See Appendix B
Chapiter 9
Boundary Value Problems for Partial Differential Equations
9.1 Several Important Partial Differential Equations
Many physical phenomena are characterized by linear partial differential equa­
tions. Such equations are attractive to study because (a) principles of superposition apply in the sense that linear combinations of component solutions can often be used to build more general solutions and (b) finite difference or finite element approxima­
tions lead to systems of linear equations amenable to solution by matrix methods. The accompanying table lists several frequently encountered equations and some ap­
plications. We only show one- or two-dimensional forms, although some of these equations have relevant applications in three dimensions.
In most practical applications the differential equations must be solved within a finite region of space while simultaneously prescribing boundary conditions on the function and its derivatives. Furthermore, initial conditions may exist. In dealing with the initial value problem, we are trying to predict future system behavior when initial conditions, boundary conditions, and a governing physical process are known. Solutions to such problems are seldom obtainable in a closed finite form. Even when series solutions are developed, an infinite number of terms may be needed to pro­
vide generality. For example, the problem of transient heat conduction in a circular cylinder leads to an infinite series of Bessel functions employing characteristic val­
ues which can only be computed approximately. Hence, the notion of an “exact” solution expressed as an infinite series of transcendental functions is deceiving. At best, we can hope to produce results containing insignificantly small computation errors.
The present chapter applies eigenfunction series to solve nine problems. Examples involving the Laplace, wave, beam, and heat equations are given. Nonhomogeneous boundary conditions are dealt with in several instances. Animation is also provided whenever it is helpful to illustrate the nature of the solutions.
Equation
Equation
Name
Applications
Uxx Uyy — OiUf
Heat
Tr ansi ent heat conduct i on
uxx + uyy = QUft
Wave
Tr ansver se vi br at i ons of membr anes and ot her wave t ype phenomena
uxx + uyy = 0
Laplace
Steady-state heat conduction and electrostatics
Ί^χχ + 'Uyy f (■£? y )
Poisson
Stress analysis of linearly elastic bodies
Uxx Uyy UJ U — 0
Helmholtz
Steady-state harmonic vibration problems
Flyxxxx = Affytt + f ( x:t)
Beam
Tr ansver se f l exur al vi br at i ons of el ast i c beams
9.2 Sol vi ng t he Lapl ace Equat i on i nsi de a Rect angul ar Regi on
Funct i ons whi ch sat i sf y Lapl ace’s equat i on ar e encount er ed of t en i n pr act i ce. Such f unct i ons ar e cal l ed har moni c; and t he pr obl em of det er mi ni ng a har moni c f unct i on subj ect t o gi ven boundar y val ues i s known as t he Di r i chl et pr obl em [119]. I n a f ew cases wi t h si mpl e geomet r i es, t he Di r i chl et pr obl em can be sol ved expl i ci t l y. One i nst ance is a r ect angul ar r egi on wi t h t he boundar y val ues of t he f unct i on bei ng expandabl e i n a Four i er si ne seri es. The f ol l owi ng pr ogr am empl oys t he FFT t o con­
st r uct a sol ut i on f or boundar y val ues r epr es ent ed by pi ecewi se l i near i nt er pol at i on. Sur f ace and cont our pl ot s of t he r esul t i ng f i el d val ues ar e al so pr esent ed.
The pr obl em of i nt er est sat i sfi es t he di f f er ent i al equat i on
d2u d2u dx2 dy2
0
0 < x < a
with the boundary conditions of the form
0 < y <b
u(x, 0) — F(x) u(x, b) — G(x) u(0,y) — P (y) u( a,y ) — Q(y)
0 < x < a . 0 < x < a 0 < y <b , 0 < y < b.
The ser i es sol ut i on can be r epr es ent ed as
tt
u(x,y) — ^ f nan(x,y) + gnan(x, b - y) +Pnbn(x,y) + qnbn(a - x,y)
n=1
where
'nKx'
sinh
^(b — y)
/ sinh
nKb
sin
a
a
a
bn(x,y) = sinh
ηπ(α —x)
b
n^y
~b~
/ sinh
b
and the constants f m, gm, pn, and qn are coefficients in the Fourier sine expansions of the boundary value functions. This implies that
F(x) = Σ fn sir
, G(x) = ^ gn sir
P( y ) = Σ Pn sin
n=1
n'Ky
b
Q(y) = Σ
= 7 ^ qn sin 1
n^y
The coefficients in the series can be computed by integration as
F(x) sin
2 i a
dx , gn = — G(x) sin
dx,
Pn = - P(y) sin
nKy
b
dy , qn = - Q(y) sin
nny
b
dy,
or approximate coefficients can be obtained using the FFT. The latter approach is chosen here and the solution is evaluated for an arbitrary number of terms in the series.
The chosen problem solution has the disadvantage of employing eigenfunctions that vanish at the ends of the expansion intervals. Consequently, it is desirable to combine the series with an additional term allowing exact satisfaction of the corner conditions for cases where the boundary value functions for adjacent sides agree. This implies requirements such as F(a) = Q(0) and three other similar conditions. It is evident that the function
n
a
a
b
a
a
a
0
0
b
b
0
0
up(x, y) = ci + c2x + c3y + c4xy
is harmonic and varies linearly along each side of the rectangle. Constants c 1, · · · ,c4 can be computed to satisfy the corner values and the total solution is represented as up plus a series solution involving modified boundary conditions.
The following program laplarec solves the Dirichlet problem for the rectangle. Function values and gradient components are computed and plotted. Functions used in this program are described below. The example data set defined in the driver program was chosen to produce interesting surface and contour plots. Different boundary conditions can be handled by slight modifications of the input data. In this example 100 term series are used.
Figure 9.1 through Figure 9.4 show function and gradient components, as well as a contour plot of function values. Readers may find it instructive to run the program and view these figures from different angles
laplarec
inputs data, calls computation modules, and
plots results
datafunc
defines an example datacase
ulinbc
particular solution for linearly varying
boundary conditions
recseris
sums the series for function and gradient val­
ues
sincof
generates coefficients in a Fourier sine series
lintrp
piecewise linear interpolation function allow­
ing jump discontinuities
using the interactive figure rotating capability provided in MATLAB. Note that the figure showing the function gradient in the x direction used view([225,20]) to show clearly the jump discontinuity in this quantity.
y direction U(X,Y)
HARMONIC FUNCTION IN A RECTANGLE
0 0
Figure 9.1: Surface Plot of Function Values
Contour Plot
2
3
y axis
x axis
- 1
- 0
- -1
x direction
Figure 9.2: Contour Plot of Function Values
DU(X,Y)/DY DU(X,Y)/DX
DERIVATIVE OF U(X,Y) IN THE X DIRECTION
4
3
2
1
0
-1
-2
- 3
- 4
- 5
3
5 - |
Figure 9.3: Function Derivative in the x Direction
DERIVATIVE OF U(X,Y) IN THE Y DIRECTION
Figure 9.4: Function Derivative in the y Direction
0
0 2
3
MATLAB Example Program laplarec
i: f u n c t i o n [ u,u x,u y,X,Y ] = l a p l a r e c (...
2: u b o t,u t o p,u l f t,u r h t,a,b,n x,n y,N )
3: %
4: % [ u,u x,u y,X,Y ] = l a p l a r e c (...
5: % u b o t,u t o p,u l f t,u r h t,a,b,n x,n y,N )
6: %
7: % T h i s p r o g r a m e v a l u a t e s a h a r mo n i c f u n c t i o n and i t s 8: % f i r s t p a r t i a l d e r i v a t i v e s i n a r e c t a n g u l a r r e g i o n.
9: % The met hod empl oys a F o u r i e r s e r i e s e x p a n s i o n. i o: % u b o t - d e f i n e s t h e b o u n d a r y v a l u e s on t h e b o t t o m i i: % s i d e. T h i s c a n be an a r r a y i n whi c h
i 2: % u b o t (:,1 ) i s x c o o r d i n a t e s and u b o t (:,2 )
i 3: % i s f u n c t i o n v a l u e s. Va l u e s a t i n t e r m e d i a t e
i 4: % p o i n t s a r e o b t a i n e d by p i e c e w i s e l i n e a r
i 5: % i n t e r p o l a t i o n. A c h a r a c t e r s t r i n g g i v i n g
i 6: % t h e name o f a f u n c t i o n c a n a l s o be u s e d.
i 7: % Then t h e f u n c t i o n i s e v u a l u a t e d u s i n g 200
i 8: % p o i n t s a l o n g a s i d e t o c o n v e r t u b o t t o an
i 9: % a r r a y. S i m i l a r comments a p p l y f o r u t o p,
2 0: % u l f t, and u r h t i n t r o d u c e d be l o w.
2 i: % u t o p - b o u n d a r y v a l u e d e f i n i t i o n on t h e t o p s i d e
2 2: % u l f t - b o u n d a r y v a l u e d e f i n i t i o n on t h e l e f t s i d e
2 3: % u r h t - b o u n d a r y v a l u e d e f i n i t i o n on t h e r i g h t s i d e
2 4: % a,b - r e c t a n g l e d i m e n s i o n s i n x and y d i r e c t i o n s
2 5: % n x,n y - number of x and y v a l u e s f o r whi c h t h e 2 6: % s o l u t i o n i s e v a l u a t e d
2 7: % N - number of t e r m s u s e d i n t h e F o u r i e r s e r i e s
2 8: % u - f u n c t i o n v a l u e f o r t h e s o l u t i o n
2 9: % u x,u y - f i r s t p a r t i a l d e r i v a t i v e s o f t h e s o l u t i o n
3 0: % X,Y - c o o r d i n a t e p o i n t a r r a y s wher e t h e s o l u t i o n
3 i: % i s e v a l u a t e d
3 2: %
3 3: % Us e r m f u n c t i o n s u s e d: d a t a f u n c u l i n b c 34: % r e c s e r i s f t s i n c o f
35:
3 6: d i s p (' ')
3 7: di sp('SOLVI NG THE LAPLACE EQUATION IN A RECTANGLE')
3 8: d i s p (' ')
39:
4 0: i f n a r g i n = = 0
4 i
42
43:
44
45
46
47
48
49
50:
5 i
52:
53:
54:
55:
56
57
58
59:
60:
6 i:
62:
63:
64:
65:
66
67:
68
69:
70:
7 i
72:
73:
74:
75:
76
77
78
79:
80:
8 i
82:
83:
84:
85:
d i s p (...
'Give t h e name of a f u n c t i o n d e f i n i n g t h e d a t a') d a t f u n = i n p u t (...
'( t r y d a t a f u n c as an example): > ? ','s'); [ u b o t,u t o p,u l f t,u r h t,a,b,n x,n y,N ] = f e v a l ( d a t f u n );
end
% C r ea t e a g r i d t o e v a l u a t e t h e s o l u t i o n
x = l i n s p a c e ( 0,a,n x ); y = l i n s p a c e ( 0,b,n y );
[X,Y]=meshgrid(x,y); d=(a+b)/1e6;
x d = l i n s p a c e ( 0,a,2 0 1 )'; y d = l i n s p a c e ( 0,b,2 0 1 )';
% Check whether boundary v a l u e s a r e gi ven u s i n g
% e x t e r n a l f u n c t i o n s. Convert t h e s e t o a r r a y s
i f i s s t r ( u b o t )
u d = f e v a l ( u b o t,x d ); u b o t = [ x d,u d (:) ];
end
i f i s s t r ( u t o p )
u d = f e v a l ( u t o p,x d ); u t o p = [ x d,u d (:) ];
end
i f i s s t r ( u l f t )
u d = f e v a l ( u l f t,y d ); u l f t = [ y d,u d (:) ];
end
i f i s s t r ( u r h t )
u d = f e v a l ( u r h t,y d ); u r h t = [ y d,u d (:) ];
end
% Determine f u n c t i o n v a l u e s a t t h e c o r n e r s
u b = i n t e r p 1 ( u b o t (:,1 ),u b o t ( u t = i n t e r p 1 ( u t o p (:,1 ),u t o p ( u l = i n t e r p 1 ( u l f t (:,1 ),u l f t ( u r = i n t e r p 1 ( u r h t (:,1 ),u r h t (: U = [ u l ( 1 ) + u b ( 1 ),u b ( 2 ) + u r ( 1 ),u r ( 2 ) + u t ( 2 ),... u t ( 1 ) + u l ( 2 ) ]/2;
,2) ,[ d,a - d ] ) ,2) ,[ d,a - d ] ) ,2) ,[ d,b - d ] ) ,2) ,[ d,b - d ] )
% Obtain a s o l u t i o n s a t i s f y i n g t h e co r n e r % v a l u e s and v a r y i n g l i n e a r l y al ong t h e s i d e s
[ v,v x,v y ] = u l i n b c ( U,a,b,X,Y );
% Reduce t h e co r n e r v a l u e s t o z e r o t o improve % b e h a v i o r of t h e F o u r i e r s e r i e s s o l u t i o n % n e a r t h e c o r n e r s
86: f = i n l i n e ('u 0 + ( u 1 - u 0 )/L * x','x', 'u 0','u 1','L');
8 7: u b o t (:,2 ) = u b o t (:,2 ) - f ( u b o t (:,1 ),U ( 1 ),U ( 2 ),a );
8 8: u t o p (:,2 ) = u t o p (:,2 ) - f ( u t o p ( :,1 ),U ( 4 ),U ( 3 ),a );
8 9: u l f t (:,2 ) = u l f t (:,2 ) - f ( u l f t (:,1 ),U ( 1 ),U ( 4 ),b );
9 0: u r h t (:,2 ) = u r h t (:,2 ) - f ( u r h t (:,1 ),U ( 2 ),U ( 3 ),b );
9 i:
9 2: % E v a l u a t e t h e s e r i e s and combi ne r e s u l t s 93: % f o r t h e v a r i o u s component s o l u t i o n s
94:
9 5: [ u b,u b x,u b y ] = r e c s e r i s ( u b o t,a,b,1,x,y,N );
9 6: [ u t,u t x,u t y ] = r e c s e r i s ( u t o p,a,b,2,x,y,N );
9 7: [ u l,u l x,u l y ] = r e c s e r i s ( u l f t,a,b,3,x,y,N );
9 8: [ u r,u r x,u r y ] = r e c s e r i s ( u r h t,a,b,4,x,y,N );
9 9: u = v + u b + u t + u l + u r; u x =v x +u bx+ut x+ul x+ur x; i 0 0: uy=v y +u b y +u t y +u l y +u r y; c l o s e
i 0 i:
i 0 2: % Show r e s u l t s g r a p h i c a l l y
i 0 3:
i 0 4: s u r f c ( X,Y,u ), x l a b e l ('x a x i s'), y l a b e l ('y a x i s') i 0 5: z l a b e l ('U ( X,Y )')
i 0 6: t i t l e('HARMONI C FUNCTION IN A RECTANGLE')
i 0 7: s h g, p a u s e
i 0 8: % p r i n t - d e p s l a p r e c s r
i 0 9:
i i 0: c o n t o u r ( X,Y,u,3 0 ); t i t l e ('C o n t o u r P l o t'); i i i: x l a b e l ('x d i r e c t i o n'); y l a b e l ('y d i r e c t i o n'); i i 2: c o l o r b a r, s h g, p a u s e i i 3: % p r i n t - d e p s l a p r e c n t
i i 4:
i i 5: s u r f ( X,Y,u x ), x l a b e l ('x a x i s'), y l a b e l ('y a x i s') i i 6: z l a b e l ('D U ( X,Y )/D X')
i i 7: t i t l e ('DERI VATI VE OF U(X,Y) IN THE X DIRECTION')
i i 8: s h g, p a u s e
i i 9: % p r i n t - d e p s l a p r e c d x
i 2 0:
i 2 i: s u r f ( X,Y,u y ), x l a b e l ('x a x i s'), y l a b e l ('y a x i s') i 2 2: z l a b e l ('D U ( X,Y )/D Y')
i 2 3: t i t l e ('DERI VATI VE OF U(X,Y) IN THE Y DIRECTION') i 2 4: % p r i n t - d e p s l a p r e c d y
i 2 5: s h g i 2 6:
i 2 7: %============================================
i 2 8:
i 2 9: f u n c t i o n [ u b o t,u t o p,u l f t,u r h t,a,b,...
i 3 0: n x,n y,N ] = d a t a f u n c
132:
133:
134
135:
136:
137:
138:
139
140 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175:
131:
% [ u b o t,u t o p,u l f t,u r h t,a,b,...
% nx,ny,N] =dat af unc
%........................................................................
% This i s a sample d a t a case which can be % modi fi ed t o apply t o o t h e r examples
%
%
% u b o t, ut op - v e c t o r s of f u n c t i o n v a l u e s on t h e
% bottom and t o p s i d e s
% u l f t, u r h t - v e c t o r s of f u n c t i o n v a l u e s on t h e
% r i g h t and l e f t s i d e s
% a, b - r e c t a n g l e dimensions al ong t h e
% x and y a x i s
% nx, ny - number of g r i d v a l u e s f o r t h e x
% and y d i r e c t i o n s
% N - number of terms used i n t h e
% F o u r i e r s e r i e s s o l u t i o n
a=3; b=2; e=1e-5; N=100; x = l i n s p a c e ( 0,1,2 0 1 )'; s = s i n ( p i * x ); c= c o s ( p i * x ); u b o t = [ a * x,2 - 4 * s ]; u t o p = [ a * x,i n t e r p 1 ( [ 0,1/3,2/3,1 ],...
[ - 2,2,2,- 2 ],x ) ]; u l f t = [ b * x,2 * c ]; u r h t = u l f t; nx=51; ny=31;
%============================================
f u n c t i o n [ u,u x,u y ] = u l i n b c ( U,a,b,X,Y )
%
% [ u,u x,u y ] = u l i n b c ( U,a,b,X,Y )
%..................................................................
% This f u n c t i o n de t e r mi ne s a harmonic f u n c t i o n % v a r y i n g l i n e a r l y al ong t h e s i d e s of a r e c t a n g l e % wi t h s p e c i f i e d c o r n e r v a l u e s
%
% U - co r n e r v a l u e s of t h e harmonic f u n c t i o n % [ U ( 1 ),...U ( 4 ) ] <=> co r n e r c o o r d i n a t e s
% ( 0,0 ), ( 0,a ), ( a,b ), (0,b)
% a,b - r e c t a n g l e dimensions i n t h e x and y
% d i r e c t i o n s
% X,Y - a r r a y c o o r d i n a t e s where t h e s o l u t i o n
% i s e v a l u a t e d
% u - f u n c t i o n v a l u e s e v a l u a t e d f o r X,Y
% ux,uy - f i r s t d e r i v a t i v e components e v a l u a t e d
% f o r t h e X,Y a r r a y s
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
c = [ 1,0,0,0;1,a,0,0;1,a,b,a * b;1,0,b,0;]\U (:); u=c(1)+c(2)*X+c(3)*Y+c(4)*X.*Y; ux=c(2)+c(4)*Y; uy=c(3)+c(4)*X;
%============================================
f u n c t i o n [ u,u x,u y,X,Y ] = r e c s e r i s ( u d a t,a,b,i s i d e,x,y,N ) %
% [ u,u x,u y,X,Y ] = r e c s e r i s ( u d a t,a,b,i s i d e,x,y,N )
%...............................................................................................................
% This f u n c t i o n computes a f u n c t i o n harmonic i n % a r e c t a n g l e wi t h g e n e r a l f u n c t i o n v a l u e s gi ven % on one s i d e and ze ro f u n c t i o n v a l u e s on t h e % o t h e r t h r e e s i d e s.
% udat - a d a t a a r r a y t o det er mi ne t h e f u n c t i o n % v a l u e s by p i e c e w i s e l i n e a r i n t e r p o l a t i o n
% al ong t h e s i d e havi ng nonzero v a l u e s.
% u d a t (:,1 ) c o n t a i n s e i t h e r x or y v a l u e s
% al ong a s i d e, and u d a t (:,2 ) c o n t a i n s
% c or r e s p o n d i n g f u n c t i o n v a l u e s
% a,b - s i d e l e n g t h s f o r t h e x and y d i r e c t i o n s
% i s i d e - an index i n d i c a t i n g t h e s i d e f o r which
% f u n c t i o n v a l u e s a r e gi ven.
% [ 1,2,3,4 ] < = > [ b o t t o m,t o p,l e f t,r i g h t ]
% x,y d a t a v e c t o r s d e f i n i n g a g r i d
% [X,Y]=meshgrid(x,y) on which t h e f u n c t i o n
% and i t s f i r s t p a r t i a l d e r i v a t i v e s a r e
% computed
% N - number of s e r i e s terms used (up t o 500)
% u,u x,u y - a r r a y s of v a l u e s of t h e harmonic f u n c t i o n
% and i t s f i r s t p a r t i a l d e r i v a t i v e s
% X,Y a r r a y s of c o o r d i n a t e v a l u e s f o r which
% f u n c t i o n v a l u e s were computed.
x = x (:) ’; y = y (:); n y = l e n g t h ( y ); N=min(N,500); i f i s i d e < 3, period=2*a; e l s e, period=2*b; end c = f t s i n c o f ( u d a t,p e r i o d ); n=1:N; c=c(n); i f i s i d e < 3 % t o p or bottom s i d e s
npa=pi/a*n; c = c./( 1 - e x p ( - 2 * b * n p a ) ); s x = s i n ( n p a (:) * x ); c x = c o s ( n p a (:) * x ); i f isi de==1 % bottom s i d e
dy=exp(-y*npa); e y = e xp( - ( 2*b- y) *npa );
u = r e p m a t ( c,n y,1 ).* ( d y - e y ) * s x;
c = r e p m a t ( c.* n p a,n y,1 );
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
u x =c.*( dy- ey) *cx; uy=-c.*( dy+ey)*sx; e l s e % t o p s i d e
dy=exp( ( y- b) *npa); ey=exp(-( y+b)*npa); u = r e p m a t ( c,n y,1 ).* ( d y - e y ) * s x; c = r e p m a t ( c.* n p a,n y,1 ); u x =c.*( dy- ey) *cx; uy=c.*(dy+ey)*sx;
end
e l s e % l e f t or r i g h t s i d e s
npb=pi/b*n; c = c./( 1 - e x p ( - 2 * a * n p b ) ); sy=s i n( y*npb); cy=cos(y*npb); i f i s i de==3 % l e f t s i d e d x = e x p ( - n p b (:) * x ); e x = e x p ( - n p b (:) * ( 2 * a - x ) ); u = r e p m a t ( c,n y,1 ).* s y * ( d x - e x ); c = r e p m a t ( c.* n p b,n y,1 ); u x = c.* s y * ( - d x - e x ); u y =c.*cy*( dx- ex); e l s e % r i g h t s i d e
d x = e x p ( - n p b (:) * ( a - x ) ); e x = e x p ( - n p b (:) * ( a + x ) ); u = r e p m a t ( c,n y,1 ).* s y * ( d x - e x ); c = r e p m a t ( c.* n p b,n y,1 ); ux=c.*sy*(dx+ex); uy=c.*cy*( dx- ex);
end
end
[X,Y]=meshgrid(x,y);
%===========================================
f u n c t i o n c = f t s i n c o f ( y,p e r i o d )
%
% c = f t s i n c o f ( y,p e r i o d )
% This f u n c t i o n computes 500 F o u r i e r s i n e % c o e f f i c i e n t s f o r a p i e c e w i s e l i n e a r % f u n c t i o n d e f i n e d by a d a t a a r r a y % y - an a r r a y d e f i n i n g t h e f u n c t i o n
% over h a l f a p e r i o d as
% Y ( x ) = i n t e r p 1 ( y (:,1 ),y (:,2 ),x )
% p e r i o d - t h e p e r i o d of t h e f u n c t i o n %
x f t = l i n s p a c e ( 0,p e r i o d/2,5 1 3 ); u f t = i n t e r p 1 ( y (:,1 ),y (:,2 )/5 1 2,x f t ); c = f f t ( [ u f t,- u f t ( 5 1 2:- 1:2 ) ] ); c = - i m a g ( c ( 2:5 0 1 ) );
9.3 The Vibrating String
Transverse motion of a tightly stretched string illustrates one of the simplest oc­
currences of one-dimensional wave propagation. The transverse deflection satisfies the wave equation
2 d2u d2u
a —
dX2 dT 2
where u(X, T ) satisfies initial conditions
u(X,0) = F(X), = G(X )
with boundary conditions
u(0, T) = 0 , u( i, T ) = 0
where i is the string length. If we introduce the dimensionless variables x = X/i and t = T/( i/a) the differential equation becomes
uxx = utt
where subscripts denote partial differentiation. The boundary conditions become
u(0, t) = u(1,t) = 0 and the initial conditions become
u(x, 0) = f (x) , ut(x, 0) = g(x).
Let us cons i der t he case wher e t he st r i ng i s r el eas ed f r om r est i ni t i al l y so g(x) = 0. The solution can be found in series form as
i(x,t) = ^ anPn(x) COs(unt)
wher e ωη are natural frequencies and satisfaction of the differential equation of mo­
tion requires
pn(x) +u2nPn(x) = 0
so
Pn = An sin(^nx) + Bn COs(^nx).
The boundar y condi t i on
p n(0) = Bn = 0 andpn(l) = An sin(wn) requires An = 0 and u n = ηπ, where n is an integer. This leads to a solution in the form
tt
u(x,t) an sin(nπx)cos(nπt).
n=1
The remaining condition on initial conditions requires
tt
an sin(nπx) = f (x) , 0 < x < l.
n=1
Therefore, the coefficients an are obtainable from an odd-valued Fourier series ex­
pansion of f (x) vanishing at x = 0 and x = 2. We see that f (—x) = —f (x) and f (x + 2) = f (x), and the coefficients are obtainable by integration as
However, an easier way to compute the coefficients is to use the FFT. A solution will be given for an arbitrary piecewise linear initial condition.
Before implementing the Fourier series solution, let us digress briefly to examine the case of an infinite string governed by
u(X, 0) = F ( X ) , uT(X, 0) = G( X).
The r eader can ver i f y di r ect l y t hat t he sol ut i on of t hi s pr obl em is gi ven by
When t he st r i ng is r el eas ed f r om rest, G( X) is zero and the solution reduces to
F(X - aT) + F( X + aT)
2
whi ch shows t hat t he i ni t i al def l ect i on spl i t s i nt o t wo par t s wi t h one hal f t r ansl at i ng t o t he l ef t at speed a and the other half moving to the right at speed a. This solution can also be adapted to solve the problem for a string of length i fixed at each end. The condition u(0, T) = 0 implies
F (—aT) = —F (aT )
which shows that F ( X ) must be odd valued. Similarly, u ( i,T) = 0 requires
F (i — aT ) + F (i + aT) =0.
Combining this condition with F ( X ) = —F ( X ) shows that
F (X + 2i) = F (X)
an = 2 f (x) sin(nπx) dx.
a2u x x = utt , —^ < X <
and i ni t i al condi t i ons
1 l f x +al
u{X, T) = - [F(X - aT) + F( X + aT)} + 77- G(x) dx
2 2a x aT
rX+aT
so, F( X) must have a period of 2i. In the string of length i, F( X) is only known for 0 < X < i, and we must take
F(X) = —F(2i — X ) , i < X < 2i.
Fur t her mor e t he sol ut i on has t he f or m
/v rji\ F{xp) -\- F{xm) u{X,T) = -------------- ---------------
where xp = X + aT and x m = X — aT. The quantity x p will always be positive and x m can be both positive and negative. The necessary sign change and periodicity can be achieved by evaluating F ( X ) as
sign(X).*F(rem(abs(X)), 2 * i)
wher e r e m i s t he i nt r i nsi c r emai nder f unct i on us ed i n t he exact sol ut i on i mpl ement ed i n f unct i on s t r ngwa v pr es ent ed ear l i er i n sect i on 2.7.
A comput er pr ogr am empl oyi ng t he Four i er ser i es sol ut i on was wr i t t en f or an i ni t i al def l ect i on t hat i s pi ecewi se l i near. The ser i es sol ut i on al l ows t he us er t o sel ect var yi ng number s of t er ms i n t he ser i es t o exami ne how wel l t he i ni t i al def l ect i on conf i gur at i on is r epr es ent ed by a t r uncat ed si ne ser i es. A f unct i on ani mat i ng t he t i me r es ponse shows cl ear l y how t he i ni t i al def l ect i on spl i t s i n t wo par t s t r ansl at i ng i n oppos i t e di r ect i ons. I n t he Four i er sol ut i on, di mensi onl ess var i abl es ar e empl oyed t o make t he st r i ng l engt h and t he wave s peed bot h equal one. Consequent l y, t he t i me r equi r ed f or t he mot i on t o exact l y r et ur n t o t he st ar t i ng posi t i on equal s t wo, r epr esent i ng how l ong i t t akes f or a di st ur bance t o pr opagat e f r om one end t o t he ot her and back. When t he mot i on is obser ved f or 0 < x < l, it is evident that waves reflected from a wall are inverted. The program employs the following functions.
stringft
function to input initial deflection data
sincof
uses fft to generate coefficients in a sine series
initdefl
defines the initial deflection by piecewise linear
interpolation
strvib
evaluates the series solution for general x and t
s mot i on
ani mat es t he st r i ng mot i on
i nput v
f aci l i t at es i nt er act i ve dat a i nput
l i n t r p
per f or ms i nt er pol at i on t o eval uat e a pi ecewi se
l i near f unct i on
Resul t s ar e shown bel ow f or a st r i ng whi ch was def l ect ed i ni t i al l y i n a squar e wave. The exampl e was chosen t o i l l ust r at e t he appr oxi mat i on pr oduced when a smal l number of Four i er coef f i ci ent s, i n t hi s cas e 30, is used. Ri ppl es ar e cl ear l y evi dent i n t he sur f ace pl ot of u(x, t) in
Figure 9.5.
The deflection configuration of
Figure 9.5: String Deflection as a Function of Position and Time
the string at t = 1 when the initial deflection form has passed through half a period of motion appears in
Figure 9.6.
One other example given in
Figure 9.7 shows the deflection surface produced using 100 series terms and a triangular initial deflection pattern. The surface describes u(x, t)
through one period of motion.
transverse deflection
Wave Propagation in a String
Figure 9.7: Surface for Triangular Initial Deflection
Program Output and Code Output from Example stringft >> s t r i n g f t;
FOURIER SERIES SOLUTION FOR WAVES IN A STRING WITH LINEARLY INTERPOLATED INITIAL DEFLECTION AND FIXED ENDS
E n t e r t h e number o f i n t e r i o r d a t a p o i n t s ( t h e f i x e d end p o i n t c o o r d i n a t e s a r e a dde d a u t o m a t i c a l l y )
? 4
The s t r i n g s t r e t c h e s b e t we e n f i x e d e n d p o i n t s a t x =z e r o and x=one.
E n t e r 4 s e t s of x,y t o s p e c i f y i n t e r i o r i n i t i a l d e f l e c t i o n s (one p a i r p e r l i n e )
? .3 3,0 ? .3 3,- 1 ? .6 7,- 1 ? .6 7,0
Gi ve t h e number o f s e r i e s t e r ms and t h e maximum v a l u e o f t ( g i v e 0,0 t o s t o p )
? 30,1
P r e s s [ E n t e r ] t o s e e t h e a n i m a t i o n
Gi ve t h e number o f s e r i e s t e r ms and t h e maximum v a l u e o f t ( g i v e 0,0 t o s t o p )
? 0,0 >>
String Vibration Program
i: f u n c t i o n [ x,t,y ] = s t r i n g f t ( X d a t,Y d a t ) 2: %
3:
4:
5:
6:
7:
8:
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
35
36
37
38
39
40:
41
42
43
44
45
46
47
% Example: [ x,t,y ] = s t r i n g f t ( X d a t,Y d a t )
% This program an a l y z e s wave motion i n a s t r i n g % havi ng a r b i t r a r y p i e c e w i s e l i n e a r i n i t i a l % d e f l e c t i o n. A F o u r i e r s e r i e s expansion i s used % t o c o n s t r u c t t h e s o l u t i o n %
% Xdat,Ydat - d a t a v e c t o r s d e f i n i n g t h e i n i t i a l
% d e f l e c t i o n s a t i n t e r i o r p o i n t s. The
% d e f l e c t i o n s a t x=0 and x=1 a r e s e t
% t o xero a u t o m a t i c a l l y. For example,
% t r y X d a t = [.2,.3,.7,.8 ],
% Y d a t = [ 0,- 1,- 1,0 ]
%
% x,t,y - a r r a y s c o n t a i n i n g t h e p o s i t i o n, time % and d e f l e c t i o n v a l u e s
%
% User m f u n c t i o n s r e q u i r e d:
% s i n c o f, i n i t d e f l, s t r v i b, smotion, i n p u t v,
% l i n t r p
g l o b a l xdat ydat
d i s p (' '), d i s p ( ...
' FOURIER SERIES SOLUTION FOR WAVES') d i s p (....
'IN A STRING WITH LINEARLY INTERPOLATED') d i s p (...'
' INITIAL DEFLECTION AND FIXED ENDS') i f nargin==0 d i s p (' ')
d i s p ( ['E n t e r t h e number of i n t e r i o r ',...
'd a t a p o i n t s ( t h e f i x e d'] ) d i s p ( ['e n d p o i n t c o o r d i n a t e s a r e ',...
'added a u t o m a t i c a l l y )'] ) n = i n p u t ('? '); i f i s e m p t y ( n ), b r e a k, end x d a t = z e r o s ( n + 2,1 ); yd a t =x d a t; xdat(n+2)=1; d i s p (' ')
d i s p ( ['T h e s t r i n g s t r e t c h e s between ',...
'f i x e d e n d p o i n t s a t'] ) d i s p ('x = z e r o and x=one. '),d i s p (' ') d i s p ( ['E n t e r ',n u m 2 s t r ( n ),...
' s e t s of x,y t o s p e c i f y i n t e r i o r'] ) d i s p ( ['i n i t i a l d e f l e c t i o n s ',...
'( o n e p a i r p e r l i n e )'] ), d i s p (' ')
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
f o r j = 2:n + 1,[ x d a t ( j ),y d a t ( j ) ] = i n p u t v; end; e l s e
x d a t = [ 0;X d a t (:);1 ]; y d a t = [ 0;Y d a t (:);0 ]; end
a = s i n c o f ( @ i n i t d e f l,1,1 0 2 4 ); % s i n e c o e f f i c i e n t s nx=51; x = l i n s p a c e ( 0,1,n x ); x x = l i n s p a c e ( 0,1,1 5 1 );
whi l e 1 d i s p (' ')
d i s p ('G i v e t h e number of s e r i e s t e r m s') d i s p ('a n d t h e maximum v a l u e of t') d i s p ('( g i v e 0,0 t o s t o p )')
[ nt r ms,t max] =i nput v;
i f i s n a n ( n t r m s ) | norm([ntrms,tmax])==0 b r e a k, end
n t = c e i l ( n x * t m a x ); t = l i n s p a c e ( 0,t m a x,n t );
y = s t r v i b ( a,t,x,1,n t r m s ); % ti me h i s t o r y
y y = s t r v i b ( a,t,x x,1,n t r m s );
[ x o,t o ] = m e s h g r i d ( x,t );
ho l d o f f; s u r f ( x o,t o,y );
g r i d on; colormap([1 1 1 ] );
%colormap([127/255 1 2 1 2/2 5 5 ] ); x l a b e l ('x a x i s'); y l a b e l ('t i m e a x i s'); z l a b e l ('t r a n s v e r s e d e f l e c t i o n'); t i t l e ( ['S t r i n g D e f l e c t i o n as a Funct i on ', ...
'o f P o s i t i o n and T i m e'] ); d i s p (' '), d i s p ('P r e s s [Enter] t o') d i s p ('s e e t h e a n i m a t i o n'), shg, pause % p r i n t -deps s t r d e f l
smot ion( xx,yy,'Wave P r o p a g a t i o n i n a S t r i n g'); d i s p (''); p a u s e ( 1 ); end
% p r i n t -deps strwave %=============================================
f u n c t i o n y = i n i t d e f l ( x )
%
% y = i n i t d e f l ( x )
% This f u n c t i o n d e f i n e s t h e l i n e a r l y % i n t e r p o l a t e d i n i t i a l d e f l e c t i o n % c o n f i g u r a t i o n.
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
%
% x - a v e c t o r of p o i n t s a t which t h e i n i t i a l
% d e f l e c t i o n i s t o be computed
%
% y - t r a n s v e r s e i n i t i a l d e f l e c t i o n v a l u e f o r
% argument x
%
% x d a t, ydat - g l o b a l d a t a v e c t o r s used f o r % l i n e a r i n t e r p o l a t i o n
%
% User m f u n c t i o n s r e q u i r e d: l i n t r p
%-----------------------------------------------------------------------------------------
g l o b a l xdat ydat y = l i n t r p ( x d a t,y d a t,x );
%=============================================
f u n c t i o n y = s t r v i b ( a,t,x,h p,n )
%
% y = s t r v i b ( a,t,x,h p,n )
%...................................................
% Sum t h e F o u r i e r s e r i e s f o r t h e s t r i n g motion. %
% a - F o u r i e r c o e f f i c i e n t s of i n i t i a l % d e f l e c t i o n
% t,x - v e c t o r s of time and p o s i t i o n v a l u e s % hp - t h e h a l f p e r i o d f o r t h e s e r i e s % expansion
% n - t h e number of s e r i e s terms used %
% y - m a t r i x wi t h y ( i,j ) equal t o t h e % d e f l e c t i o n a t p o s i t i o n x ( i ) and
% t ime t ( j )
%
% User m f u n c t i o n s r e q u i r e d: none %-----------------------------------------------------------------------------------------
w= p i/hp*( 1:n); a = a ( 1:n ); a = a (:)'; x = x (:); t = t (:)';
y = ( ( a ( o n e s ( l e n g t h ( x ),1 ),:).* ... s i n ( x * w ) ) * c o s ( w (:) * t ) )';
%=============================================
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
f u n c t i o n s m o t i o n ( x,y,t i t l )
%
% s m o t i o n ( x,y,t i t l )
% This f u n c t i o n animates t h e s t r i n g motion.
%
% x - a v e c t o r of p o s i t i o n v a l u e s al ong t h e
% s t r i n g
% y - a m a t r i x of t r a n s v e r s e d e f l e c t i o n
% v a l u e s where s u c c e s s i v e rows gi ve
% d e f l e c t i o n s a t s u c c e s s i v e t i mes
% t i t l - a t i t l e shown on t h e p l o t ( o p t i o n a l ) %
% User m f u n c t i o n s r e q u i r e d: none %
---------------------------------------------------------------------------------
i f n a r g i n < 3, t i t l =' end xmin=min(x); xmax=max(x); ymi n=mi n( y(:) ); ymax=max(y(:)); [ n t,n x ] = s i z e ( y ); c l f r e s e t; f o r j = 1:n t
p l o t ( x,y ( j,:),'k'); axis([xmin,xmax,2*ymin,2*ymax]); a x i s ('o f f'); t i t l e ( t i t l ); drawnow; f i g u r e ( g c f ); p a u s e (.1 ) end
%============================================
f u n c t i o n a = s i n c o f ( f u n c,h a f p e r,n f t )
%
% a = s i n c o f ( f u n c,h a f p e r,n f t )
%................................................................
% This f u n c t i o n c a l c u l a t e s t h e s i n e % c o e f f i c i e n t s.
%
% func - t h e name of a f u n c t i o n d e f i n e d over % a h a l f p e r i o d
% h a f p e r - t h e l e n g t h of t h e h a l f p e r i o d of t h e % f u n c t i o n
% n f t - t h e number of f u n c t i o n v a l u e s used
% i n t h e F o u r i e r s e r i e s
%
% a - t h e v e c t o r of F o u r i e r s i n e s e r i e s
% c o e f f i c i e n t s
183: %
1 8 4: % Us e r m f u n c t i o n s r e q u i r e d: none
1 8 5: %-------------------------------------------------------------------------------------------------------------------------------------------------
186:
187: n 2 = n f t/2; x = h a f p e r/n 2 * ( 0:n 2 );
1 8 8: y = f e v a l ( f u n c,x ); y = y (:);
1 8 9: a = f f t ( [ y;- y ( n 2:- 1:2 ) ] ); a = - i m a g ( a ( 2:n 2 ) )/n 2;
1 9 0:
1 9 1: %===========================================
1 9 2:
1 9 3: % f u n c t i o n y = l i n t r p ( x d,y d,x )
1 9 4: % See Appe ndi x B
1 9 5:
1 9 6: %===========================================
1 9 7:
1 9 8: % f u n c t i o n v a r a r g o u t = i n p u t v ( p r o m p t )
1 9 9: % See Appe ndi x B
9.4 Force Moving on an Elastic String
The behavior of a semi-infinite string acted on by a moving transverse force illus­
trates an interesting aspect of wave propagation. Consider a taut string initially at rest and un-deflected when a force moving at constant speed is applied. This simple example shows how a wave front moves ahead of the force when the velocity of wave propagation in the string exceeds the speed of the force, but the force acts at the front of the disturbance when the force moves faster than the wave speed of the string. The governing differential equations, initial conditions, and boundary conditions are:
Fo
a2uxx(x, t ) = Utt(x, t) Η δ(χ — vt ) , t > 0 , 0 < x < oo,
ρ
u(0, t) = 0 , u( t t, t) = 0,
u(x,
0) = 0 , ut (x, 0) = 0 , 0 < x < t t.
I n t hese equat i ons a is the speed of wave propagation in the string and v is the speed at which a concentrated downward force F0 moves toward the right along the string, ρ is the mass per unit length of the string, and δ is the Dirac delta function. This problem can be solved using the Fourier sine transform pair defined by
tt tt
= J u( x,t ) sm( px) dx , u{x^t ) = — J U( p,t ) sm( px) dp. ο ο
Transforming the differential equation and initial conditions, and making use of the boundary conditions gives
Fo
—p2a2U(p, t) = Utt(p, t) + — sin(pvt) , U(p, 0) = 0 , Ut (p, 0) = 0.
ρ
It follows that
U(p, t) =
Fo
ip(a2 — v 2)
v sin(apt) — a sin(vpt)
p2
provided v = a. Applying the inverse transformation then gives the desired displace­
ment response as
u (x, t )
Fo
2ap(a2 — v2)
[ (v — a)x — v \x — at\ + a \x — vt\ ] .
9.4.1 Comput e r Anal ys i s
The f ol l owi ng MATLAB pr ogr am anal yzes t he r es ponse pr edi ct ed by t he l ast equat i on. A sur f ace pl ot shows u(x,t ). Positions of the force at successive times are also marked by a heavy dark line superimposed on the surface. Then an anima­
tion shows the string deflection and the point of action of the force throughout the chosen time interval. As the force moves along the string, no deflection occurs ahead of the force if the speed of the force exceeds the speed of wave propagation for the string. Otherwise, a disturbance propagates ahead of the force at the wave speed of the string. Graphical results from the program are shown first. Then the computer code is listed.
Let us first consider what happens when the force moves slower than the wave speed. Taking so v = 1.0, a =1.2 gives the following results in
Figure 9.8.
Since the point of application of the load is denoted by an arrow, it is clear from the last figure that the disturbance moves ahead of the load when the load moves slower than the wave speed for the string. Next consider what happens when the force moves faster than the wave speed for the string. For example taking v = 1, a = 0.80 gives significantly different output. In this instance, no disturbance occurs at a point until the load passes the point. This case is illustrated in
Figure 9.9.
The reader may find it instructive to run the program for different combinations of force speed and wave speed. The program does not account for the case where v exactly equals a, but these values can be taken close enough together to see what the limiting case will give. We simply increase a to 1.00001 times a.
FORCE SPEED SLOWER THAN THE WAVE SPEED
A = 1.2, V = 1, T = 10.00
Figure 9.8:
Force Moving Slower than the Wave Speed
FORCE SPEED FASTER THAN THE WAVE SPEED
Figure 9.9: Force Moving Faster than the Wave Speed
Program forcmove
[ u,X,T,u f,t ] = f o r c m o v e ( a,v,t m a x,n t )
This f u n c t i o n computes t h e dynamic r e s ponse of a t a u t s t r i n g s u b j e c t e d t o an upward d i r e c t e d c o n c e n t r a t e d f o r c e moving al ong t h e s t r i n g a t c o n s t a n t s p e e d. The s t r i n g i s f i x e d a t x=0 and x = + i n f i n i t y. The system i s i n i t i a l l y a t r e s t when t h e f o r c e s t a r t s moving toward t h e r i g h t from t h e l e f t end. I f t h e f o r c e speed exceeds t h e wave p r o p a g a t i o n speed, t h e n no d i s t u r b a n c e occurs ahead of t h e f o r c e. I f t h e f o r c e speed i s slower t h a n t h e wave p r o p a g a t i o n speed, t h e n t h e d e f l e c t i o n p r o p a g a t e s ahead of t h e f o r c e a t t h e wave p r o p a g a t i o n speed.
v - speed of t h e moving l oad
a - speed of wave p r o p a g a t i o n i n t h e
s t r i n g
tmax - maximum time f o r which t h e s o l u t i o n i s computed u - m a t r i x of d e f l e c t i o n v a l u e s where
time and p o s i t i o n var y row-wise and column-wise, r e s p e c t i v e l y T,X - m a t r i c e s of ti me and p o s i t i o n v a l u e s cor r e s p o n d i n g t o t h e d e f l e c t i o n m a t r i x U
uf - d e f l e c t i o n v a l u e s where t h e f o r c e a c t s
t - v e c t o r of t i me s (same as columns of T)
User m f u n c t i o n s u s e d: u s t r i n g
i f nargin==0, a=.8; v=1; tmax=10; nt=15; end
i f a>v
titl='FORCE SPEED SLOWER THAN THE WAVE SPEED'; e l s e i f a<v
titl='FORCE SPEED FASTER THAN THE WAVE SPEED'; e l s e
f u n c t i o n [ u,X,T,u f,t ] = f o r c m o v e ( a,v,t m a x,n t )
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
74
75
76
77
78
79
80
81
82
83
84
85
86
titl='FORCE SPEED EQUAL TO THE WAVE SPEED'; a=v*1.00001; end
% Obtain s o l u t i o n v a l u e s and p l o t r e s u l t s
[ u,X,T,u f,t ] = u s t r i n g ( a,v,t m a x,n t );
i f a>v, x f = X (:,2 ); u f = u (:,2 ); xw=X(:,3);
e l s e, x f = X (:,3 ); u f = u (:,3 ); end
c l o s e, s u b p l o t ( 2 1 1 )
w a t e r f a l l ( X,T,- u ), x l a b e l ('x a x i s')
y l a b e l ('t i m e'), z l a b e l ('d e f l e c t i o n')
t i t l e ( t i t l ), g r i d on, ho l d on % p l o t 3 ( x f,t,- u f,'.k',x f,t,- u f,'k') p l o t 3 ( x f,t,- u f,'k','l i n e w i d t h',2 ); col ormap([0 0 0 ] ), v i e w ( [ - 1 0,3 0 ] ), shg umi n=mi n( u(:) ); umax=max(u(:)); xmax=X(1,4); range=[0,xmax,2*umin,2*umax]; h o l d on T i t l = ['A = ',n u m 2 s t r ( a ),', V = ',n u m 2 s t r ( v ),... ', T = % 4.2 f']; s u b p l o t ( 2 1 2 ) , a x i s o f f
% Use a dense s e t of p o i n t s f o r ani mat i on nt=80; [ u u,X X,T T,u u f,t t ] = u s t r i n g ( a,v,t m a x,n t ); umax=max( abs(uu(:) )); uu=uu/umax; uuf=uuf/umax; XX=XX/xmax; r a n g e = [ 0,1,- 1,1 ]; h=.4; a r x = h * [ 0,.0 2,-.0 2,0,0 ]; a r y = h * [ 0,.2 5,.2 5,0,1 ]; f o r j = 1:n t
u j = u u ( j,:); x j = X X ( j,:); x f j = v/x m a x * t t ( j ); u f j = u u f ( j ); p l o t ( x j,- u j,'k',x f j + a r x,- u f j - a r y,'- k') a x i s o f f, t i m e = ( s p r i n t f ( T i t l,t t ( j ) ) ); t e x t (.3,-.5,t i m e ), a x i s ( r a n g e ), drawnow p a u s e (.0 5 ), f i g u r e ( g c f ), i f j < n t, c l a, end
end
% p r i n t -deps forcmove h o l d o f f; s u b p l o t
%=============================================
f u n c t i o n [ u,X,T,u f,t ] = u s t r i n g ( a,v,t m a x,n t )
%
% [ u,X,T,u f,t ] = u s t r i n g ( a,v,t m a x,n t )
%..................................................................................
% This f u n c t i o n computes t h e d e f l e c t i o n u ( x,t )
% of a s e m i - i n f i n i t e s t r i n g s u b j e c t e d t o a
87
88
89
90
91
92
93
94
95
96
97
98
99 100 101 102
103
104
105
106
107
108
109
110
% moving f o r c e. The e q u a t i o n f o r t h e normal i zed % d e f l e c t i o n i s
% u ( x,t ) = 1/a/( a ~ 2 - v ~ 2 ) * ( ( v - a - v * a b s ( x - a * t )...
%
% a %v
% tmax % n t % uu %
%
%
%
% X,T % uf % t %
%
t = l i n s p a c e ( 0,t m a x,n t )'; xmax=1.05*tmax*max(a,v); u = z e r o s ( n t,4 ); nx=4; X = z e r o s ( n t,n x ); X(:,nx)=xmax; c = 1/a/( a ~ 2 - v ~ 2 ); xw=a*t; x f =v * t; T = r e p m a t ( t,1,4 ); uw=c*xw*(v-a+abs(v-a)); u f = c * x f * ( v - a - a b s ( v - a ) ); i f a>v, X (:,2 ) = x f; X(:,3)=xw; u (:,2 ) = u f; e l s e, X(:,2)=xw; X (:,3 ) = x f; u (:,2 ) = u w; end
+ a * a b s ( x - v * t ) );
- speed of wave p r o p a g a t i o n i n t h e s t r i n g
- speed of t h e f o r c e moving t o t h e r i g h t
- maximum t ime f o r computing t h e s o l u t i o n
- number of time v a l u e s
- a r r a y of d i s pl ac e me nt v a l u e s normal i zed
by d i v i d i n g by a f a c t o r equal t o t h e f o r c e magnitude over t wi c e t h e d e n s i t y p e r u n i t l e n g t h. P o s i t i o n v a r i e s column-wise and t ime v a r i e s row-wise i n t h e a r r a y.
- p o s i t i o n and ti me a r r a y s f o r t h e s o l u t i o n
- d e f l e c t i o n v e c t o r under t h e f o r c e
- t ime v e c t o r f o r t h e s o l u t i o n (same as t h e columns of T)
9.5 Waves in Rectangular or Circular Membranes
Wave propagation in two dimensions is illustrated well by the transverse vibration of an elastic membrane. Membrane dynamics is discussed here for general boundary shapes. Then specific solutions are given for rectangular and circular membranes subjected to a harmonically varying surface force. In the next chapter, natural mode vibrations of an elliptical membrane are also discussed. We consider a membrane occupying an area S of the x, y plane bounded by a curve L where the deflection is zero. The differential equation, boundary conditions, and initial conditions govern­
ing the transverse deflection U(x, y, t) are
V2U = c-2Utt - P(x,y,t) , (x,y) e S,
U(x, y, 0) = Uo(x, y) , Ut(x, y, 0) = Vo(x, y) , (x, y) e S,
U( x,y,t ) = 0 , (x,y) e L.
The par amet er c is the speed of wave propagation in the membrane and P is the applied normal load per unit area divided by the membrane tension per unit length.
When P = 0 , the motion is resolvable into a series of normal mode vibrations [22] of the form un(x, y) sin(Qnt + en) satisfying
V2un(x, y) = -An un(x, y), (x, y) e S , un(x, y) = 0 , (x,y) e L
wher e An = Qn/c is a positive real frequency parameter, and u n satisfies
n(x,y) um(x,y) dxdy = CnSnm , Cn = uri(x,y)2dxdy
where Snm is the Kronecker delta symbol. If the initial displacement and initial velocity are representable by a series of the modal functions, then the homogeneous solution satisfying general initial conditions is
U(x,y,t) = ^ 2 un(x,y) [An cos(Qnt) + Bn sin(Qnt)/^n]
n=1
where
An = J J Uo(x,y) un(x,y) dxdy/Cn , Bn = J J Vo(x,y) un(x,y) dxdy/Cn.
The nonhomogeneous case wi l l be t r eat ed wher e t he appl i ed nor mal f or ce on t he membr ane var i es har moni cal l y as
P(x, y, t) = p(x, y) cos(il t)
and Ω does not mat ch any nat ur al f r equency of t he membr ane. We as s ume t hat t he membr ane is i ni t i al l y at r est wi t h zer o def l ect i on a n dp(x, y) is expandable as
W Λ Λ
p(x,y) = ^ 2 Pnun(x,y) dxdy, Pn = p(x,y) un(x,y) dxdy/Cn.
n=1
Then the forced response solution satisfying zero initial conditions is found to be
P
U(x,y,t) = Σ A 2 _"A 2 u*(x,y) [cos(Ωί) - cos(Ω„ί)].
n=1 - n
Thi s equat i on shows cl ear l y t hat when t he f r equency of t he f or ci ng f unct i on i s cl ose t o any one of t he nat ur al f r equenci es, t hen l ar ge def l ect i on ampl i t udes can occur.
Next we t ur n t o speci f i c sol ut i ons f or r ect angul ar and ci r cul ar membr anes. Con­
si der t he nor mal mode f unct i ons f or a r ect angul ar r egi on def i ned by 0 < x < a, 0 < y < b. It can be shown that the modal functions are
unm(x,y) = sm(nnx/a) sm(mny/b) , ilnm = c ^\J (n/a)2 + (m/6)2
and Cn = ab/4. In the simple case where the applied surface force is a concentrated load applied at (x0, y0), then
p(x, y) = poS(x - xo) s(y - yo)
where δ is the Dirac delta function. The series solution for a forced response solution is found to be
O O O O
ττί ja 2 Pnm . ,η-πχ mny /0
U{x,y,t)=c 2 ^ Q2 _ Q2 sm(——) sm(—^—) [cos(Ωί) - c o s ^ nmt)J
n=1 m=1 - nm
wi t h
P n m = —— si n(n7rx0/a ) sin(m7ryo/&)·
ab
A similar kind of solution is obtainable as a series of Bessel functions when the membrane is circular. Transforming the wave equation to polar coordinates (r, θ) gives
Urr + r-1Ur + r-2Uoo = c-2Utt — P(r, θ,ί) , 0 < r < a , —π < θ < π , t > 0.
To reduce the algebraic complexity of the series solution developed below, it is help­
ful to introduce dimensionless variables ρ = r/a and τ = ct/a . Then the boundary value problem involving a harmonic forcing function becomes
Upp+p-1Up+p-2Ugg = UTT—p(p, θ)βΐη(ω τ ) , 0 < ρ < 1 , —π < θ < π , τ > 0,
U(ρ, θ, 0) = 0 , UT(ρ, θ, 0) = 0,
where ω = Ω a/c. The modal functions for this problem are
unm(ρ, θ) = Jn(^nmρ) £°3(ηθ + 6n)
involving the integer order Bessel functions, with λ nm being the mth positive root of Jn(ρ) . These modal functions satisfy the orthogonality conditions discussed above and we employ the series expansion
ρ(ρ, θ) = Σ Σ Jn(Km ρ) real(Anm e ine)
where
n nm
n=0 m=1
A n m /Ί i J? 72 ί\ \ I I P(Pi ^ ) p ' dp d9.
π(1 + δ ^ ) Jn+1 (*nm) J J
—π 0
Then the forced response solution becomes
υ(ρ,θ,τ) = Y Y JniKmP) reai(^4 nmeM!.0 ) [cos(wr) - cos(Anmr )].
0 . ω2 — X2nm
n=0 m=1 nm
In the special case where a concentrated force acts at ρ = ρ 0, θ = 0 ,so that
ρ(ρ,θ) = ρ 0 δ(ρ — ρ 0 ) δ ( θ 1
then evaluating the double integral gives
Anm = p0ρ0Jn(λnmρ0)
and real(Anme~in0) simplifies to Anm cos(nO).
1
π
Program membwave was written to depict wave propagation in a rectangular or circular membrane. Input data specifies information on membrane dimensions, forc­
ing function frequency, force position coordinates, wave speed, and maximum time for solution generation. The primary computation tasks involve summing the double series defining the solutions. In the case of the circular membrane, the Bessel func­
tion roots determining the natural frequencies must also be computed. The various program modules are listed in the following table.
9.5.1 Computer Formulation
membwave
reads data, calls other computational mod­
ules, and outputs time response
memrecwv
sums the series for dynamic response of a
rectangular membrane
memcirwv
calls besjroot to obtain the natural frequen­
cies and sums the series for the circular mem­
brane response
besjroot
computes a table of Bessel function roots
membanim
animates the dynamic response of the mem­
brane
9.5.2 Input Data for Program membwave
Listed below are data cases showing animations of both rectangular and circular membranes. Waves propagate outward in a circular pattern from the point of appli­
cation of the oscillating concentrated load. The membrane response becomes more complex as waves reflect from all parts of the boundary. In order to fully appreciate the propagating wave phenomenon, readers should run the program for several com­
binations of forcing function frequency and maximum time. The two surface plots below show deflected positions before waves have reached the entire boundary, so some parts of the membrane surface still remain undisturbed.
>> membwave;
WAVE MOTION IN A RECTANGULAR OR CIRCULAR MEMBRANE HAVING AN OSCILLATING LOAD
S e l e c t t he geometry type:
Ent er 1 f o r a r e c t a n g l e, 2 f o r a c i r c l e > ? 1
Specify t he r e c t a n g l e dimensions:
Give v a l u e s f o r a,b > ? 2,1
Give c o o r d i n a t e s (x0,y0) where the
f o r c e a c t. E n t e r x 0,y 0 > ? 1.5,.5
E n t e r t h e
w a v e s p e e d
>?1
T h e f i r s t
f o r t y - t w o
n a t u r a l
f r e q u e n c i e s
a r e:
3.5 1 2 4
4.4 4 2 9
5.6 6 3 6
6.4 7 6 6
7.0 2 4 8
7
7.8 5 4 0
8.4 5 9 0
8.8 8 5 8
9.5 5 4 8
9.9 3 4 6
9
1 0.0 5 8 0
1 0.5 3 7 2
1 1.3 2 7 2
1 1.3 2 7 2
1 1.4 3 5 6
12
1 2.6 6 4 2
1 2.6 6 4 2
1 2.9 5 3 1
1 2.9 5 3 1
1 3.3 2 8 6
13
1 4.0 4 9 6
1 4.0 4 9 6
1 4.4 8 2 0
1 4.4 8 2 0
1 4.8 1 8 9
1 5
1 5.7 0 8 0
1 5.7 0 8 0
1 5.7 8 6 3
1 6.0 1 9 0
1 6.0 1 9 0
1 6
1 6.6 9 7 8
1 6.9 1 8 0
1 6.9 1 8 0
1 6.9 9 0 8
1 7.5 6 2 0
17
I n p u t t h e
f r e q u e n c y
o f t h e
f o r c i n g f u n c t i o n ? 1 7,
5
I n p u t t h e ma x i mu m s o l u t i o n e v a l u a t i o n t i m e.
> ? 5
P r e s s r e t u r n f o r a n i m a t i o n o r e n t e r 0 t o s t o p > ?
P r e s s r e t u r n f o r a n i m a t i o n o r e n t e r 0 t o s t o p > ? 0
A l l d o n e
>> me mb wa v e;
WAVE MOTI ON I N A RECTANGULAR OR CI RCULAR MEMBRANE HAVI NG AN OSCI LLATI NG LOAD
S e l e c t t h e g e o e m t r y t y p e:
E n t e r 1 f o r a r e c t a n g l e, 2 f o r a c i r c l e > ? 2
T h e c i r c l e r a d i u s e q u a l s o n e. G i v e t h e r a d i a l d i s t a n c e r 0 f r o m t h e c i r c l e c e n t e r t o t h e f o r c e > ? .5
E n t e r t h e w a v e s p e e d > ? 1
T h e f i r s t f o r t y - t w o n a t u r a l f r e q u e n c i e s a r e:
2.4 0 4 8 3.8 3 1 7 5.1 3 5 6 5.5 2 0 1 6.3 8 0 1 7
7.5 8 8 3 8.4 1 7 3 8.6 5 3 7 8.7 7 1 5 9.7 6 1 1 9
1 0.1 7 3 5 1 1.0 6 4 7 1 1.0 8 6 4 1 1.6 1 9 9 1 1.7 9 1 6 1 2
1 2.3 3 8 5 1 3.0 1 5 2 1 3.3 2 3 7 1 3.3 5 4 3 1 3.5 8 9 3 1 4
0 2 4 8
9 3 4 6
2 6 8 3
4 2 0 9
4 7 0 5
3 9 9 6
5 6 2 0
.0 1 5 6
.9 3 6 2
.2 2 5 1
.3 7 2 6
14.4755 14.7960 14.8213 14.9309 15.5898 15
16.0378 16.2234 16.4707 16.6983 17.0037 17
17.6159 17.8014 17.9599 18.0711 18.2876 18
Input the frequency of t he f o r c i n g f u n c t i o n ? 17.5
Input the maximum s o l u t i o n e v a l u a t i o n time.
> ? 5
Press r e t u r n f o r animation or e n t e r 0 t o st op > ?
Press r e t u r n f o r animation or e n t e r 0 t o st op > ? 0
Al l done >>
MEMBRANE POSITION AT T= 0.94
2
7002
2412
4335
Figure 9.10: Wave Propagation in a Rectangular Membrane
u axis
MEMBRANE POSITION AT T= 0.96
Program membwave
i: f u n c t i o n [ u,x,y,t ] = m e m b w a v e ( t y p e,d i m s,a l p,w,t m a x ) 2: %
3: % [ u,x,y,t ] = m e m b w a v e ( t y p e,d i m s,a l p,w,t m a x )
4: %
5: % T h i s p r o g r a m i l l u s t r a t e s waves p r o p a g a t i n g i n 6: % a membrane of r e c t a n g u l a r o r c i r c u l a r s h a p e 7: % w i t h an o s c i l l a t o r y c o n c e n t r a t e d l o a d a c t i n g a t 8: % an a r b i t r a r y i n t e r i o r p o i n t. The membrane h a s 9: % f i x e d e d g e s and i s i n i t i a l l y u n d e f l e c t e d and i o: % a t r e s t. The r e s p o n s e u ( x,y,t ) i s comput ed and i i: % a n i m a t e d p l o t s d e p i c t i n g t h e mo t i o n a r e shown.
12: %
i 3: % t y p e - 1 f o r r e c t a n g l e, 2 f o r c i r c l e
i 4: % di ms - v e c t o r g i v i n g p r o b l e m d i m e n s i o n s. For
i 5: % t y p e = 1, d i m s = [ a,b,x 0,y 0 ] wher e a and
i 6: % b a r e r e c t a n g l e d i m e n s i o n s a l o n g t h e
i 7: % x and y a x e s. Al s o t h e o s c i l l a t i n g
i 8: % f o r c e a c t s a t ( x 0,y 0 ). For t y p e = 2,
i 9: % a c i r c u l a r membrane of u n i t r a d i u s i s
2 0: % a n a l y z e d w i t h t h e c o n c e n t r a t e d f o r c e
2 i: % a c t i n g a t ( r 0,0 ) wher e r 0 = d i m s ( 1 );
2 2: % a l p - wave p r o p a g a t i o n v e l o c i t y i n t h e
2 3: % membrane
2 4: % w - f r e q u e n c y o f t h e a p p l i e d f o r c e. T h i s
2 5: % c a n be z e r o i f t h e f o r c e i s c o n s t a n t.
2 6: % x 0,y 0 - c o o r d i n a t e s of t h e p o i n t wher e
2 7: % t h e f o r c e a c t s
2 8: % x,y,t - v e c t o r s o f p o s i t i o n and t i m e v a l u e s
2 9: % f o r e v a l u a t i o n of t h e s o l u t i o n
3 0: % u - an a r r a y of s i z e [ l e n g t h ( x ),...
3 i: % l e n g t h ( y ),l e n g t h ( t ) ]
3 2: % i n whi c h u ( i,j,k ) c o n t a i n s t h e
3 3: % n o r m a l i z e d d i s p l a c e m e n t a t
3 4: % y ( i ),x ( j ),t ( k ). The d i s p l a c e m e n t i s
3 5: % n o r m a l i z e d by d i v i d i n g by
3 6: % m a x ( a b s ( u (:) ) )
37:
3 8: d i s p (' ')
3 9: di sp('WAVE MOTION IN A RECTANGULAR OR CIRCULAR')
4 0: d i s p (' MEMBRANE HAVING AN OSCILLATING LOAD')
4 i:
42
43:
44
45
46
47:
48
49
50:
5 i:
52
53:
54
55
56
57:
58
59
60:
6 i:
62
63:
64
65
66
67:
68
69
70:
7 i
72
73:
74
75
76
77:
78
79
80:
8 i
82
83:
84
85
86
i f n a r g i n > 0 % Data pa s s e d t h r o u g h t h e c a l l l i s t % must s p e c i f y: t y p e, dims, a l p, w, tmax % T ypi ca l v a l u e s a r e: a=2; b=1; alp=1;
% w=18.4; x0=1; y0=0.5; tmax=5; i f type==1
a=dims(1); b=dims(2); x0=dims(3); y0=dims(4); [ u,x,y,t ] = m e m r e c w v ( a,b,a l p,w,x 0,y 0,t m a x ); e l s e
r0=di ms(1);
end
e l s e % I n t e r a c t i v e d a t a i n p u t
d i s p (' '), d i s p ('S e l e c t t h e geometry t y p e:') t y p e = i n p u t ( ['E n t e r 1 f o r a r e c t a n g l e, ',...
'2 f o r a c i r c l e > ? '] );
i f t ype ==1 d i s p (' ')
d i s p ('S p e c i f y t h e r e c t a n g l e d i m e n s i o n s:') s = i n p u t ('G i v e v a l u e s f o r a,b > ? ','s'); s = e v a l ( ['[',s,']'] ); a = s ( 1 ); b = s ( 2 ); d i s p (' ')
d i s p ('G i v e c o o r d i n a t e s (x0,y0) where t h e') s = i n p u t ('f o r c e a c t s. E n t er x0,y0 > ? ','s'); s = e v a l ( ['[',s,']'] ); x 0 =s ( 1); y0=s(2); d i s p (' '), a l p = i n p u t ('E n t e r t h e wave speed > ? ');
N=40; M=40; p a n = p i/a * ( 1:N )'; pbm=pi/b*(1:M); W=al p*s qr t ( r epma t ( pan.~2,1,M) + r e pma t ( pbm.~2,N,1) ); w s o r t = s o r t ( W (:) ); w s o r t = r e s h a p e ( w s o r t ( 1:4 2 ),6,7 )' ; d i s p (' ')
d i s p ( ['T h e f i r s t f o r t y - t w o n a t u r a l ',...
'f r e q u e n c i e s a r e:'] ) d i s p ( w s o r t ) w = i n p u t (...
'I n p u t t h e fr equenc y of t h e f o r c i n g f u n c t i o n ? '); e l s e
d i s p (' '), d i s p (...
'The c i r c l e r a d i u s e q u a l s one. Give t h e r a d i a l') d i s p (...
'd i s t a n c e r 0 from t h e c i r c l e c e n t e r t o t h e') r 0 = i n p u t ('f o r c e > ? ');
d i s p (' '), a l p = i n p u t ('E n t e r t h e wave speed > ? ');
87
88
89
90
9 i
92
93
94
95
96
97
98
99
i 0 0
i 0 i
i 0 2
i 0 3
i 0 4
i 0 5
i 0 6
i 0 7
i 0 8
i 0 9
i i 0
i i i
i i 2
i i 3
i i 4
i i 5
i i 6
i i 7
i i 8
i i 9
i 2 0
i 2 i
i 2 2
i 2 3
i 2 4
i 2 5
i 2 6
i 2 7
i 2 8
i 2 9
i 3 0
i 3 i
% F i r s t 42 Bes s el f u n c t i o n r o o t s w s o r t = a l p * [...
2.4048 3.8317 5.1356 5.5201 6.3801 7.0156
7.5883 8.4173 8.6537 8.7715 9.7611 9.9362
10.1735 11.0647 11.0864 11.6199 11.7916 12.2251
12.3385 13.0152 13.3237 13.3543 13.5893 14.3726
14.4755 14.7960 14.8213 14.9309 15.5898 15.7002
16.0378 16.2234 16.4707 16.6983 17.0037 17.2412
17.6159 17.8014 17.9599 18.0711 18.2876 18.4335];
d i s p (' '), d i s p ( ['T h e f i r s t f o r t y - t w o ',...
'n a t u r a l f r e q u e n c i e s a r e:'] )
d i s p ( w s o r t )
w = i n p u t (...
'I n p u t t h e fr equenc y of t h e f o r c i n g f u n c t i o n ? '); end d i s p (' ')
d i s p ('I n p u t t h e maximum s o l u t i o n e v a l u a t i o n t i m e.') t m a x = i n p u t (' > ? ');
end
i f type==1
[ u,x,y,t ] = m e m r e c w v ( a,b,a l p,w,x 0,y 0,t m a x ); e l s e
t h = l i n s p a c e ( 0,2 * p i,8 1 ); r = l i n s p a c e ( 0,1,2 0 ); [ u,x,y,t ] = m e m c i r w v ( r,t h,r 0,a l p,w,t m a x ); end
% Animate t h e s o l u t i o n membani m(u,x,y,t);
%================================================
f u n c t i o n [ u,x,y,t ] = memrecwv(a,b,al p,w,x0,y0,t max)
%
% [ u,x,y,t ] = m e m r e c w v ( a,b,a l p,w,x 0,y 0,t m a x )
%....................................................................................................
% This f u n c t i o n i l l u s t r a t e s wave motion i n a % r e c t a n g u l a r membrane s u b j e c t e d t o a c o n c e n t r a t e d % o s c i l l a t o r y f o r c e a p p l i e d a t an a r b i t r a r y % i n t e r i o r p o i n t. The membrane has f i x e d edges % and i s i n i t i a l l y a t r e s t i n an u n d e f l e c t e d % p o s i t i o n. The r e s u l t i n g r e s p o n s e u ( x,y,t ) i s % computed and a p l o t of t h e motion i s shown.
% a,b - s i d e dimensions of t h e r e c t a n g l e
i 3 3:
134
135
136
137
138
139
140 i 4 i: i 4 2 i 4 3: i 4 4:
145
146
147 i 4 8: i 4 9 i 5 0: i 5 i: i 5 2: i 5 3: i 5 4: i 5 5: i 5 6: i 5 7: i 5 8: i 5 9: i 6 0: i 6 i: i 6 2: i 6 3: i 6 4: i 6 5: i 6 6: i 6 7: i 6 8: i 6 9: i 7 0: i 7 i: i 7 2 i 7 3:
174
175
176
i32
% a l p - wave p r o p a g a t i o n v e l o c i t y i n t h e
% membrane
% w - fr equenc y of t h e a p p l i e d f o r c e. This
% can be z e ro i f t h e f o r c e i s c o n s t a n t.
% x0,y0 - c o o r d i n a t e s of t h e p o i n t where
% t h e f o r c e a c t s
% x,y,t - v e c t o r s of p o s i t i o n and time v a l u e s
% f o r e v a l u a t i o n of t h e s o l u t i o n
% u - an a r r a y of s i z e [ l e n g t h ( y ),...
% l e n g t h ( x ),l e n g t h ( t ) ] i n which u ( i,j,k )
% c o n t a i n s t h e nor mal i ze d di s pl ace me nt
% cor r e s p o n d i n g t o y ( i ), x ( j ), t ( k ). The
% d i s pl ace me nt i s nor mal i ze d by d i v i d i n g
% by m a x ( a b s ( u (:) ) ).
%
% The s o l u t i o n i s a double F o u r i e r s e r i e s of form %
% u ( x,y,t ) = S u m ( A ( n,m,x,y,t ), n=1..N, m=1..M)
% where
% A ( n,m,x,y,t ) = s i n ( n * p i * x 0/a ) * s i n ( n * p i * x/a ) *...
% s i n ( m * p i * y 0/b ) * s i n ( m * p i * y/b ) *...
% ( c o s ( w * t ) - c o s ( W ( n,m ) * t ) )/...
% ( w~2-W(n,m)~2)
% and t h e membrane n a t u r a l f r e q u e n c i e s a r e % W( n,m)=pi *al p*s qr t ( ( n/a) ~2+( m/b) ~2)
i f nargin==0
a=2; b=1; alp=1; tmax=3; w=13; x0=1.5; y0=0.5; end i f a<b
nx=31; ny=round( b/a*21); ny=ny+rem(ny+1,2); e l s e
ny=31; nx=round( a/b*21); nx=nx+rem(nx+1,2);
end
x = l i n s p a c e ( 0,a,n x ); y = l i n s p a c e ( 0,b,n y );
N=40; M=40; p a n = p i/a * ( 1:N )'; pbm=pi/b*(1:M); W=al p*s qr t ( r epma t ( pan.~2,1,M) + r e pma t ( pbm.~2,N,1) ); w s o r t = s o r t ( W (:) ); w s o r t = r e s h a p e ( w s o r t ( 1:3 0 ),5,6 )'; N t = c e i l ( 4 0 * t m a x * a l p/m i n ( a,b ) ); t = t m a x/( N t - 1 ) * ( 0:N t - 1 );
% E val ua t e f i x e d terms i n t h e s e r i e s s o l u t i o n mat=sin(x0*pan)*sin(y0*pbm)./(w~2-W.~2); s x n = s i n ( x (:) * p a n'); s m y = s i n ( p b m'* y (:)');
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220 2 2 i
u = z e r o s ( n y,n x,N t ); f o r j =1:Nt
A = m a t.* ( c o s ( w * t ( j ) ) - c o s ( W * t ( j ) ) ); uj=sxn*(A*smy); u (:,:,j ) = u j'; end
%================================================
f u n c t i o n [ u,x,y,t,r,t h ] = m e m c i r w v ( r,t h,r 0,a l p,w,t m a x ) %
% [ u,x,y,t,r,t h ] = m e m c i r w v ( r,t h,r 0,a l p,w,t m a x )
%............................................................................................................
% This f u n c t i o n computes t h e wave r e s ponse i n a % c i r c u l a r membrane havi ng an o s c i l l a t i n g f o r c e % a p p l i e d a t a p o i n t on t h e r a d i u s al ong t h e % p o s i t i v e x a x i s.
%
% r,t h - v e c t o r s of r a d i u s and p o l a r angl e v a l u e s % r0 - r a d i a l p o s i t i o n of t h e c o n c e n t r a t e d f o r c e % w - fr equenc y of t h e a p p l i e d f o r c e % tmax - maximum t ime f o r computing t h e s o l u t i o n %
% User m f u n c t i o n used: b e s j r o o t
i f nargin==0
r 0 =.4; w=15.5; t h = l i n s p a c e ( 0,2 * p i,8 1 ); r = l i n s p a c e ( 0,1,2 1 ); alp=1; end
Nt = c e i l ( 2 0 * a l p * t ma x ); t = t m a x/( N t - 1 ) * ( 0:N t - 1 );
% Compute t h e B es s el f u n c t i o n r o o t s needed i n % t h e s e r i e s s o l u t i o n. This t a k e s a whi l e. l a m = b e s j r o o t ( 0:2 0,2 0,1 e - 3 );
% Compute t h e s e r i e s c o e f f i c i e n t s [ n j,n k ] = s i z e ( l a m ); r = r (:)'; n r = l e n g t h ( r ); t h = t h (:); n t h = l e n g t h ( t h ); n t = l e n g t h ( t ); N = r e p m a t ( ( 0:n j - 1 )',1,n k ); Nvec=N(:)'; c = b e s s e l j ( N,l a m * r 0 )./( b e s s e l j (...
N+1,l am).~2.*(l am.~2- w~2)); c ( 1,:) = c ( 1,:)/2; c = c (:)';
% Sum t h e s e r i e s of Bes s el f u n c t i o n s
222
223
224
225
226
227
228
229
230
2 3 i
232
233
234
235
236
237
238
239
240
2 4 i
242
243
244
245
246
247
248
249
250
2 5 i
252
253
254
255
256
257
258
259
260
2 6 i
262
263
264
265
266
l a m v e c = l a m (:)'; wlam=w./lamvec; c = c o s ( t h * N v e c ).* r e p m a t ( c,n t h,1 ); r m a t = b e s s e l j ( r e p m a t ( N v e c',1,n r ),l a m v e c'* r ); u = z e r o s ( n t h,n r,n t ); f o r k=1:nt
t v e c = - c o s ( w * t ( k ) ) + c o s ( l a m v e c * t ( k ) ); u (:,:,k ) = c.* r e p m a t ( t v e c,n t h,1 ) * r m a t; end
u=2/pi *u; x = c o s ( t h ) * r; y = s i n ( t h ) * r; %================================================
f u n c t i o n r t s = b e s j r o o t ( n o r d e r,n r t s,t o l )
%
% r t s = b e s j r o o t ( n o r d e r,n r t s,t o l )
%........................................................................
% This f u n c t i o n computes an a r r a y of p o s i t i v e r o o t s % of t h e i n t e g e r o r d e r Be s s el f u n c t i o n s b e s s e l j of % t h e f i r s t ki n d f o r v a r i o u s o r d e r s. A chosen number % of r o o t s i s computed f o r each o r d e r % no r d e r - a v e c t o r of f u n c t i o n o r d e r s f o r which
% r o o t s a r e t o be computed. Taking 3:5
% f o r n o r d e r would use o r d e r s 3,4 and 5.
% n r t s - t h e number of p o s i t i v e r o o t s computed f o r % each o r d e r. Roots a t x=0 a r e i g n o r e d.
% r t s - an a r r a y of r o o t s havi ng l e n g t h ( n o r d e r )
% rows and n r t s columns. The element i n
% column k and row i i s t h e k't h r o o t of
% t h e f u n c t i o n b e s s e l j ( n o r d e r ( i ),x ).
% t o l - e r r o r t o l e r a n c e f o r r o o t computation.
i f nar gi n< 3, t o l = 1 e - 5; end j n = i n l i n e ('b e s s e l j ( n,x )','x','n'); N = l e n g t h ( n o r d e r ); r t s = o n e s ( N,n r t s ) * n a n; o p t = o p t i m s e t ('T o l F u n',t o l,'T o l X',t o l ); f o r k=1:N
n = n o r d e r ( k ); x m a x = 1.2 5 * p i * ( n r t s - 1/4 + n/2 ); x s r c h =.1:p i/4:x m a x; f b = b e s s e l j ( n,x s r c h ); n f = l e n g t h ( f b ); K = f i n d ( f b ( 1:n f - 1 ).* f b ( 2:n f ) < = 0 ); i f l e n g t h ( K ) < n r t s
d i s p ('S e a r c h e r r o r i n f u n c t i o n b e s j r o o t') r t s = n a n; r e t u r n e l s e
K=K(1:nrt s); f o r i = 1:n r t s
267
268
269
270
2 7 i
272
273
274
275
276
277
278
279
280
2 8 i
282
283
284
285
286
287
288
289
290
2 9 i
292
293
294
295
296
297
298
299
300
3 0 i
302
303
304
305
306
307
308
309
3 i 0
3 i i
i n t e r v a l = x s r c h ( K ( i ):K ( i ) + 1 ); r t s ( k,i ) = f z e r o ( j n,i n t e r v a l,o p t,n );
end
end
end
%==============================================
f u n c t i o n membanim(u,x,y,t)
%
% f u n c t i o n membanim(u,x,y,t)
%................................................................
% This f u n c t i o n animates t h e motion of a % v i b r a t i n g membrane %
% u a r r a y i n which component u ( i,j,k ) i s t h e
% d i s p l a ce me n t f o r y ( i ),x ( j ),t ( k )
% x,y a r r a y s of x and y c o o r d i n a t e s
% t v e c t o r of t ime v a l u e s
% Compute t h e p l o t range
i f nargin==0;
[ u,x,y,t ] = m e m r e c w v ( 2,1,1,1 5.5,1.5,.5,5 );
end
xmi n=mi n( x(:) ); xmax=max(x(:)); ymi n=mi n( y(:) ); ymax=max(y(:)); xmid=(xmin+xmax)/2; ymid=(ymin+ymax)/2; d=max(xmax-xmin,ymax-ymin)/2; N t = l e n g t h ( t ); range=[ xmi d- d,xmi d+d,ymi d- d,ymi d+d,... 3 * m i n ( u (:) ),3 * m a x ( u (:) ) ];
whi l e 1 % Show t h e ani mat i on r e p e a t e d l y
d i s p (' '), d i s p ('P r e s s r e t u r n f o r a n i m a t i o n') dumy=i nput ('or e n t e r 0 t o s t o p > ? ','s'); i f ~isempty(dumy)
d i s p (' '), d i s p ('A l l d o n e'), b r e ak end
% P l o t p o s i t i o n s f o r s u c c e s s i v e t i mes f o r j =1:Nt
s u r f ( x,y,u (:,:,j ) ), a x i s ( r a n g e ) x l a b e l ('x a x i s'), y l a b e l ('y a x i s') z l a b e l ('u a x i s'), t i t l = s p r i n t f (...
'MEMBRANE POSITION AT T = % 5.2 f',t ( j ) ); t i t l e ( t i t l ), colormap([1 1 1 ] )
3 1 2: c o l o r m a p ( [ 1 2 7/2 5 5 1 2 1 2/2 5 5 ] )
3 1 3: % a x i s o f f
3 1 4: drawnow, s h g, p a u s e (.1 )
3 1 5: end
3 1 6: end
9.6 Wave Propagation in a Beam with an Impact Moment Applied to One End
Analyzing the dynamic response caused when a time dependent moment acts on the end of an Euler beam involves a boundary value problem for a fourth order linear partial differential equation. In the following example we consider a beam of uniform cross section which is pin-ended (hinged at the ends) and is initially at rest. Suddenly, a harmonically varying moment M 0 cos(Q0T ) is applied to the right end as shown in Figure 9.12. Determination of the resulting displacement and bending moment in the beam is desired. Let U be the transverse displacement, X the longitudinal distance
Μηοο8(ΩηΤ)
| ^
7 ^ 7 E, I, L tA t
Figure 9.12: Beam Geometry and Loading
from the right end, and T the time. The differential equation, boundary conditions, and initial conditions characterizing the problem are
d4U d2U
Ε Ι ~ 0 χ ϊ = ~ A p ~d T2 ’ ° < X < L ’ T > ° ’
U{ 0, Τ) = 0 , | ^ ( 0, T) = 0 , U( L, T) = 0 , U ( L, T) = M0 cos(Ω0Τ)/( ΕΙ ), dU
U(0,T) = 0, — (0,T) = 0,
where L is the beam length, EI is the product of the elastic modulus and the moment of inertia, and Ap is the product of the cross section area and the mass density.
This problem can be represented more conveniently by introducing dimensionless variables
X E I T E I ττ (~Ap d2
x L:t V Ap L2 ’ U MqL2 U ’ ω \j E I L Q o,m dx2'
The new boundary value problem is then
d4u 32u
= ~ ~W ’ 0 < x < 1 ’ t > ° ’
d2u . . . d2u , ,
u(0, t) = 0 , 0 ^ ( 0,t) = 0 , u{l,t ) = 0 , ^ 2 ( M) = cos(wi),
du .
u(x, 0) = 0 , 0 ) = 0, 0 < x < 1.
The problem can be solved by combining a particular solution w which satisfies the differential equation and nonhomogeneous boundary conditions with a homoge­
neous solution in series form which satisfies the differential equation and homoge­
neous boundary conditions. Thus we have u = w + v. The particular solution can be found in the form
w = f (x) cos(wt)
where f (x) satisfies
f ""(x) = ω2 f (x)
and
f (0) = f"( 0) = f ( 1 ) = 0 , f"(1) = 1.
This ordinary differential equation is solvable as
4
f ( x ) = Y Ckeskx k=1
where
sk = v ^ e ^ - 1)/2 and 1 = 7 = 1 The boundary conditions require
4 4 4 4
Y^Ck = 0 , Y s\ck = 1 -.Y^Ck esk = 0 , Y CkskeSk = 0.
k=1 k = 1 k=1 k = 1
Solving these simultaneous equations determines the particular solution. The initial displacement for the particular solution can be expanded in a Fourier series as an odd valued function of period 2. Hence we can write
tt tt rs
w(0
,t) = f ( x ) = ^ 2 Cfc et7rkx = Y a k sin(fcTrx) , (0, t) = 0
k=-tt k=1
involving complex Fourier coefficients, c k, and ak = —2 imag(ck). The homoge­
neous solution is representable as
(x,t) = — ak cos(^2k2t) sin(k^x)
k=1
v
so that w + v combine to satisfy the desired initial conditions of zero displacement and velocity.
Of course, perfect satisfaction of the initial conditions cannot be achieved with­
out taking an infinite number of terms in the Fourier series. However, the series converges very rapidly because the coefficients are of order n - 3. When a hundred or more terms are used, an approximate solution produces results which satisfy the differential equation and boundary conditions, and which insignificantly violate the initial displacement condition. It is important to remember the nature of this er­
ror when examining the bending moment results presented below. Effects of high frequency components are very evident in the moment. Despite the oscillatory char­
acter of the moments, these results are exact for the initial displacement conditions produced by the truncated series. These displacements agree closely with the exact solution.
A program was written to evaluate the series solution to compute displacements and moments as functions of position and time. Plots and surfaces showing these quantities are presented along with timewise animations of the displacement and moment across the span. The computation involves the following steps:
1. Evaluate f (x);
2. Expand f (x) using the FFT to get coefficients for the homogeneous series solution;
3. Combine the particular and homogeneous solution by summing the series for any number of terms desired by the user;
4. Plot u and m for selected times;
5. Plot surfaces showing u(x, t) and m(x, t);
6. Show animated plots of u and m.
The principal parts of the program are shown in the table below.
bemimpac
reads data and creates graphical output
beamresp
converts material property data to dimension­
less form and calls ndbemrsp
ndbemrsp
construct the solution using Fourier series
sumser
sums the series for displacement and moment
animate
animates the time history of displacement and
moment
The numerical results show the response for a beam subjected to a moment close to the first natural frequency of the beam. It can be shown that, in the dimensionless problem, the system of equations defining the particular solution becomes singular
Displacement f o r Nearly Resonant Moment Acting at Right End
x axis
Figure 9.13: Displacement Due to Impact Moment at Right End
when ω assumes values of the form k 2π2 for integer k. In that instance the series solution provided here will fail. However, values of ω near to resonance can be used to show how the displacements and moments quickly become large. In our example we let EI, Ap, l,
and M0
all equal unity, and ω =
0.95π2. Figures 9.13 an
d 9.14
show displacement and bending moment patterns shortly after motion is initiated. The surfaces in
Figures 9.15 an
d 9.16 also show how the displacement and moment grow quickly with increasing time. The reader may find it interesting to run the program for various choices of ω and observe how dramatically the chosen forcing frequency affects results.
transverse deflection moment
Bending Moment f o r Nearly Resonant Moment Acting at Right End
x axis
Figure 9.14: Bending Moment in the Beam
Transverse Deflection as a Function of Time and Position
Figure 9.15: Displacement Growth Near Resonance
Bending Moment as a Function of Time and Position
Figure 9.16: Moment Growth Near Resonance
MATLAB Example Program bemimpac
i: f u n c t i o n bemimpac 2: % Exampl e: bemimpac
3: %...........................................................................
4: % T h i s p r o g r a m a n a l y z e s an i mp a c t dynami cs 5: % p r o b l e m f o r an e l a s t i c E u l e r beam of
6: % c o n s t a n t c r o s s s e c t i o n whi c h i s s i mp l y
7: % s u p p o r t e d a t e a c h e n d. The beam i s i n i t i a l l y 8: % a t r e s t when a h a r m o n i c a l l y v a r y i n g moment 9: % m0*cos ( w0*t ) i s a p p l i e d t o t h e r i g h t end. i o: % The r e s u l t i n g t r a n s v e r s e d i s p l a c e m e n t and i i: % b e n d i n g moment a r e comput ed. The i 2: % d i s p l a c e m e n t and moment a r e p l o t t e d a s i 3: % f u n c t i o n s o f x f o r t h e t h r e e t i m e v a l u e s.
i 4: % Ani mat ed p l o t s o f t h e e n t i r e d i s p l a c e m e n t
i 5: % and moment h i s t o r y a r e a l s o g i v e n.
i 6: %
i 7: % Us e r m f u n c t i o n s r e q u i r e d:
i 8
i 9
2o:
2 i:
22
23:
24
25
26
27:
28
29
3o:
3 i
32
33
34
35
36
37
38
39
4o:
4 i
42
43
44
45
46
47
48
49
5o:
5 i:
52
53:
54
55
56
57:
58
59
6o:
6 i:
62
fprintf('\nDYNAMICS OF A BEAM WITH AN '); fprintf('OSCILLATING END MOMENT\n'); ei =1; arho=1; len=1; m0=1; w0=.90*pi~2; tmin=0; tmax=5; nt=101; xmin=0; xmax=len; nx=151; ntrms=200; [ t,x,d i s p l,m o m ] = b e a m r e s p ( e i,a r h o,l e n,m 0,w 0,...
t m i n,t m a x,n t,x m i n,x m a x,n x,n t r m s );
d i s p (' ')
d i s p ('P r e s s [Enter] t o see t h e d e f l e c t i o n') d i s p ('f o r t h r e e p o s i t i o n s'), pause
np=[3 5 8 ]; c l f; p l t s a v e = 0; d i p = d i s p l ( n p,:); mop=mom(np,:); p l o t ( x,d i p ( 1,:),'- k',x,d i p ( 2,:),':b',...
x,d i p ( 3,:),'—r'); x l a b e l ('x a x i s'); y l a b e l ('d i s p l a c e m e n t'); hh=gca;
r ( 1:2 ) = g e t ( h h,'X L i m'); r ( 3:4 ) = g e t ( h h,'Y L i m');
x p = r ( 1 ) + ( r ( 2 ) - r ( 1 ) )/1 0;
d p = r ( 4 ) - ( r ( 4 ) - r ( 3 ) )/1 0;
t s t r = ['D i s p l a c e m e n t f o r Nearl y Resonant' ...
' Moment Ac ti ng a t Right E n d']; t i t l e ( t s t r );
t e x t ( x p,d p,['N u m b e r of s e r i e s terms ' ...
'u s e d = ',i n t 2 s t r ( n t r m s ) ] ); l e g e n d ('t = 0.1 0','t = 0.2 0','t = 0.3 5',3 ) d i s p (' ')
d i s p ('P r e s s [Enter] t o t h e bending moment') d i s p ('f o r t h r e e p o s i t i o n s') shg; pause
i f p l t s a v e, p r i n t -deps 3 p o s i t n s, end c l f;
p l o t ( x,m o p ( 1,:),'- k',x,m o p ( 2,:),':b',...
x,m o p ( 3,:),'—r'); h=gca;
r ( 1:2 ) = g e t ( h,'X L i m'); r ( 3:4 ) = g e t ( h,'Y L i m'); m p = r ( 3 ) + ( r ( 4 ) - r ( 3 ) )/1 0; x l a b e l ('x a x i s'); y l a b e l ('m o m e n t'); t s t r = ['B e n d i n g Moment f o r Nearl y Resonant' ...
' Moment Ac ti ng a t Right E n d']; t i t l e ( t s t r );
t e x t ( x p,mp,['N u mb e r of s e r i e s terms ' ...
% b e a m r e s p, b e a m a n i m, s u m s e r, n d b e m r s p
63:
64
65
66
67:
68
69
70:
7 i
72
73
74
75
76
77
78
79
80:
8 i
82
83
84
85
86
87
88
89
90:
9 i:
92
93:
94
95
96
97:
98
99
i 0 0:
i 0 i:
i 0 2
i 0 3
i 0 4
i 0 5
i 0 6
i 0 7
'u s e d = ',i n t 2 s t r ( n t r m s ) ] ); l e g e n d ('t = 0.1 0','t = 0.2 0','t = 0.3 5',2 ), d i s p (' '), d i s p (...
'P r e s s [Enter] t o see t h e d e f l e c t i o n s s u r f a c e') shg, pause
i f p l t s a v e, p r i n t -deps 3moments, end i n c t = 2; incx=2;
h t = 0.7 5; i t = 1:i n c t:.8 * n t; i x = 1:i n c x:n x; t t = t ( i t ); x x = x ( i x ); d d = d i s p l ( i t,i x ); mm=mom(it,ix); a = s u r f ( x x,t t,d d );
t s t r = ['T r a n s v e r s e D e f l e c t i o n as a ' ...
'F u n c t i o n of Time and P o s i t i o n']; t i t l e ( t s t r );
x l a b e l ('x a x i s'); y l a b e l ('t i m e'); z l a b e l ('t r a n s v e r s e d e f l e c t i o n'); d i s p (' '), d i s p ( ['P r e s s [Enter] t o ',...
's e e t h e bending moment s u r f a c e'] ) shg, pause
i f p l t s a v e, p r i n t -deps b d e f l s r f, end a = s u r f ( x x,t t,m m );
t i t l e ( ['B e n d i n g Moment as a F u nct i on ' ...
'o f Time and P o s i t i o n'] ) x l a b e l ('x a x i s'); y l a b e l ('t i m e'); z l a b e l ('b e n d i n g moment'); d i s p (' ') d i s p ('P r e s s [Enter] t o see ani mat i on o f'); d i s p ('t h e beam d e f l e c t i o n'), shg, pause i f p l t s a v e, p r i n t -deps bmomsrf, end b e a m a n i m ( x,d i s p l,.1,'T r a n s v e r s e D e f l e c t i o n', ...
'x a x i s','d e f l e c t i o n'), d i s p (' ') d i s p ('P r e s s [Enter] t o see a n i m a t i o n'); d i s p ('o f t h e bending moment'); pause beamanim(x,mom,.1,'Bending Moment H i s t o r y', ...
'x a x i s','m o m e n t'); f p r i n t f ('\n A l l D o n e\n'); c l o s e;
%=============================================
f u n c t i o n [ t,x,d i s p l,m o m ] = ...
b e a m r e s p ( e i,a r h o,l e n,m 0,w 0,t m i n,t m a x, ... n t,x m i n,xmax,nx,nt r ms )
%
% [ t,x,d i s p l,m o m ] = b e a m r e s p ( e i,a r h o,l e n,m 0, ...
i 0 8: % w 0,t m i n,t m a x,n t,x m i n,x m a x,n x,n t r m s )
i 0 9: %
i i 0: % T h i s f u n c t i o n e v a l u a t e s t h e t i m e d e p e n d e n t i i i: % d i s p l a c e m e n t and moment i n a c o n s t a n t i i 2: % c r o s s s e c t i o n, s i m p l y s u p p o r t e d beam whi ch i i 3: % i s i n i t i a l l y a t r e s t when a h a r m o n i c a l l y i i 4: % v a r y i n g moment i s s u d d e n l y a p p l i e d a t t h e i i 5: % r i g h t e nd. The r e s u l t i n g t i m e h i s t o r i e s of
i i 6: % d i s p l a c e m e n t and moment a r e comput ed.
i i 7: %
i i 8: % e i - modul us o f e l a s t i c i t y t i m e s
i i 9: % moment of i n e r t i a
i 2 0: % a r h o - mass p e r u n i t l e n g t h of t h e
i 2 i: % beam
i 2 2: % l e n - beam l e n g t h
i 2 3: % m0,w0 - a m p l i t u d e and f r e q u e n c y o f t h e
i 2 4: % h a r m o n i c a l l y v a r y i n g r i g h t end
i 2 5: % moment
i 2 6: % t m i n,t m a x - minimum and maximum t i m e s f o r
i 2 7: % t h e s o l u t i o n
i 2 8: % n t - number of e v e n l y s p a c e d
i 2 9: % s o l u t i o n t i m e s
i 3 0: % xmi n,xmax - minimum and maximum p o s i t i o n
i 3 i: % c o o r d i n a t e s f o r t h e s o l u t i o n.
i 3 2: % The s e v a l u e s s h o u l d l i e b e t we e n
i 3 3: % z e r o and l e n (x=0 and x = l e n a t
i 3 4: % t h e l e f t and r i g h t e n d s ).
i 3 5: % nx - number of e v e n l y s p a c e d s o l u t i o n
i 3 6: % p o s i t i o n s
i 3 7: % n t r ms - number of t e r m s u s e d i n t h e
i 3 8: % F o u r i e r s i n e s e r i e s
i 3 9: % t - v e c t o r of n t e q u a l l y s p a c e d t i me
i 4 0: % v a l u e s v a r y i n g f r om t m i n t o t max
i 4 i: % x - v e c t o r of nx e q u a l l y s p a c e d
i 4 2: % p o s i t i o n v a l u e s v a r y i n g f r om
i 4 3: % xmi n t o xmax
i 4 4: % d i s p l - m a t r i x of t r a n s v e r s e
i 4 5: % d i s p l a c e m e n t s w i t h t i m e v a r y i n g
i 4 6: % f r o m row t o r ow, and p o s i t i o n
i 4 7: % v a r y i n g f r o m col umn t o col umn
i 4 8: % mom - m a t r i x of b e n d i n g moments w i t h
i 4 9: % t i m e v a r y i n g f r om row t o r ow,
i 5 0: % and p o s i t i o n v a r y i n g f r om col umn
i 5 i: % t o col umn
i 5 2: %
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
% User m f u n c t i o n s c a l l e d: ndbemrsp
%-----------------------------------------------------------------------------------------
t c o f = s q r t ( a r h o/e i ) * l e n ~ 2; dcof=m0*len~2/ei; t m i n = t m i n/t c o f; t max=tmax/tcof; w=w0*tcof; xmin=xmin/len; xmax=xmax/len;
[ t,x,d i s p l,m o m ] =...
n d b e m r s p( w,t mi n,t max,nt,xmi n,xmax,nx,nt r ms ); t = t * t c o f; x=x*len; d i s p l = d i s p l * d c o f; mom=mom*m0;
%=============================================
f u n c t i o n b e a m a n i m ( x,u,t p a u s e,t i t l,x l a b l,y l a b l )
b e a m a n i m ( x,u,t p a u s e,t i t l,x l a b l,y l a b l,s a v e )
This f u n c t i o n draws an animated p l o t of d a t a v a l u e s s t o r e d i n a r r a y u. The d i f f e r e n t columns of u cor res pond t o p o s i t i o n v a l u e s i n v e c t o r x. The s u c c e s s i v e rows of u cor respond t o d i f f e r e n t t i m e s. Parameter t p a u s e c o n t r o l s t h e speed of ani mat i on.
u - m a t r i x of v a l u e s t o animate p l o t s
of u v e r s u s x x - s p a t i a l p o s i t i o n s f o r d i f f e r e n t
columns of u t p a u s e - cl o c k seconds between o u t p u t of fr ames. The d e f a u l t i s .1 s ecs when t p a u s e i s l e f t o u t. When t pause=0, a new frame appears when t h e u s e r p r e s s e s any key. t i t l - graph t i t l e x l a b l - l a b e l f o r h o r i z o n t a l a x i s y l a b l - l a b e l f o r v e r t i c a l a x i s
User m f u n c t i o n s c a l l e d: none
i f nar gi n< 6, y l a b l =''; end; i f nar gi n< 5, x l a b l =''; end i f nar gi n< 4, t i t l =''; end; i f nar gi n< 3, t p a u s e =.1; end;
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
[ n t i m e,n x p t s ] = s i z e ( u ); umi n=mi n( u(:) ); umax=max(u(:)); udif=umax-umin; uavg=.5*(umin+umax); xmin=min(x); xmax=max(x); xdif=xmax-xmin; xavg=.5*(xmin+xmax); xwmin=xavg-.55*xdif; xwmax=xavg+.55*xdif; uwmin=uavg-.55*udif; uwmax=uavg+.55*udif; c l f; axis([xwmin,xwmax,uwmin,uwmax]); t i t l e ( t i t l ); x l a b e l ( x l a b l ); y l a b e l ( y l a b l ); h o l d on;
f o r j = 1:n t i m e u t = u ( j,:);
p l o t ( x,u t,'-'); a x i s ('o f f'); f i g u r e ( g c f ); i f tpause==0 pause; e l s e
p a u s e ( t p a u s e );
end
i f j ==ntime, b r e a k, e l s e, c l a; end end
% p r i n t -deps c n t l t r a c h o l d o f f; c l f;
%=============================================
f u n c t i o n [ u,t,x ] = s u m s e r ( a,b,c,f u n t,f u n x, ...
tmin,t ma x,nt,xmi n,xma x,nx)
%
% [ u,t,x ] = s u m s e r ( a,b,c,f u n t,f u n x,t m i n, ...
% tmax,nt,xmi n,xmax,nx)
%............................................................................................................
% This f u n c t i o n e v a l u a t e s a f u n c t i o n U ( t,x )
% which i s d e f i n e d by a f i n i t e s e r i e s. The % s e r i e s i s e v a l u a t e d f o r t and x v a l u e s t a k e n % on a r e c t a n g u l a r g r i d network. The m a t r i x u % has el ements s p e c i f i e d by t h e f o l l o w i n g % s e r i e s summation:
%
% u ( i,j ) = sum( a ( k ) * f u n t ( t ( i ) * b ( k ) ) *...
% k=1:nsum
% f u n x ( c ( k ) * x ( j ) )
%
% where nsum i s t h e l e n g t h of each of t h e % v e c t o r s a, b, and c.
%
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
% a,b,c %
% f u n t,f u n x %
%
%
%
%
%
%
% t m i n,t m a x,n t %
%
% xmin,xmax,nx %
%
% u %
%
%
% t,x %
%
%
% User m f u n c t i o n s c a l l e d: none.
%-----------------------------------------------------------
t t = ( t m i n:( t m a x - t m i n )/( n t - 1 ) :t ma x )' ; xx=(xmi n:(xmax-xmi n)/(nx- 1):xmax); a = a (:).'; u = a ( o n e s ( n t,1 ),:).* f e v a l ( f u n t,t t * b (:).') *...
f e v a l ( f u n x,c (:) * x x ); i f nar gout>1, t = t t; x=xx'; end
%
f u n c t i o n [ t,x,d i s p l,m o m ] = ...
ndbe mr s p( w,t mi n,t max,nt,xmin,xmax,nx,nt rms )
%
% [ t,x,d i s p l,m o m ] = n d b e m r s p ( w,t m i n,t m a x,n t,...
% xmin,xmax,nx,ntrms)
%...............................................................................................................
% This f u n c t i o n e v a l u a t e s t h e nondimensional % d i s pl a ce me nt and moment i n a c o n s t a n t % c r o s s s e c t i o n, simply s u p p o r t e d beam which % i s i n i t i a l l y a t r e s t when a h a r mo n i c a l l y
- v e c t o r s of c o e f f i c i e n t s i n t h e s e r i e s
- h an d l es of f u n c t i o n s a c c e p t i n g m a t r i x argument. f u n t i s e v a l u a t e d f o r an argument of t h e form f u n t ( t * b ) where t i s a column and b i s a row. funx i s e v a l u a t e d f o r an argument of t h e form funx(c*x) where
c i s a column and x i s a row.
- produces v e c t o r t wi t h n t evenly spaced v a l u e s between tmin and tmax
- produces v e c t o r x wi t h nx evenly spaced v a l u e s between xmin and xmax
- t h e n t by nx m a t r i x c o n t a i n i n g v a l u e s of t h e s e r i e s e v a l u a t e d a t t ( i ),x ( j ), f o r i = 1:n t and j =1:nx
- column v e c t o r s c o n t a i n i n g t and x v a l u e s. These out put v a l u e s a r e o p t i o n a l.
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
% v a r y i n g moment of fr equenc y w i s suddenly % a p p l i e d a t t h e r i g h t end. The r e s u l t i n g % time h i s t o r y i s computed.
%
% w - fr equenc y of t h e h ar mo n i c a l l y
% v a r y i n g end moment
% t min,tmax - minimum and maximum % d i m e n s i o n l e s s t i mes
% n t - number of evenly spaced
% s o l u t i o n t i mes
% xmin,xmax - minimum and maximum % d i m e n s i o n l e s s p o s i t i o n
% c o o r d i n a t e s. These v a l u e s
% s houl d l i e between z e r o and
% one (x=0 and x=1 gi ve t h e
% l e f t and r i g h t en d s ).
% nx - number of eve nly spaced
% s o l u t i o n p o s i t i o n s
% ntrms - number of terms used i n t h e
% F o u r i e r s i n e s e r i e s
% t - v e c t o r of n t e q u a l l y spaced
% t ime v a l u e s v a r y i n g from
% tmin t o tmax
% x - v e c t o r of nx e q u a l l y spaced
% p o s i t i o n v a l u e s v a r y i n g
% from xmin t o xmax
% d i s p l - m a t r i x of d i m e n s i o n l e s s
% d i s p l a c e me n t s wi t h time
% v a r y i n g from row t o row,
% and p o s i t i o n v a r y i n g from
% column t o column
% mom - m a t r i x of d i m e n s i o n l e s s
% bending moments wi t h time
% v a r y i n g from row t o row, and
% p o s i t i o n v a r y i n g from column
% t o column
%
% User m f u n c t i o n s c a l l e d: sumser
%---------------------------------------------------------------------------------
i f n a r g i n < 8, w=0; end; nft =512; n h = n f t/2; x f t = 1/n h * ( 0:n h )';
x=xmi n+(xmax- xmi n)/( nx- 1) *( 0:nx- 1)'; t = t m i n + ( t m a x - t m i n )/( n t - 1 ) * ( 0:n t - 1 )'; cwt=cos(w*t);
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
% Get p a r t i c u l a r s o l u t i o n f o r nonhomogeneous % end c o n d i t i o n
i f w ==0 % Case f o r a c o n s t a n t end moment cp=[1 0 0 0; 0 0 2 0; 1 1 1 1; 0 0 2 6 ]\ ... [ 0;0;0;1 ];
y p = [ o n e s ( s i z e ( x ) ), x, x.~ 2, x.~ 3 ] * c p; y p = y p'; m p = [ z e r o s ( n x,2 ), 2 * o n e s ( n x,1 ), 6 * x ] * c p; mp=mp';
y p f t = [ o n e s ( s i z e ( x f t ) ), x f t, x f t.~ 2, x f t.~ 3 ] * c p;
% Case wher e end moment o s c i l l a t e s
% w i t h f r e q u e n c y w
e l s e
s = s q r t ( w ) * [ 1, i, - 1, - i ]; e s = e x p ( s ); c p = [ o n e s ( 1,4 ); s.~ 2; e s; e s.* s.~ 2 ]\ ...
[0; 0; 0; 1 ]; y p = r e a l ( e x p ( x * s ) * c p ); y p = y p'; m p = r e a l ( e x p ( x * s ) * ( c p.* s (:).~ 2 ) ); mp=mp'; y p f t = r e a l ( e x p ( x f t * s ) * c p ); end
% F o u r i e r c o e f f i c i e n t s f o r % p a r t i c u l a r s o l u t i o n y f t = - f f t ( [ y p f t;- y p f t ( n h:- 1:2 ) ] )/n f t;
% S i n e s e r i e s c o e f f i c i e n t s f o r % homogeneous s o l u t i o n a c o f = - 2 * i m a g ( y f t ( 2:n t r m s + 1 ) ); c c o f = p i * ( 1:n t r m s )'; b c o f = c c o f.~ 2;
% Sum s e r i e s t o e v a l u a t e F o u r i e r % s e r i e s p a r t o f s o l u t i o n. Then combi ne % w i t h t h e p a r t i c u l a r s o l u t i o n. d i s p l = s u m s e r ( a c o f,b c o f,c c o f,@ c o s,@ s i n,...
t m i n,t m a x,n t,x m i n,x m a x,n x ); d i s p l = d i s p l + c w t * y p; a c o f = a c o f.* b c o f; m o m = s u m s e r ( a c o f,b c o f,c c o f,'c o s','s i n',...
t m i n,t m a x,n t,x m i n,x m a x,n x );
mom=-mom+cwt*mp;
9.7 Forced Vibration of a Pile Embedded in an Elastic Medium
Structures are often supported by piles embedded in soil foundations. The re­
sponse of these systems, when the foundation is shaken in the manner occurring in an earthquake, has considerable practical interest. Let us examine a simple model approximating a single pile connected to an overlying structure. The pile is treated as a beam of uniform cross section buried in an elastic medium. An attached mass at the top causes inertial resistance to translation and rotation. The beam, shown in Figure 9.19 in a deflected position, has length i with x = 0 denoting the lower end and x = i denoting the top. Rotating the member 90 ° from the vertical is done to agree with the coordinate referencing traditionally used in beam analysis. We are in­
terested in the steady-state response when the foundation displacement is y o cos(wt). For convenience we use a complex valued forcing function and get the final results by taking the real part of the complex valued solution. The transverse bending re­
sponse is to be computed when the surrounding elastic medium has an oscillatory motion of the form
yf = yoetut.
The differential equation governing transverse oscillations of the beam is
^Td4y{x,t) d2y{x,t ) , iut N
EI^ ^ ~ = + k {y°€ ~ y)
where E I is the product of the elastic modulus and the inertial moment of the beam, Ap is the product of the cross section area and the mass per unit volume, and k de­
scribes the foundation stiffness in terms of force per unit length per unit of transverse deflection. The shear V and moment M in the beam are related to the deflection
y(x,t) by
V = , Μ = Ε Ι ^ φ Ά.
dx3 dx2
In the current analysis we consider forced response of frequency ω described in the form
y(x,t) = f (x)elut
so that
V = EI f'"( x) eiut , M = EI f"( x ) eiut.
The boundar y condi t i ons at x = 0 require vanishing moment and shear:
f"(0) = 0, f (0) = 0.
The boundary conditions at x = i are more involved because inertial resistance of the end mass must be handled. We assume that the gravity center of the end mass is located along the axis of the beam at a distance h above the top end. Furthermore,
y
Figure 9.17: Forced Vibration of a Pile in an Elastic Medium
the attached body has a mass m o and inertial moment j o about its gravity center. The angular acceleration θ and the transverse acceleration am are expressible as
dxdt2 and
am = —^ 2’ ^ + hi) = —u)~elLJt [/(<*) + hf'( ( )] .
Writing equations of motion for the end mass gives
moam = V(i,t)
and = - hV( i,t ) - M( i,t ).
Repr es ent i ng t hese condi t i ons i n t er ms of f (x) yields
^ 2mo[f (i) + hf '(i)] = EI f'"( i ) and ω2Jof '(i) = EI [ f "(i) + h f '"(i)]. Furthermore, the factor eiUt cancels out of the differential equation E I f'"'(x) = (Αρω2 - k ) f (x) +yok.
The gener al sol ut i on of t hi s f our t h or der l i near di f f er ent i al equat i on is expr essed as
yok
U r ) = k - A,^ where s3 are complex roots given by
1 + Έ -
3=1
» p°3x
'3e
s
3
The conditions of zero moment and shear at x = 0 lead to
4 4
3=1 3=0
The shear and moment conditions at x = t require
s^eS3ec3 = —mo ω2 1 + ^^( 1 + hs3)eSjic3 3=1 L 3=1
and
4
4
Σ (*2 + hs3)
The system of four simultaneous equations can be solved for c 1,...,c 4. Then the forced response solution corresponding to a foundation motion
where f (x) is complex valued.
The function pilevibs evaluates the displacement, moment, and shear for 0 < x < t, 0 < t < 2π/ω. Surface plots of these quantities are shown in Figures 9.18 through 9.20. Figure 9.21 is a single frame from an animation depicting how the pile and the attached mass move.
real (yoetut) = yo cos(ut)
is gi ven by
y(x,t ) = real ( f (x)eMt )
bending moment transverse deflection
Deflection Surface for a Vibrating Pile
Figure 9.18: Deflection Surface for a Vibrating Pile
Bending Moment in the Pile
Figure 9.19: Bending Moment in a Vibrating Pile
shear force
Shear Force in the Pile
Figure 9.20: Shear Force in a Vibrating Pile
Forced Vibration of a Pile
Figure 9.21: Frame from Pile Animation
150
Program Output and Code Program pilevibs
i: f u n c t i o n p i l e v i b s 2: % Exampl e: p i l e v i b s
3: %...........................................................................
4: % The r o u t i n e i s u s e d t o s o l v e an exampl e 5: % p r o b l e m u s i n g f u n c t i o n p v i b s. The exampl e 6: % i n v o l v e s a s t e e l p i l e 144 i n c h e s l o n g whi ch 7: % h a s a s q u a r e c r o s s s e c t i o n of 4 i n c h d e p t h.
8: % The p i l e i s i mmer s ed i n s o i l h a v i n g an e l a s t i c 9: % modul us of 200 p s i. The a t t a c h e d mass we i g h s i o: % 736 l b. The f o u n d a t i o n i s s h a k e n a t an i i: % a m p l i t u d e o f 0.5 i n c h w i t h a f r e q u e n c y of i 2: % 20 c y c l e s p e r s e c o n d.
i 3: %
i 4: % Us e r m f u n c t i o n s r e q u i r e d: p v i b s
i 5:
i 6: c l e a r;
i 7: L=144; d=4; a=d~2; I = d ~ 4/1 2; e=30e6; e i = e * I; i 8: g =3 2.2 * 1 2; D e n s i t y _ s t e e l = 0.2 8 4; i 9: r h o = D e n s i t y _ s t e e l/g;
2 0: Cap_w=36; Cap_h=18; Cap_t =4;
2 i: m0=Cap_w*Cap_h*Cap_t *rho;
2 2: j 0=m0/12*( Cap_h~2+Cap_w~2);
2 3: h=Cap_h/2; a r h o = a * r h o;
2 4: e _ s o i l = 2 0 0; k = e _ s o i l * d; y 0 = 0.5; w=40*pi;
2 5: nx=42; n t = 2 5;
26:
2 7: [ t,x,y,m,v ] = ...
2 8: p v i b s ( y 0,e i,a r h o,L,k,w,h,m 0,j 0,n x,n t );
29:
3 0: % ========================= = === === ===== === === = =
3 i:
3 2: f u n c t i o n [ t,x,y,m,v ] = ...
3 3: p v i b s ( y 0,e i,a r h o,L,k,w,h,m 0,j 0,n x,n t )
3 4: %
3 5: % [ t,x,y,m,v ] = p v i b s ...
3 6: % ( y 0,e i,a r h o,L,k,w,h,m 0,j 0,n x,n t )
3 7: %
3 8: %
3 9: % T h i s f u n c t i o n comput es t h e f o r c e d ha r mo n i c 40: % r e s p o n s e of a p i l e b u r i e d i n an o s c i l l a t i n g
4 i
42
43
44
45
46
47:
48
49
50:
5 i:
52
53:
54:
55
56
57:
58:
59
60:
6 i:
62
63:
64:
65
66
67:
68:
69
70:
7 i
72
73
74
75
76
77:
78
79
80:
8 i
82
83
84
85
e l a s t i c medium. The lower end of t h e p i l e i s f r e e from s h e a r and moment. The t o p of t h e p i l e c a r r i e s an a t t a c h e d body havi ng g e n e r a l mass and i n e r t i a l p r o p e r t i e s. The e l a s t i c f o u n d a t i o n i s gi ven a h o r i z o n t a l o s c i l l a t i o n of t h e form
y f = r e a l ( y 0 * e x p ( i * w * t ) )
The r e s u l t i n g t r a n s v e r s e f o r c e d r e s ponse of t h e p i l e i s e x p r e s s e d as
y ( x,t ) = r e a l ( f ( x ) * e x p ( i * w * t ) )
where f ( x ) i s a complex v a l ued f u n c t i o n. The bending moment and s h e a r f o r c e i n t h e p i l e a r e a l s o computed.
y0 - ampl i tude of t h e f o u n d a t i o n o s c i l l a t i o n
e i - p r oduc t of moment of i n e r t i a and
e l a s t i c modulus f o r t h e p i l e arho - mass p e r u n i t l e n g t h of t h e p i l e
L - p i l e l e n g t h
k - t h e e l a s t i c r e s i s t a n c e c o n s t a n t f o r t h e
f o u n d a t i o n d e s c r i b e d as f o r c e p e r u n i t l e n g t h p e r u n i t of t r a n s v e r s e d e f l e c t i o n w - t h e c i r c u l a r fr equenc y of t h e
f o u n d a t i o n o s c i l l a t i o n which v i b r a t e s l i k e r e a l ( y 0 * e x p ( i * w * t ) ) h - t h e v e r t i c a l d i s t a n c e above t h e p i l e
upper end t o t h e g r a v i t y c e n t e r of t h e
a t t a c h e d body m0 - t h e mass of t h e a t t a c h e d body
j 0 - t h e mass moment of i n e r t i a of t h e
a t t a c h e d body wi t h r e s p e c t t o i t s g r a v i t y c e n t e r nx - t h e number of e q u i d i s t a n t v a l u e s along t h e p i l e a t which t h e s o l u t i o n i s computed
n t - t h e number of v a l u e s of t v a l u e s a t
which t h e s o l u t i o n i s computed such t h a t 0 <= w*t <= 2*pi
t
- a v e c t o r of time v a l u e s such t h a t t h e
86
87:
88
89
90:
9 i:
92
93:
94:
95
96
97:
98:
99
i 0 0:
i 0 i:
i 0 2
i 0 3
i 0 4:
i 0 5
i 0 6
i 0 7:
i 0 8:
i 0 9
i i 0:
i i i:
i i 2:
i i 3:
i i 4:
i i 5:
i i 6:
i i 7:
i i 8:
i i 9:
i 2 0:
i 2 i:
i 2 2:
i 2 3:
i 2 4:
i 2 5:
i 2 6:
i 2 7:
i 2 8:
i 2 9:
i 3 0:
% p i l e moves t hr ough a f u l l p e r i o d of
% motion. This means 0 <= t <= 2*pi/w
% x - a v e c t o r of x v a l u e s wi t h 0 <= x <= L
% y - t h e t r a n s v e r s e d e f l e c t i o n y ( x,t ) f o r
% t h e p i l e wi t h t v a r y i n g from row t o
% row, and x v a r y i n g from column t o
% column
% m,v - m a t r i c e s g i v i n g v a l u e s bending moment % and s h e a r f o r c e
%
% User m f u n c t i o n s c a l l e d: none %-----------------------------------------------------------------------------------------
% D e f a u l t d a t a f o r a s t e e l p i l e 144 i nc he s l ong i f nargin==0
y0=0.5; ei=64e7; arho=0.0118; L=144; k=800; w=125.6637; h=9; m0=1.9051; j0=257.1876; nx=42; nt=25; end
w2=w~2; x = l i n s p a c e ( 0,L,n x )'; t = l i n s p a c e ( 0,2 * p i/w,n t );
% E val ua t e c h a r a c t e r i s t i c r o o t s and complex % e x p o n e n t i a l s
s = ( ( a r h o * w 2 - k )/e i ) ~ ( 1/4 ) * [ 1,i,- 1,- i ]; s2=s.~2; s 3 =s 2.* s; c0=y0*k/(k-w2*arho); e s l =e xp( s *L ); esx=exp(x*s); ei wt =e xp( i *w*t );
% Solve f o r c o e f f i c i e n t s t o s a t i s f y t h e % boundary c o n d i t i o n s
c=[s2; s3; e s l.* ( h * s 3 + s 2 - j 0 * w 2/e i * s ); ... e s l.* ( s 3 + m 0 * w 2/e i * ( 1 + h * s ) ) ]\ ... [ 0;0;0;- c0*m0*w2/ei ];
% Compute t h e d e f l e c t i o n, moment and s h e a r
y = r e a l ( ( c 0 + e s x * c ) * e i w t )';
y p e = r e a l ( s.* e s l * c * e i w t )';
m = r e a l ( e i * s 2 ( o n e s ( n x,1 ),:).* e s x * c * e i w t )';
v = r e a l ( e i * s 3 ( o n e s ( n x,1 ),:).* e s x * c * e i w t )';
t = t'; x = x'; ho l d o f f; c l f;
% Make s u r f a c e p l o t s showing t h e d e f l e c t i o n,
% moment, and s h e a r over a complete p e r i o d of
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
% t h e motion s u r f ( x,t * w,y );
x l a b e l ('x a x i s'); y l a b e l ('t * w a x i s'); z l a b e l ('t r a n s v e r s e d e f l e c t i o n'); t i t l e ('D e f l e c t i o n Sur f a ce f o r a V i b r a t i n g P i l e'); g r i d on; f i g u r e ( g c f )
% p r i n t -deps p i l e s u r f
d i s p ('P r e s s [Enter] t o c o n t i n u e'), pause s u r f ( x,t * w,m );
x l a b e l ('x a x i s'); y l a b e l ('t * w a x i s'); z l a b e l ('b e n d i n g moment'); t i t l e ('B e n d i n g Moment i n t h e P i l e') g r i d on; f i g u r e ( g c f )
% p r i n t -deps pilemom;
d i s p ('P r e s s [Enter] t o c o n t i n u e'), pause s u r f ( x,t * w,v );
x l a b e l ('x a x i s'); y l a b e l ('t * w a x i s'); z l a b e l ('s h e a r f o r c e'); t i t l e ('S h e a r Force i n t h e P i l e'); g r i d on; f i g u r e ( g c f )
% p r i n t -deps p i l e s h e r
d i s p ('P r e s s [Enter] t o see a n i m a t i o n'), pause
% Draw an ani mat i on d e p i c t i n g t h e p i l e re s ponse % t o t h e o s c i l l a t i o n of t h e f o u n d a t i o n f u =.1 0/m a x ( y (:) ); p = [ - 0.7 0, 0.7 0, -.1, 1.3 ]; u=fu*y; upe=fu*L*ype; d=.15; x m = [ 0,0,1,1,0,0 ] * d; y m = [ 0,- 1,- 1,1,1,0 ] * d; zm=xm+i*ym; c l o s e; f o r j j = 1:4 f o r j = 1:n t
z = e x p ( i * a t a n ( u p e ( j ) ) ) * z m; x x = r e a l ( z ); yy=imag(z); u t = [ u ( j,:),u ( j,n x ) + y y ]; x t = [ x/L,1 + x x ]; p l o t ( u t,x t,'-'); a x i s ( p ); a x i s ('s q u a r e'); t i t l e ('F o r c e d V i b r a t i o n of a P i l e'); a x i s ('o f f'); drawnow; f i g u r e ( g c f ); end end
% p r i n t -deps p i l e a n i m f p r i n t f ('\n A l l D o n e\n');
9.8 Transient Heat Conduction in a One-Dimensional Slab
Let us analyze the temperature history in a slab which has the left side insulated while the right side temperature varies sinusoidally according to U0 sin(QT). The initial temperature in the slab is specified to be zero. The pertinent boundary value problem is
d2U dU
a ^ ( X,T ) = — ( X,T ),0 < X < £,T > 0,
d U
— (0,T) = 0, U{i,T) = U0sm{QT),
U (X, 0) = 0 , 0 < X < ί
wher e U, X, T, and a are, respectively, the temperature, position, time, and thermal diffusivity.
The problem can be converted to dimensionless form by letting
U X aT Ωί2
u ~ TTo ' x ~ Ύ ' * ~ ' ω ~
Then we get
d2u du
= 77— , 0 < x < 1 , t > 0, dx2 dx
du
— (0, t) = 0 , u( 1, t) = imag (ε*ωί) , u(x, 0) = 0.
The solution consists of two parts as u = w + v, where w is a particular solution satisfying the differential equation and nonhomogeneous boundary conditions, and v is a solution satisfying homogeneous boundary conditions and specified to impose the desired zero initial temperature when combined with w. The appropriate form for the particular solution is
w = imag [f (χ)βιωί] .
Making w satisfy the heat equation requires
f'(x) = iwf (x).
Consequently
f (x) = c1 si n^x) + c2 cos ^x)
wher e φ = ^/—ιω. The conditions of zero gradient at x = 0 and unit function value at x = 1 determine c1 and c2. We get the particular solution as
imag
cos(φχ) ut
cos^)
w
This forced response solution evaluated at t = 0 yields
w(x, 0) = imag
cos(φx) coβ(φ)
The general solution of the heat equation satisfying zero gradient at x function value at x = 1 is found to be
0 and zero
v(x,t) an cos(Xnx)e
where An = π( 2η—1)/2. To make the initial temperature equal zero in the combined solution, the coefficients an are chosen to satisfy
tt
an
n=1
an cos(Xnx) = — imag
cos^x)
cos^)
The orthogonality of the functions cos(Anx) implies
an = 2
which can be integrated to give
imag
cos^x)
cos^)
cos(Anx)dx
an = — imag
(sin(An + φ)/(An + φ) + sin(An — φ)/(An — φ))
cos ^)
Thi s compl et el y det er mi nes t he sol ut i on. Taki ng any fi ni t e number of t er ms i n t he ser i es pr oduces an appr oxi mat e sol ut i on exact l y sat i sf yi ng t he di f f er ent i al equat i on and boundar y condi t i ons. Exact sat i sf act i on of t he zer o i ni t i al condi t i on woul d t heo­
r et i cal l y r equi r e an i nf i ni t e number of ser i es t er ms. However, t he t er ms i n t he ser i es decr ease l i ke O( 1/n3) and using a 250-term series produces initial temperature val­
ues not exceeding 10~6. Thus, the finite series is satisfactory for practical purposes.
The above equations were evaluated in a function called heat. Function slab- heat was also written to plot numerical results. The code and resulting
Figures 9.23
and
9.24 appear below. This example illustrates nicely how well MATLAB handles complex arithmetic and complex valued functions.
2
Kt
1
0
dimensionless temperature temperature
Temperature Variation in a Slab
Figure 9.22: Temperature Variation in a Slab
Temperature History at Ends and Middle
dimensionless time
2
time
x axis
Figure 9.23: Temperature History at Ends and Middle
Heat Conduction Program Program slabheat
f u n c t i o n s l a b h e a t % Exampl e: s l a b h e a t %...........................................
% T h i s p r o g r a m comput es t h e t e m p e r a t u r e % v a r i a t i o n i n a o n e - d i m e n s i o n a l s l a b w i t h % t h e l e f t end i n s u l a t e d and t h e r i g h t end % g i v e n a t e m p e r a t u r e v a r i a t i o n s i n ( w * t ).
%
% Us e r m f u n c t i o n s r e q u i r e d: h e a t
[ u 1,t 1,x 1 ] = h e a t ( 1 2,0,2,5 0,0,1,5 1,2 5 0 ); s u r f ( x 1,t 1,u 1 ); a x i s ( [ 0 1 0 2 - 2 2 ] ); t i t l e ('T e m p e r a t u r e V a r i a t i o n i n a S l a b'); x l a b e l ('x a x i s'); y l a b e l ('t i m e'); z l a b e l ('t e m p e r a t u r e'); v i e w ( [ 4 5,3 0 ] ) c o l o r m a p ('d e f a u l t'), s hg
d i s p (' '), d i s p ('P r e s s [ E n t e r ] t o c o n t i n u e') p a u s e
% p r i n t - d e p s t e m p s u r f
[ u 2,t 2,x 2 ] = h e a t ( 1 2,0,2,1 5 0,0,1,3,2 5 0 ); p l o t ( t 2,u 2 (:,1 ),'- -',t 2,u 2 (:,2 ),':', ...
t 2,u 2 (:,3 ),'-'); t i t l e ( ['T e m p e r a t u r e H i s t o r y a t E n d s' ...
' and M i d d l e'] ); x l a b e l ('d i m e n s i o n l e s s t i m e'); y l a b e l ('d i m e n s i o n l e s s t e m p e r a t u r e'); t e x t 1 ='L e f t E n d'; t e x t 2 ='M i d d l e'; t e x t 3 ='R i g h t E n d'; l e g e n d ( t e x t 1,t e x t 2,t e x t 3,3 ); s hg % p r i n t - d e p s t e m p l o t d i s p (' '), d i s p ('A l l D o n e');
%=============================================
f u n c t i o n [ u,t,x ] = ...
h e a t ( w,t m i n,t m a x,n t,x m i n,x m a x,n x,n s u m )
%
% [ u,t,x ] = h e a t ( w,t m i n,t m a x,n t,x m i n,x m a x,n x,n s u m ) %.......................................................................................................................
41: % T h i s f u n c t i o n e v a l u a t e s t r a n s i e n t h e a t
4 2: % c o n d u c t i o n i n a s l a b whi c h h a s t h e l e f t end
4 3: % (x=0) i n s u l a t e d and h a s t h e r i g h t end (x=1)
4 4: % s u b j e c t e d t o a t e m p e r a t u r e v a r i a t i o n
4 5: % s i n ( w * t ). The i n i t i a l t e m p e r a t u r e of t h e s l a b
4 6: % i s z e r o.
4 7: %
4 8: % W 49: %
5 0: % t m i n,t m a x
5 1: % n t
5 2: %
5 3: % xmi n,xmax
5 4: %
5 5: %
5 6: % nx
5 7: % nsum
5 8: %
5 9: % u 60: %
6 1: %
6 2: % t,x
6 3: %
6 4: % Us e r m f u n c t i o n s c a l l e d: n o n e.
6 5: %-------------------------------------------------------------------------------
66:
6 7: t = t m i n + ( t m a x - t m i n )/( n t - 1 ) * ( 0:n t - 1 ) ;
6 8: x = x m i n + ( x m a x - x m i n )/( n x - 1 ) * ( 0:n x - 1 ) ';
6 9: W = s q r t ( - i * w ); l n = p i * ( ( 1:n s u m ) - 1/2 );
7 0: v1=ln+W; v2=l n-W;
7 1: a = - i m a g ( ( s i n ( v 1 )./v 1 + s i n ( v 2 )./v 2 )/c o s ( W ) );
7 2: u = i m a g ( c o s ( W* x ) * e x p ( i * w * t )/c o s ( W) ) + ...
7 3: ( a ( o n e s ( n x,1 ),:).* c o s ( x * l n ) ) * ...
7 4: e x p ( - l n (:).~ 2 * t );
7 5: u = u'; t = t (:);
9.9 Transient Heat Conduction in a Circular Cylinder with Spa­
tially Varying Boundary Temperature
9.9.1 Problem Formulation
Transient heat conduction in a circular cylinder can be analyzed using an infinite series of Bessel functions. Consider a cylinder having an initial temperature distri­
- f r e q u e n c y o f t h e r i g h t s i d e t e m p e r a t u r e v a r i a t i o n
- t i m e l i m i t s f o r s o l u t i o n
- number o f u n i f o r m l y s p a c e d t i m e v a l u e s u s e d
- p o s i t i o n l i m i t s f o r s o l u t i o n. Va l u e s s h o u l d l i e b e t we e n z e r o and one.
- number o f e q u i d i s t a n t x v a l u e s
- number o f t e r m s u s e d i n t h e s e r i e s s o l u t i o n
- m a t r i x o f t e m p e r a t u r e v a l u e s. Time v a r i e s f r om row t o row.
x v a r i e s f r om col umn t o col umn.
- v e c t o r s o f t i m e and x v a l u e s
bution u0(r, θ) when the boundary is suddenly given a temperature variation f (θ) depending on the polar angle but independent of time. The problem is conveniently formulated in polar coordinates using dimensionless radius and time variables. The differential equation, boundary conditions, and initial conditions are as follows:
Urr H ur H TfUgg = ut , 0 < r < 1 , t > 0,
u(1^,t) = f ( θ) = Σ f nei n , 0 < θ < 2π,
n=-t t
u(r, θ, 0) = u0(r,θ) , 0 < r < 1 , 0 < θ < 2π.
Wi t h t he boundar y condi t i on expr essed as a compl ex Four i er ser i es, t he st eady- st at e sol ut i on sat i sf yi ng t he di f f er ent i al equat i on and t he boundar y condi t i ons is
j(r, θ) = - f 0 + 2 real | f nz n\ where z = rel6
The t ot al sol ut i on i s t he st eady- st at e sol ut i on combi ned wi t h a t r ansi ent sol ut i on w(r, θ, t) chosen to satisfy the initial condition and boundary conditions expressed as
w(r, θ, 0) = u0(r, θ) — v(r, θ) , w(1, θ, t) = 0.
The transient solution is a Fourier-Bessel series involving double subscripted coeffi­
cients depending on the functions v(r, θ) and u 0(r, θ). It is found that
w(r, θ, t) = Σ Σ Jn( Kkr) [Ank οοβ(ηθ) + Bnk sin(n$)] e x p ^ X 2^ t )
n=0k=1
wher e, f or n >
0 and k >
1, we have
2π 1
Ank
+ iBnk = Cnk =
— t t — τ w{r, θ
, O)rJn(Xnkr) βχρ(ίηθ)circle
πJn+1(Xnk) J J 0 0
with Xnk denoting the k/th positive root of Jn(r). The last formula almost applies for n = 0 except that A0k = C0k/2 and B0k = 0. The coefficients for n = 0 pertain to the radially symmetric case independent of the polar angle. Evaluating this series solution involves several steps which are: 1) Expanding the boundary condition in a complex Fourier series to obtain the steady-state solution; 2) Determining the zeros of the integer order Bessel functions J n(r); 3) Computing the series coefficients by numerical integration; and 4) Summing the series solution for various (r, θ) values with enough terms being used in the series to assure adequate satisfaction of the initial conditions and boundary conditions.
INITIAL TEMPERATURE DISTRIBUTION
Figure 9.24: Initial Temperature
9.9.2 Computer Formulation
A computer program was written to analyze the time dependent temperature field. The program specifies general initial temperature and boundary temperature. The series solution is evaluated on a polar coordinate grid and an animation of the tem­
perature variation from initial to steady state is shown. The program modules in­
clude: 1) heatcyln which calls the computational modules and plots results; 2) besjtabl returns Bessel function roots used in the series solution; 3) tempinit spec­
ifies the initial temperature field; 4) tempstdy computes the steady state solution; 5) tempdif computes the difference in the initial and the final temperature fields; 6) foubesco evaluates coefficients in the Fourier-Bessel series; and (7) tempsum sums the Fourier-Bessel series for a vector of time values. Figures 9.25
throug
h 9.28 show the initial, final, and two intermediate temperature states. The program animates the temperature history so the transition from initial to steady-state can be visualized.
temperature temperature
Temperature at time = 0.020
Figure 9.26: Temperature at t=0.05
temperature
STEADY STATE TEMPERATURE DISTRIBUTION
Figure 9.27: Steady State Temperature
Program heatcyln
1: f u n c t i o n h e a t c y l n 2: %
3: % h e a t c y l n
4: %..................................
5: % T h i s p r o g r a m a n a l y z e s t h e t i m e v a r y i n g t e m p e r a t u r e 6: % h i s t o r y i n a c i r c u l a r c y l i n d e r whi c h i n i t i a l l y h a s 7: % a r a d i a l l y s y mme t r i c t e m p e r a t u r e v a r y i n g p a r a - 8: % b o l i c a l l y. Then a s p a t i a l l y v a r y i n g b u t c o n s t a n t 9: % b o u n d a r y t e m p e r a t u r e d i s t r i b u t i o n i s i mpos e d. The 10: % t o t a l s o l u t i o n i s composed of a h a r mo n i c s t e a d y 11: % s t a t e s o l u t i o n p l u s a t r a n s i e n t component g i v e n by 12: % a F o u r i e r - B e s s e l s e r i e s.
13: % Us e r f u n c t i o n s c a l l e d:
14: % b e s j t a b l, t e m p i n i t, t e m p s t d y, f o u b e s c o,
15: % t empsum, t e m p d i f, gcqua d
16:
17: g l o b a l u b d r y b e s j r t
18:
19: % O b t a i n B e s s e l f u n c t i o n r o o t s n e e d e d i n t h e
2 0: % t r a n s i e n t s o l u t i o n
2 1: b e s j r t = b e s j t a b l ( 0:2 0,2 0 );
22:
2 3: % D e f i n e t h e s t e a d y s t a t e t e m p e r a t u r e i mpos ed 24: % on t h e o u t e r b o u n d a r y f o r t > 0 25: t h = l i n s p a c e ( 0,p i,1 0 0 )';
2 6: u d = c o s ( 2 * t h ).* ( t h < = p i/2 ) + .. .
2 7: ( - 3 + 4/p i * t h ).* ( t h > p i/2 & t h < 3 * p i/4 );
2 8: u d = [ u d;u d ( e n d - 1:- 1:1 ) ];
2 9: u b d r y = [ l i n s p a c e ( 0,3 6 0,1 9 9 )' ,u d ];
3 0: t h e t a = l i n s p a c e ( 0,2 * p i,6 5 );
3 1: r = l i n s p a c e ( 0,1,1 5 );
32:
3 3: % Compute and p l o t t h e i n i t i a l a nd f i n a l
3 4: % t e m p e r a t u r e f i e l d s
3 5: [ u i n i t,z ] = t e m p i n i t ( t h e t a,r );
3 6: [ u s t e a d y,z ] = t e m p s t d y ( t h e t a,r );
3 7: u m i n = m i n ( [ u s t e a d y (:);u i n i t (:) ] );
3 8: u m a x = m a x ( [ u s t e a d y (:);u i n i t (:) ] );
3 9: r a n g e = [ - 1,1,- 1,1,u m i n,u m a x ];
4 0: x = r e a l ( z ); y = i m a g ( z );
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:
74
75
76
77:
78
79
80:
81:
82
83:
84
85
86
s u r f ( x,y,u i n i t ), c o l o r m a p ('d e f a u l t') t i t l e ('I N I T I A L TEMPERATURE DISTRIBUTION') x l a b e l ('x a x i s'), y l a b e l ('y a x i s') z l a b e l ('t e m p e r a t u r e'), a x i s ( r a n g e ), d i s p (' ') d i s p ('P r e s s [Enter] t o see t h e s t e a d y') d i s p ('s t a t e t e m p e r a t u r e d i s t r i b u t i o n') shg, pause, d i s p (' ')
% p r i n t -deps t e m p i n i t
s u r f ( x,y,u s t e a d y )
title('STEADY STATE TEMPERATURE DISTRIBUTION') x l a b e l ('x a x i s'), y l a b e l ('y a x i s') z l a b e l ('t e m p e r a t u r e'), a x i s ( r a n g e ), shg % p r i n t -deps tempstdy
% Compute c o e f f i c i e n t s used i n t h e F o u r i e r - % Bessel s e r i e s f o r t h e t r a n s i e n t s o l u t i o n [ c,l a m,c p t i m ] = f o u b e s c o ( @ t e m p d i f,2 0,2 0,4 0,1 2 8 );
% Set a time i n t e r v a l s u f f i c i e n t t o n e a r l y % r e a c h s t e a d y s t a t e
tmax=.4; nt=81; t = l i n s p a c e ( 0,t m a x,n t );
% E val ua t e t h e t r a n s i e n t s o l u t i o n [ u,t s u m ] = t e m p s u m ( c,t h e t a,r,t,l a m ); u (:,:,1 ) = u i n i t - u s t e a d y;
% P l o t time h i s t o r y f o r t h e t o t a l s o l u t i o n whi l e 1
d i s p ('P r e s s [Enter] t o see t h e a n i m a t i o n') d i s p ('o r e n t e r 0 t o s t o p'), v = i n p u t ('> ? '); i f i s e m p t y ( v ), v=1; end i f v~=1, b r e a k, end f o r j = 1:n t
u t o t a l = u s t e a d y + u (:,:,j );
s u r f ( x,y,u t o t a l )
t i t l = s p r i n t f ( ['T e m p e r a t u r e a t time =',...
'% 6.3 f'],t ( j ) ); t i t l e ( t i t l ) x l a b e l ('x a x i s'), y l a b e l ('y a x i s') z l a b e l ('t e m p e r a t u r e'), a x i s ( r a n g e ); d r a w n o w; s h g, p a u s e (.3 ) e n d e n d
% = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
f u n c t i o n [ u,z ] = t e m p s t d y ( t h e t a,r )
%
% [ u,z ] = t e m p s t d y ( t h e t a,r )
%........................................................
% Steady s t a t e t e m p e r a t u r e d i s t r i b u t i o n i n a % c i r c u l a r c y l i n d e r of u n i t r a d i u s wi t h % p i e c e w i s e l i n e a r boundary v a l u e s % d e s c r i b e d i n g l o b a l a r r a y ubdry. g l o b a l ubdry
t h f t = 2 * p i/( 1 0 2 4 ) * ( 0:1 0 2 3 ); n=100; u f f t = i n t e r p 1 ( p i/1 8 0 * u b d r y (:,1 ),...
u b d r y (:,2 )/1 0 2 4,t h f t ); c = f f t ( u f f t ); z = e x p ( i * t h e t a (:) ) * r (:)'; u = - r e a l ( c ( 1 ) ) + 2 * r e a l (... p o l y v a l ( c ( n:- 1:1 ),z ) );
%=============================================
f u n c t i o n [ u,z ] = t e m p i n i t ( t h e t a,r )
%
% [ u,z ] = t e m p i n i t ( t h e t a,r )
%........................................................
% I n i t i a l t e m p e r a t u r e v a r y i n g p a r a b o l i c a l l y % wi t h t h e r a d i u s
t h e t a = t h e t a (:); r = r (:)'; z = e x p ( i * t h e t a ) * r; u = o n e s ( l e n g t h ( t h e t a ),1 ) * ( 1 - r.~ 2 );
%=============================================
f u n c t i o n [ u,z ] = t e m p d i f ( t h e t a,r )
%
% [ u,z ] = t e m p d i f ( t h e t a,r )
%.....................................................
% D i f f e r e n c e between t h e s t e a d y s t a t e temp- % e r a t u r e and t h e i n i t i a l t e m p e r a t u r e u 1 = t e m p s t d y ( t h e t a,r ); [ u 2,z ] = t e m p i n i t ( t h e t a,r ); u=u2-u1;
%=============================================
f u n c t i o n [ c,l a m,c p t i m ] = f o u b e s c o (...
f,n o r d,n r t s,n r q u a d,n f t )
%
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
% [ c,l a m,c p t i m ] = f o u b e s c o ( f,n o r d,n r t s,n r q u a d,n f t )
%....................................................................................................................
% F o u r i e r - B e s s e l c o e f f i c i e n t s computed u s i n g t h e % FFT
g l o b a l b e s j r t i f nar gi n< 5, nft =128; end i f nar gi n< 4, nrquad=50; end i f nar gi n< 3, n r t s = 1 0; end i f nar gi n< 2, nord=10; end i f nargin==0, f ='f b e s'; end t i c; l a m = b e s j r t ( 1:n o r d,1:n r t s ); c = z e r o s ( n o r d,n r t s );
[ d u m m y,r,w ] = g c q u a d ( [ ],0,1,n r q u a d,1 ); r = r (:)'; w=w(:)'; t h = 2 * p i/n f t * ( 0:n f t - 1 )'; f m a t = f f t ( f e v a l ( f,t h,r ) ); f m a t = f m a t ( 1:n o r d,:).* r e p m a t ( r.* w,n o r d,1 ); f o r n=1:nord f o r k = 1:n r t s l nk = l a m ( n,k );
v = s u m ( f m a t ( n,:).* b e s s e l j ( n - 1,l n k * r ) ); c ( n,k ) = 4 * v/n f t/b e s s e l j ( n,l n k ).~ 2; end end
c ( 1,:) = c ( 1,:)/2; cptim=toc; %=============================================
f u n c t i o n [ u,t c p u ] = t e m p s u m ( c,t h,r,t,l a m )
%
% [ u,t s u m ] = t e m p s u m ( c,t h,r,t,l a m )
%
% This f u n c t i o n sums a F o u r i e r - B e s s e l s e r i e s % f o r t r a n s i e n t t e m p e r a t u r e h i s t o r y i n a c i r c u l a r % c y l i n d e r wi t h gi ven i n i t i a l c o n d i t i o n s and % ze ro t e m p e r a t u r e a t t h e boundary. The s e r i e s % has t h e form
% u ( t h e t a,r,t ) = s u m ( { n = 0:n o r d - 1 ),k = 1:n r t s },...
% b e s s e l j ( n,l a m ( n + 1,k ) * r ) * r e a l (...
% c ( n + 1,k ) * e x p ( i * ( n + 1 ) * t h e t a ) ) *...
% e x p ( - l a m ( n + 1,k ) ~ 2 * t ), where % b e s s e l j ( n - 1,l a m ( n,k ) ) = 0 and % [ n o r d,n r t s ] = s i z e ( c )
%
% c - t h e s e r i e s c o e f f i c i e n t s f o r t h e i n i t i a l % t e m p e r a t u r e d i s t r i b u t i o n o b t a i n e d u s i n g
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
% f u n c t i o n foubesco
% t h - v e c t o r or t h e t a v a l u e s between
% z e r o and 2*pi
% r - v e c t o r of r a d i u s v a l u e s between
% z e r o and one
% lam - m a t r i x of b e s s e l f u n c t i o n r o o t s.
% I f t h i s argument i s o m i t t e d, t h e n
% f u n c t i o n b e s j r o o t i s c a l l e d t o
% compute t h e r o o t s
% u - a t h r e e - d i m e n s i o n a l a r r a y of f u n c t i o n
% v a l u e s where u ( i,j,k ) c o n t a i n s t h e
% t e m p e r a t u r e f o r t h e t a ( i ), r ( j ), t ( k )
% t c p u - computation time i n seconds t i c; [ n o r d,n r t s ] = s i z e ( c );
i f nar gi n< 5, l a m = b e s j r o o t ( 0:n o r d - 1,n r t s ); end t h = t h (:); n t h = l e n g t h ( t h ); r = r (:)'; n r = l e n g t h ( r ); n t = l e n g t h ( t ); N = r e p m a t ( ( 0:n o r d - 1 )',1,n r t s ); N=N(:)'; c = c (:).'; l am=l am(:); l a m 2 = - ( l a m.~ 2 )'; u = z e r o s ( n t h,n r,n t ); thmat=exp(i *t h*N); b e s m a t = b e s s e l j ( r e p m a t ( N',1,n r ),l a m * r ); f o r I = 1:n t
C = c.* e x p ( l a m 2 * t ( I ) );
u (:,:,I ) = r e a l ( t h m a t.* r e p m a t ( C,n t h,1 ) ) * b e s m a t;
end
t c p u = t o c;
%=============================================
f u n c t i o n r = b e s j t a b l ( n o r d r,n r t s )
%
% r = b e s j t a b l e ( n o r d r,n r t s )
%.....................................................
% This f u n c t i o n r e t u r n s a t a b l e f o r r o o t s of % b e s s e l j ( n,x ) = 0 a c c u r a t e t o about f i v e d i g i t s.
% r ( k,:) - c o n t a i n s t h e f i r s t 20 p o s i t i v e r o o t s of % b e s s e l j ( k - 1,x ) = 0; f o r k=1:21
% n o r d r - a v e c t o r of f u n c t i o n o r d e r s l y i n g % between 0 and 20
% n r t s - t h e h i g h e s t r o o t o r d e r not t o exceed % t h e t w e n t i e t h p o s i t i v e r o o t
i f nargin==0, nordr =0:20; n r t s = 2 0; end i f max(nordr)>20 | n r t s > 2 0, r=nan; r e t u r n; end r=[ 2.4 0 4 8 21.6415 40.7729 33.7758 53.7383 73.2731
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
3.8317 22.9452 42.0679 5.1356 24.2339 43.3551 6.3801 25.5094 44.6349 7.5883 26.7733 45.9076 8.7715 28.0267 47.1740 9.9362 29.2706 48.4345 11.0864 30.5060 24.3525 12.2251 31.7334 25.9037 13.3543 32.9537 27.4206 14.4755 34.1672 28.9084 15.5898 35.3747 30.3710 16.6983 36.5764 31.8117 17.8014 37.7729 33.2330 18.9000 14.9309 34.6371 19.9944 16.4707 36.0257 21.0852 17.9599 37.4001 22.1725 19.4094 38.7618 23.2568 20.8269 40.1118 24.3383 22.2178 41.4511 25.4171 23.5861 42.7804 5.5201 24.9350 44.1006 7.0156 26.2668 45.4122 8.4173 27.5839 46.7158 9.7611 28.8874 48.0122 11.0647 30.1790 49.3012 12.3385 31.4600 50.5836 13.5893 32.7310 51.8600 14.8213 33.9932 27.4935 16.0378 35.2471 29.0469 17.2412 36.4934 30.5692 18.4335 37.7327 32.0649 19.6160 38.9654 33.5372 20.7899 40.1921 34.9887 21.9563 41.4131 36.4220 23.1158 18.0711 37.8387 24.2692 19.6159 39.2405 25.4170 21.1170 40.6286 26.5598 22.5828 42.0041 27.6979 24.0190 43.3684 28.8317 25.4303 44.7220 29.9616 26.8202 46.0655 8.6537 28.1912 47.4003 10.1735 29.5456 48.7265 11.6199 30.8854 50.0446 13.0152 32.2119 51.3552
.3323 55.1847 74.6738 .8629 56.6196 76.0673 .3705 58.0436 77.4536 .8577 59.4575 78.8337 .3263 60.8617 80.2071 .7784 62.2572 81.5752 .2154 63.6441 55.7655 .6384 65.0231 57.3275 .0487 66.3943 58.8730 .4475 67.7586 60.4033 .8346 69.1159 61.9193 .2120 70.4668 63.4221 .5798 71.8113 64.9128 .9382 46.3412 66.3913 .2892 47.9015 67.8594 .6319 49.4422 69.3172 .9672 50.9651 70.7653 .2953 52.4716 72.2044 .6170 53.9631 73.6347 .9323 55.4405 75.0567 .9171 56.9052 76.4710 .4748 58.3579 77.8779 .0085 59.7991 79.2776 .5208 61.2302 80.6706 .0138 62.6513 82.0570 .4893 64.0629 83.4373 .9489 65.4659 84.8116 .3941 66.8607 58.9070 .8259 68.2474 60.4695 .2453 69.6268 62.0162 .6533 70.9988 63.5484 .0504 72.3637 65.0671 .4378 73.7235 66.5730 .8157 75.0763 68.0665 .1850 49.4826 69.5496 .5458 51.0436 71.0219 .8990 52.5861 72.4843 .2448 54.1117 73.9369 .5840 55.6217 75.3814 .9158 57.1174 76.8170 .2418 58.5996 78.2440 .0584 60.0694 79.6643 .6171 61.5277 81.0769 .1535 62.9751 82.4825 .6698 64.4123 83.8815
35
36
38
39
41
42
44
45
47
48
49
51
52
53
55
56
57
59
60
61
36
38
40
41
43
44
45
47
48
50
51
53
54
55
57
58
59
61
62
63
65
40
41
43
44
267
268
269
270
271
272
273
274
275
276
277
278
279
280 281 282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
14.3726 33.5265 52.6589 46.1679 65.8399 85.2738
15.7002 34.8300 53.9559 47.6493 67.2577 86.6603
17.0037 36.1237 55.2466 49.1157 68.6681 88.0408
18.2876 37.4081 30.6346 50.5681 70.0699 62.0485
19.5546 38.6843 32.1897 52.0077 71.4639 63.6114
20.8070 39.9526 33.7166 53.4352 72.8506 65.1593
22.0470 41.2135 35.2187 54.8517 74.2302 66.6933
23.2758 42.4678 36.6990 56.2576 75.6032 68.2142
24.4949 43.7155 38.1598 57.6538 76.9699 69.7230
25.7051 44.9577 39.6032 59.0409 78.3305 71.2205
26.9074 21.2117 41.0308 60.4194 52.6241 72.7065
28.1024 22.7601 42.4439 61.7893 54.1856 74.1827
29.2909 24.2702 43.8439 63.1524 55.7297 75.6493
30.4733 25.7482 45.2315 64.5084 57.2577 77.1067
31.6501 27.1990 46.6081 65.8564 58.7709 78.5555
32.8218 28.6266 47.9743 67.1982 60.2703 79.9960
33.9887 30.0337 49.3308 68.5339 61.7567 81.4291
11.7916 31.4228 50.6782 43.1998 63.2313 82.8535
13.3237 32.7958 52.0172 44.7593 64.6947 84.2714
14.7960 34.1543 53.3483 46.2980 66.1476 85.6825
16.2234 35.4999 54.6719 47.8178 67.5905 87.0870
17.6159 36.8336 55.9885 49.3204 69.0240 88.4846
18.9801 38.1563 57.2984 50.8072 70.4486 89.8772
20.3208 39.4692 58.6020 52.2794 71.8648 91.2635];
r = r e s h a p e ( r (:),2 1,2 0 ); r = r ( 1 + n o r d r,1:n r t s );
%=============================================
% f u n c t i o n [ v a l,b p,w f ] = g c q u a d ( f u n c,x l o w,...
% x h i g h,n q u a d,m p a r t s,v a r a r g i n )
% See Appendix B
9.10 Torsional Stresses in a Beam of Rectangular Cross Section
Elastic beams of uniform cross section are commonly used structural members. Evaluation of the stresses caused when beams undergo torsional moments depends on finding a particular type of complex valued function. This function is analytic inside the beam cross section and has its imaginary part known on the boundary [72]. The shear stresses TXZ and TYZ are obtained from the stress function f (z) of the complex variable z = x + iy according to
Tzx - ίτζγ ,n
---------------------------- = / ( z ) - I Z
μα
where μ is the shear modulus and α is the twist per unit length. In the case for a simply connected cross section, such as a rectangle or a semicircle, the necessary boundary condition is
at all boundary points. It can also be shown that the torsional moment causes the beam cross section to warp. The warped shape is given by the real part of f (z).
The geomet r y we wi l l anal yze i s r ect angul ar. As l ong as t he r at i o of si de l engt h r emai ns f ai r l y cl ose t o uni t y, f (z) can be well approximated by
where c1,... ,cn are real coefficients computed to satisfy the boundary conditions in the least square sense. The parameter s is used for scaling to prevent occurrence of large numbers when n becomes large. We take a rectangle with sides parallel to the coordinate axes and assume side lengths of 2a and 2b for the horizontal and vertical directions, respectively. The scaling parameter will be chosen as the larger of a and b. The boundary conditions state that for any point z * on the boundary we should have
Once the series coefficients are found, then shear stresses are computed as
A program was written to compute stresses in a rectangular beam and to show graph­
ically the cross section warping and the dimensionless stress values. The program is short and the necessary calculations are almost self explanatory. It is worthwhile to observe, however, the ease with which MATLAB handles complex functions. Note how intrinsic function linspace is used to generate boundary data and meshgrid is used to generate a grid of complex values (see lines 50, 51,72,73, and 74 of function recstrs). The sample problem employs a rectangle of dimension 2 units by 4 units. The maximum stress occurs at the middle of the longest side. Figures 9.28 through 9.31 plot the results of this analysis.
imag [f{z)\ = 1-\ζ γ
n
total stress transverse warping
Warping of the Cross Section
Figure 9.28: Warping of the Cross Section
Total Shear St re s s Surface
Figure 9.29: Total Shear Stress Surface
tangential stress y axis
Total Stress Contours
1
0.8 0.6 0.4 0.2 0 -0.2 -0.4 -0.6 -0.8 -1
-1.5 -1 -0.5 0 0.5 1 1.5
x axis
Figure 9.30: Total Stress Contours
Stress for y = b/2
position on a horizontal side
0.8
0.6
0.4
0.2
Figure 9.31: Stress for y = b/2
MATLAB Example Output from Torsion Example
>> r e c t o r;
=== TORSIONAL STRESS CALCULATION IN A RECTANGULAR ===
=== BEAM USING LEAST SQUARE APPROXIMATION ===
I n p u t t h e l e n g t h s of t h e h o r i z o n t a l and t h e v e r t i c a l s i d e s (make t h e l o n g s i d e h o r i z o n t a l )
> ? 3,2
I n p u t t h e number o f t e r ms u s e d i n t h e s t r e s s f u n c t i o n (30 t e r ms i s u s u a l l y enough)
> ? 30
P r e s s [ E n t e r ] t o p l o t t h e wa r p i n g s u r f a c e
P r e s s [ [ E n t e r ] ] t o p l o t t h e t o t a l s t r e s s s u r f a c e
P r e s s [ E n t e r ] t o p l o t t h e s t r e s s c o n t o u r s
P r e s s [ E n t e r ] t o p l o t t h e maximum s t r e s s on a r e c t a n g l e s i d e
The Maximum S h e a r S t r e s s i s 1.6951 a t x = 0 and y = 1
A l l Done >>
Program rector
i: f u n c t i o n r e c t o r 2: % Exampl e: r e c t o r
4: % T h i s p r o g r a m u s e s p o i n t m a t c h i n g t o o b t a i n an 5: % a p p r o x i m a t e s o l u t i o n f o r t o r s i o n a l s t r e s s e s 6: % i n a S a i n t Ve nant beam h a v i n g a r e c t a n g u l a r 7: % c r o s s s e c t i o n. The compl ex s t r e s s f u n c t i o n i s
8:
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
35
36
37
38
39
40:
41:
42
43:
44
45
46
47
48
49
50:
51:
52
% a n a l y t i c i n s i d e t h e r e c t a n g l e and has i t s % r e a l p a r t equal t o a b s ( z * z )/2 on t h e % boundary. The problem i s s o l v e d appr oxima te ly % u s i n g a polynomial s t r e s s f u n c t i o n which f i t s % t h e boundary c o n d i t i o n i n t h e l e a s t s quar e % s e n s e. S u r f a c e s and cont our cur ves d e s c r i b i n g % t h e s t r e s s and d e f or mat i on p a t t e r n i n t h e % beam c r o s s s e c t i o n a r e drawn.
%
% User m f u n c t i o n s r e q u i r e d: r e c s t r s c l e a r;
f p r i n t f ('\n = = = TORSIONAL STRESS CALCULATION'); f p r i n t f (' IN A RECTANGULAR ==='); f p r i n t f ('\n = = = BEAM USING LEAST SQUARE ');
fprintf('APPROXIMATION = = =\n');
f p r i n t f ('\n I n p u t t h e l e n g t h s of t h e '); f p r i n t f ('h o r i z o n t a l and t h e v e r t i c a l s i d e s\n'); f p r i n t f ('( m a k e t h e l ong s i d e h o r i z o n t a l )\n'); u = i n p u t ('> ? ','s'); u = e v a l ( ['[',u,']'] ); a = u ( 1 )/2; b = u ( 2 )/2;
% The b o u n d a r y c o n d i t i o n s a r e a p p r o x i m a t e d i n % t e r m s of t h e number o f l e a s t s q u a r e p o i n t s % u s e d a l o n g t h e s i d e s ns e g b =1 0 0; n s e g a = c e i l ( a/b * n s e g b ); n s e g a = f i x ( n s e g a/2 ); n s e g b = f i x ( n s e g b/2 ); f p r i n t f ('\n I n p u t t h e number o f t e r m s '); f p r i n t f ('u s e d i n t h e s t r e s s f u n c t i o n'); f p r i n t f ('\n ( 3 0 t e r m s i s u s u a l l y e n o u g h )\n'); n t r m s = i n p u t ('> ? ');
% D e f i n e a g r i d f o r e v a l u a t i o n o f s t r e s s e s.
% I n c l u d e t h e m i d d l e of e a c h s i d e. nx=41; n y = f i x ( b/a * n x ); n y = n y + 1 - r e m ( n y,2 );
[ c,p h i,s t r e s,z ] = ...
r e c s t r s ( a,n s e g a,b,n s e g b,n t r m s,n x,n y ); [ s m a x,k ] = m a x ( a b s ( s t r e s (:) ) ); z m a x = z (:); zmax=zmax( k); x m a x = a b s ( r e a l ( z m a x ) ); y ma x =a b s ( i ma g ( z ma x ) );
d i s p (' '), d i s p ( ['T h e Maximum S h e a r ',...
'S t r e s s i s ',n u m 2 s t r ( s m a x ) ] ); d i s p ( ['a t x = ',n u m 2 s t r ( x m a x ),' a n d y = ',...
n u m 2 s t r ( y m a x ) ] );
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
d i s p (' '); d i s p ('A l l Done');
%=
f u n c t i o n [ c,p h i,s t r e s,z ] =...
r e c s t r s ( a,n s e g a,b,n s e g b,n t r m s,n x o u t,n y o u t )
[ c,p h i,s t r e s,z ] =...
r e c s t r s ( a,n s e g a,b,n s e g b,n t r m s,n x o u t,n y o u t )
This f u n c t i o n us es l e a s t s quar e f i t t i n g t o o b t a i n an approximate s o l u t i o n f o r t o r s i o n a l s t r e s s e s i n a S a i n t Venant beam havi ng a r e c t a n g u l a r c r o s s s e c t i o n. The complex s t r e s s f u n c t i o n i s a n a l y t i c i n s i d e t h e r e c t a n g l e and has i t s r e a l p a r t equal t o a b s ( z * z )/2 on t h e boundary. The problem i s s o l v e d appr oxi ma t e l y u s i n g a polynomial s t r e s s f u n c t i o n which f i t s t h e boundary c o n d i t i o n i n t h e l e a s t s quar e s e n s e. The beam i s 2*a wide p a r a l l e l t o t h e x a x i s and 2*b deep p a r a l l e l t o t h e y a x i s. The s h e a r s t r e s s e s i n t h e beam a r e gi ven by t h e s t r e s s formul a:
( t a u z x - i * t a u z y )/( m u * a l p h a ) = - i * c o n j ( z ) + f'( z )
where
f ( z ) = i * s u m ( c ( j ) * z ~ ( 2 * j - 2 ), j = 1:n t r m s ) and c ( j ) a r e r e a l.
a,b - h a l f t h e s i d e l e n g t h s of t h e h o r i z o n t a l and v e r t i c a l s i d e s nsega, - numbers of s u b i n t e r v a l s used t o
nsegb form t h e l e a s t s quar e e q u a t i o n s
ntrms - number of terms used i n t h e
polynomial s t r e s s f u n c t i o n nxout, - number of g r i d p o i n t s used t o
nyout e v a l u a t e out put
c - c o e f f i c i e n t s d e f i n i n g t h e s t r e s s
f u n c t i o n
phi - v a l u e s of t h e membrane f u n c t i o n
s t r e s - a r r a y of complex s t r e s s v a l u e s
z - complex p o i n t a r r a y a t which
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
% s t r e s s e s a r e found
%
% User m f u n c t i o n s c a l l e d: none
%-------------------------------------------------------------------------------------
% Generate v e c t o r zbdry of boundary p o i n t s % f o r p o i n t matching. z b d r y = [ a + i * b/n s e g a * ( 0:n s e g a - 1 )';
i * b + a/n s e g b * ( n s e g b:- 1:0 )'];
% Determine a s c a l i n g p a r amet er used t o % p r e v e n t oc c ur r e nce of l a r g e numbers when % hi gh powers of z a r e used s=max(a,b);
% Form t h e l e a s t s quar e e q u a t i o n s t o impose % t h e boundary c o n d i t i o n s. n e q = l e n g t h ( z b d r y ); amat =ones(neq,nt rms); z t m p = ( z b d r y/s ).~ 2; b v e c =.5 * a b s ( z b d r y ).~ 2; f o r j = 2:n t r ms
a m a t (:,j ) = a m a t (:,j - 1 ).* z t m p;
end
% Solve t h e l e a s t s quar e e q u a t i o n s. amat = r e a l ( a m a t ); c=pinv(amat)*bvec;
% Generate g r i d p o i n t s t o e v a l u a t e % t h e s o l u t i o n. x s i d = l i n s p a c e ( - a,a,n x o u t ); y s i d = l i n s p a c e ( - b,b,n y o u t ); [ x g,y g ] = m e s h g r i d ( x s i d,y s i d ); z=xg+i*yg; z z = ( z/s ).~ 2;
% E val ua t e t h e warping f u n c t i o n p h i = - i m a g ( p o l y v a l ( f l i p u d ( c ),z z ) );
% E val ua t e s t r e s s e s and p l o t r e s u l t s c c = ( 2 * ( 1:n t r m s ) - 2 )'.* c; s t r e s = - i * c o n j ( z ) + i * ...
p o l y v a l ( f l i p u d ( c c ),z z )./( z + e p s * ( z = = 0 ) );
am=num2st r(- a);ap=num2st r( a);
bm=num2str(-b);bp=num2str(b);
% P l o t r e s u l t s
d i s p (' '), d i s p ('P r e s s [Enter] t o p l o t')
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
d i s p ('t h e warping s u r f a c e'), pause [ p a,k ] = m a x ( a b s ( p h i (:) ) ); P h i = a/4 * s i g n ( p h i ( k ) )/p h i ( k ) * p h i; c l o s e, c o l o r m a p ('d e f a u l t') s u r f c ( x g,y g,P h i )
t i t l e ('W a r p i n g of t h e Cross S e c t i o n') x l a b e l ('x a x i s'), y l a b e l ('y a x i s') z l a b e l ('t r a n s v e r s e w a r p i n g'); a x i s ('e q u a l') shg, d i s p (' ')
d i s p ('P r e s s [ [ E n t e r ] ] t o p l o t t h e') d i s p ('t o t a l s t r e s s s u r f a c e'), pause % p r i n t -deps warpsurf
s u r f c ( x g,y g,a b s ( s t r e s ) ); t i t l e ('T o t a l Shear S t r e s s S u r f a c e') x l a b e l ('x a x i s'); y l a b e l ('y a x i s') z l a b e l ('t o t a l s t r e s s'), a x i s ('e q u a l'), shg d i s p (' '), d i s p ('P r e s s [Enter] t o p l o t t h e') d i s p ('s t r e s s c o n t o u r s'), pause % p r i n t -deps r e c t o r s t
c o n t o u r ( x g,y g,a b s ( s t r e s ),2 0 ); c o l o r b a r t i t l e ('T o t a l S t r e s s C o n t o u r s'); x l a b e l ('x a x i s'); y l a b e l ('y a x i s') shg, d i s p (' ')
d i s p ('P r e s s [Enter] t o p l o t t h e maximum') d i s p ('s t r e s s on a r e c t a n g l e s i d e'), pause % p r i n t -deps t o r c o n t u
p l o t ( x s i d,a b s ( s t r e s ( 1,:) ),'k'); g r i d; y l a b e l ('t a n g e n t i a l s t r e s s'); x l a b e l ('p o s i t i o n on a h o r i z o n t a l s i d e'); t i t l e ('S t r e s s f o r y = b/2'); shg % p r i n t -deps t o r s t s i d
Chapiter 10
Eigenvalue Problems and Applications
10.1 Introduction
Eigenvalue problems occur often in mechanics, especially linear system dynam­
ics, and elastic stability. Usually nontrivial solutions are sought for homogeneous systems of differential equations. For a few simple systems like the elastic string, or a rectangular membrane, the eigenvalues and eigenfunctions can be determined exactly. More often, some discretization methods such as finite difference or finite element methods are employed to reduce the system to a linear algebraic form which is numerically solvable. Several eigenvalue problems analyzed in earlier chapters reduced easily to algebraic form where the function eig could immediately produce the desired results. The present chapter deals with several instances where reduction to eigenvalue problems is more involved. We will also make some comparisons of exact, finite difference, and finite element analyses. Among the physical systems studied are Euler beams and columns, two-dimensional trusses, and elliptical mem­
branes.
10.2 Approximation Accuracy in a Simple Eigenvalue Problem
One of the simplest but useful eigenvalue problems concerns determining nontriv­
ial solutions of
y"(x) + X2y(x) = 0, y(0) = y(1) = 0.
The eigenvalues and eigenfunctions are
yn = sin(n^x), 0 < x < 1, where λ η = ηπ, η = 1, 2, 3,...
It is instructive to examine the answers obtained for this problem using finite differ­
ences and spline approximations. We introduce a set of node points defined by
xj = j Δ, j = 0,1,2,...,N +1, Δ = 1/( N +1).
Then a finite difference description for the differential equation and boundary condi­
tions is
yj-1 - 2yj + Vj+1 + ω2Vj = 0, 1 < j < N, yo = Vn +1 = 0, ω = Δλ.
Sol vi ng t he l i near di f f er ence equat i on gi ves
Κ = 2(ΛΓ + 1) sin ^ , η =ί,...,Ν,
Vj = sin > η = 1,...,Ν, j = 0,..., Ν + 1
where the superscript d indicates a finite difference result. The ratio of the approxi­
mate eigenvalues to the exact eigenvalues is
sd / λ ■ ( πη λ ( πη λ
11! " " Sln \2 ( Ν + 1) ) ! \2 ( Ν + 1) ) '
So, for large enough M, we get Xf / Ai = 1 and / XN = ^ a 0.63. The smallest eigenvalue is quite accurate, but the largest eigenvalue is too low by about thirty-seven percent. This implies that the finite difference method is not very good for computing high order eigenvalues. For instance, to get λ d00 / λ 100 = 0.999 requires a rather high value of N = 2027.
An alternate approach to the finite difference method is to use a series representa­
tion
N
V(x) = Σ f k (x) ck
k = 1
w h e r e t h e f k(x) vanish at the end points. We then seek a least-squares approximate solution imposing
N N
Σ f k (ξ )ck + f k( ^j ) Ck = 0
k=1 k=1
for a set of collocation points ξ j, j = 1 ... M with M taken much larger than N. With the matrix form of the last equation denoted as B C + λ 2 A C = 0, we make the error orthogonal to the columns of matrix A and get the resulting eigenvalue problem
(A\B) C + λ2 C = 0
employing the generalized inverse of A. A short program eigverr written to compare the accuracy of the finite difference and the spline algorithms produced
Figure 10.1.
The program is also listed. The spline approximation method gives quite accurate results, particularly if no more than half of the computed eigenvalues are used.
Percent Error
COMPARING TWO METHODS FOR EIGENVALUES OF Y"(X)+W*Y(X)=0, Y(0)=Y(1)=0
Eigenvalue Index
Figure 10.1: Comparing an eigenvalue computation using the least squares
method and a second order finite differences method
Program eigverr
f u n c t i o n e i g v e r r ( n f d,n s p l,k s e g )
% e i g v e r r ( n f d,n s p l,k s e g )
% This f u n c t i o n compares two methods of computing % e i g e n v a l u e s cor r e s p o n d i n g t o %
% y"(x)+w~2*y(x)=0, y( 0) =y(1)=0.
%
% R e s u l t s a r e o b t a i n e d u s i n g 1) f i n i t e d i f f e r e n c e s % and 2) cubic s p l i n e s.
%
% n f d - number of i n t e r i o r p o i n t s used f o r t h e
% f i n i t e d i f f e r e n c e e q u a t i o n s
% n s p l - number of i n t e r i o r p o i n t s used f o r t h e
% s p l i n e f u n c t i o n s.
% kseg - t h e number of i n t e r i o r s p l i n e p o i n t s i s % k s e g * ( nspl +1) + ns pl
i f nargin==0, nfd=100; nspl=100; kseg=4; end [ w s,e s ] = s p l e i g ( n s p l,k s e g ); [ w d,e d ] = f i n d i e i g ( n f d ); str=['COMPARING TWO METHODS FOR EIGENVALUES ',...
'O F Y"( X ) + W ~ 2 * Y ( X ) = 0, Y ( 0 ) = Y ( 1 ) = 0']; p l o t ( 1:n s p l,e s,'k -',1:n f d,e d,'k.') t i t l e ( s t r ), x l a b e l ('E i g e n v a l u e I n d e x') y l a b e l ('P e r c e n t E r r o r'), N f d = n u m 2 s t r ( n f d ); N s = n u m 2 s t r ( n s p l ); M = n u m 2 s t r ( n s p l + ( n s p l + 1 ) * k s e g ); l e g e n d ( ['U s i n g ',N s,' c u b i c s p l i n e s a n d ',...
M,' l e a s t s q u a r e p o i n t s'],...
['U s i n g ',N f d,' f i n i t e d i f f e r e n c e s p o i n t s'],3 ) g r i d on, s hg % p r i n t - d e p s e i g v e r r
%==========================================
f u n c t i o n [ w,p c t e r r ] = f i n d i e i g ( n )
% [ w,p c t e r r ] = f i n d i e i g ( n )
% T h i s f u n c t i o n d e t e r m i n e s e i g e n v a l u e s of % y''( x ) + w ~ 2 * y ( x ) = 0, y ( 0 ) = y ( 1 ) = 0 % The s o l u t i o n u s e s an n p o i n t f i n i t e % d i f f e r e n c e a p p r o x i m a t i o n i f n a r g i n = = 0, n=100; end a = 2 * e y e ( n,n ) - d i a g ( o n e s ( n - 1,1 ),1 )...
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
74
75
76
77
78
79
80
- d i a g ( o n e s ( n - 1,1 ),- 1 ); w = ( n + 1 ) * s q r t ( s o r t ( e i g ( a ) ) ); w e = p i * ( 1:n )'; pct er r=100*(w-we)./we;
%==========================================
f u n c t i o n [ w,p c t e r r ] = s p l e i g ( n,n s e g )
% [ w,p c t e r r ] = s p l e i g ( n,n s e g )
% This f u n c t i o n de t e r mi ne s e i g e n v a l u e s of % y''( x ) +w~ 2 * y ( x ) =0, y(0)=y(1)=0 % The s o l u t i o n u s e s n s p l i n e b a s i s f u n c t i o n s % and nseg*(n+1)+n l e a s t s quar e p o i n t s
i f nargin==0, n=100; nseg=1; end nl s=(n+1)*nseg+n; x l s = ( 1:n l s )'/( n l s + 1 ); a = z e r o s ( n l s,n ); b=a; f o r k=1:n
a (:,k ) = s p l n f ( k,n,1,x l s,2 ); b (:,k ) = s p l n f ( k,n,1,x l s ); end
w = s q r t ( s o r t ( e i g ( - b\a ) ) ); w e = p i * ( 1:n )'; pct er r=100*(w-we)./we;
%==========================================
f u n c t i o n y = s p l n f ( n,N,l e n,x,i d e r i v )
% y = s p l n f ( n,N,l e n,x,i d e r i v )
% This f u n c t i o n computes t h e s p l i n e b a s i s % f u n c t i o n s and d e r i v a t i v e s xd=l en/( N+1) *( 0:N+1)'; yd=zeros(N+2,1); y d ( n + 1 ) = l;
i f nar gi n< 5, y = s p l i n e ( x d,y d,x ); e l s e i f i de r i v = = 1, y = s p l i n e d ( x d,y d,x ); e l s e, y = s p l i n e d ( x d,y d,x,2 ); end
%==========================================
% f u n c t i o n v a l = s p l i n e d ( x d,y d,x,i f 2 )
% See Appendix B
10.3 Stress Transformation and Principal Coordinates
The state of stress at a point in a three-dimensional continuumis described in terms of a symmetric 3 x 3 matrix t = [t(i, j)] where t(i, j) denotes the stress component in the direction of the x % axis on the plane with it normal in the direction of the x 0 axis [9]. Suppose we introduce a rotation of axes defined by matrix b such that row b(i,:) represents the components of a unit vector along the new X x axis measured relative to the initial reference state. It can be shown that the stress matrix t corresponding to the new axis system can be computed by the transformation
t = btbT.
Somet i mes i t is desi r abl e t o l ocat e a set of r ef er ence axes such t hat t t is diagonal, in which case the diagonal components of t t represent the extremal values of normal stress. This means that seeking maximum or minimumnormal stress on aplane leads to the same condition as requiring zero shear stress on the plane. The eigenfunction operation
[ e i g v e c s,e i g v a l s ] =\b e i g ( t );
applied to a symmetric matrix t produces an orthonormal set of eigenvectors stored in the columns of e i g v e c s, and a diagonal matrix e i g v a l s having the eigenvalues on the diagonal. These matrices satisfy
e i g v e c s T t e i g v e c s = e i g v a l s.
Consequently, the rotation matrix b needed to transform to principal axes is simply the transpose of the matrix of orthonormalized eigenvectors. In other words, the eigenvectors of the stress tensor give the unit normals to the planes on which the normal stresses are extremal and the shear stresses are zero. The function prnstres performs the principal axis transformation.
10.3.1 Principal Stress Program Function prnstres
i: f u n c t i o n [ p s t r e s,p v e c s ] = p r n s t r e s ( s t r e s s )
2: % [ p s t r e s,p v e c s ] = p r n s t r e s ( s t r e s s )
3: %...........................................................................................................................................
4: %
5: % T h i s f u n c t i o n comput es p r i n c i p a l s t r e s s e s 6: % and p r i n c i p a l s t r e s s d i r e c t i o n s f o r a t h r e e -
7: % d i m e n s i o n a l s t r e s s s t a t e.
8: %
9: % s t r e s s -
10: %
11: %
12: %
13: % p s t r e s -
14: %
15: % p v e c s -
16: %
17: %
18: %
19: %
2 0: %
2 1: %
2 2: % Us e r m f u n c t i o n s c a l l e d: none
23:
2 4: s = s t r e s s (:)';
2 5: s = ( [ s ( [ 1 4 5 ] ); s ( [ 4 2 6 ] ); s ( [ 5 6 3 ] ) ] );
2 6: [ p v e c s,p s t r e s ] = e i g ( s );
2 7: [ p s t r e s,k ] = s o r t ( d i a g ( p s t r e s ) );
2 8: p v e c s = p v e c s (:,k )';
2 9: i f d e t ( p v e c s ) < 0, p v e c s ( 3,:) = - p v e c s ( 3,:); end
a v e c t o r d e f i n i n g t h e s t r e s s component s i n t h e o r d e r [ s x x,s y y,s z z,s x y,s x z,s y z ]
t h e p r i n c i p a l s t r e s s e s a r r a n g e d i n a s c e n d i n g o r d e r
t h e t r a n s f o r m a t i o n m a t r i x d e f i n i n g t h e o r i e n t a t i o n of t h e p r i n c i p a l a x i s s y s t e m. The rows o f t h i s m a t r i x d e f i n e t h e s u r f a c e n o r ma l s t o t h e p l a n e s on whi c h t h e e x t r e m a l n o r ma l s t r e s s e s a c t
10.3.2 Principal Axes of the Inertia Tensor
A rigid body dynamics application quite similar to principal stress analysis occurs in the kinetic energy computation for a rigid body rotating with angular velocity ω = [ωχ; ων; ωζ] about the reference origin [48]. The kinetic energy, K, of the body can be obtained using the formula
Κ = -ωτ.Τω
with the inertia tensor J computed as
J
p[L
r r — rr
where ρ is the mass per unit volume, I is the identity matrix, and r is the Cartesian radius vector. The inertia tensor is characterized by a symmetric matrix expressed in component form as
J
9 9
y + z2 - x y - x z
- x y
xz
2 2 x 2 + z2 - y z
2 2 - y z x + y
dxdydz.
Under the rotation transformation
r = br with bT b = I,
we can see t hat t he i ner t i a t ensor t r ansf or ms as
J = bJbT
whi ch i s i dent i cal t o t he t r ansf or mat i on l aw f or t he st r ess component mat r i x di s­
cus s ed earl i er. Consequent l y, t he i ner t i a t ens or wi l l al so possess pr i nci pal axes whi ch make t he of f - di agonal component s zer o. The ki net i c ener gy is expr essed mor e s i m­
pl y as
wher e t he component s of ω and J must be referred to the principal axes. The function prnstres can also be used to locate principal axes of the inertia tensor since the same transformations apply. As an example of principal axis computation, consider the inertia tensor for a cube of side length A and mass M which has a corner at (0,0,0) and edges along the coordinate axes. The inertia tensor is found to be
The computation
[ p v l,p v c ] = p r n s t r e s ( [ 2/3,2/3,2/3,- 1/4,- 1/4,- 1/4 ] );
produces the results
This shows that the smallest possible inertial component equals 1/6(« 0.1667) about the diagonal line through the origin while the maximal inertial moments of 11/12(« 0.9167) occur about the axes normal to the diagonal.
Trusses are a familiar type of structure used in diverse applications such as bridges, roof supports, and power transmission towers. These structures can be envisioned as
10.4 Vibration of Truss Structures
" 2/3 - 1/4 - 1/4"
J = - 1/4 2/3 - 1/4 MA 2. - 1/4 - 1/4 2/3
0.1667 p v l = 0.9167 , pvc 0.9167
-0.5574 -0.5574 -0.5574 -0.1543 0.7715 -0.6172 0.8018 —0.2673 —0.5345
a series of nodal points among which various axially loaded members are connected. These members are assumed to act like linearly elastic springs supporting tension or compression. Typically, displacement constraints apply at one or more points to prevent movement of the truss from its supports. The natural frequencies and mode shapes of two-dimensional trusses are computed when the member properties are known and the loads of interest arise from inertial forces occurring during vibration. A similar analysis pertaining to statically loaded trusses has been published recently [102].
Consider an axially loaded member of constant cross section connected between nodes i and j which have displacement components (u l,vl ) and (u0,v0) as indicated in
Figure 10.2.
The member length is given by
ί = \J(xo - x )2 + y - y^)2,
and the member inclination is quantified by the trigonometric functions
x„ — x, „ y-ι — yi
c = cos Θ = — and s = sm Θ = —.
The axial extension for small deflections is
Δ = ( u - Ui)c + ( v - vi)s.
The axial force needed to extend a member having length ί, elastic modulus E, and cross section area A is given by
AE AE
Pi j =— A = — [-c, - s, c, sj u%]
wher e
UIJ [ui ; Vl; UJ; vJ]
is a col umn mat r i x descr i bi ng t he nodal di spl acement s of t he member ends. The cor r espondi ng end f or ces ar e r epr es ent ed by
F%0 [Flx; Fiy; Fj x; Fjy] [ c, s, c, s ],
so t hat t he end f or ces and end di spl acement s ar e r el at ed by t he mat r i x equat i on
Fij — κ ^,
wher e t he el ement st i f f ness mat r i x is
AE
Aj j — —— [—c; —s; c; s] [—c, — s, c, s].
In regard to mass effects in a member, we will assume that any transverse motion is negligible and half of the mass of each member can be lumped at each end. Hence the mass placed at each end would be Αρί/2 where ρ is the mass per unit volume.
v
j
U
j
Figure 10.2: Typical Truss Element
The deflection of a truss with n nodal points can be represented using a generalized displacement vector and a generalized nodal force vector:
U [u1; V1; u2 ; v2 ; ... ; un; vn] , F [F1x ; F1y; F2x ; F2y; ... ; Fnx; Fny] .
When the contributions of all members in the network are assembled together, a global matrix relation results in the form
F = KU
wher e K is called the global stiffness matrix. Before we formulate procedures for assembling the global stiffness matrix, dynamical aspects of the problem will be discussed.
In the current application, the applied nodal forces are attributable to the accelera­
tion of masses located at the nodes and to support reactions at points where displace­
ment constraints occur. The mass concentrated at each node will equal half the sum of the masses of all members connected to the node. According to D’Alembert’s principle [48] a particle having mass m and acceleration u is statically equivalent to a force -mu.. So, the equation of motion for the truss, without accounting for support reactions, is
KU = - M U
wher e M is a global mass matrix given by
M = diag([m-1; m1; m2; m2; ...; mri; m j )
with ml denoting the mass concentrated at the i’th node. The equation of motion MU + KU = 0 will also be subjected to constraint equations arising when some points are fixed or have roller supports. This type of support implies a matrix equa­
tion of the form CU = 0.
Natural frequency analysis investigates states-of-motion where each node of the structure simultaneously moves with simple harmonic motion of the same frequency. This means solutions are sought of the form
U = X cos(wt)
where ω denotes a natural frequency and X is a modal vector describing the deflec­
tion pattern for the corresponding frequency. The assumed mode of motion implies U = - XU where λ =
ω2.
We are led to an eigenvalue problem of the form K X = XMX
wi t h a si de const r ai nt CX = 0 needed to satisfy support conditions.
MATLAB provides the intrinsic functions eig and null which deal with the solu­
tion to this problem effectively. Using function null we can write
X = QY
wher e Q has columns that are an orthonormal basis for the null space of matrix C. Expressing the eigenvalue equation in terms of Y and multiplying both sides by Q T gives
Ko Y = XMoY
wher e
Ko = QTKQ and Mo = QTMQ.
It can be shown f r om physi cal consi der at i ons t hat, i n gener al, K and M are symmet­
ric matrices such that K has real non-negative eigenvalues and M has real positive eigenvalues. This implies that Mo
can be factored as
Mo = N T N
wher e N isan upper triangular matrix. Then the eigenvalue problem can be rewritten
as
K1Z = XZ ,Y = N Z , K 1 = ( NT) -1 K oN - 1.
Becaus e mat r i x K 1 will be real and symmetric, the intrinsic function eig generates orthonormal eigenvectors. The function eigsym used by program trusvibs produces a set of eigenvectors in the columns of X which satisfy generalized orthogonality conditions of the form
XTM X = I and X TK X = Λ,
where Λ is a diagonal matrix containing the squares of the natural frequencies ar­
ranged in ascending order. The calculations performed in function eigsym illustrate the excellent matrix manipulative features that MATLAB embodies.
Before we discuss a physical example, the problem of assembling the global stiff­
ness matrix will be addressed. It is helpful to think of all nodal displacements as if
they were known and then compute the nodal forces by adding the stiffness contri­
butions of all elements. Although the total force at each node results only from the forces in members touching the node, it is better to accumulate force contributions on an element-by-element basis instead of working node by node. For example, a member connecting node i and node j will involve displacement components at row positions 2i - 1,2i, 2j - 1, and 2j in the global displacement vector and force com­
ponents at similar positions in the generalized force matrix. Because principles of superposition apply, the stiffness contributions of individual members can be added, one member at a time, into the global stiffness matrix. This process is implemented in function assemble which also forms the mass matrix. First, selected points con­
strained to have zero displacement components are specified. Next the global stiff­
ness and mass matrices are formed. This is followed by an eigenvalue analysis which yields the natural frequencies and the modal vectors. Finally the motion associated with each vibration mode is described by superimposing on the coordinates of each nodal point a multiple of the corresponding modal vector varying sinusoidally with time. Redrawing the structure produces an appearance of animated motion.
The complete program has several functions which should be studied individually for complete understanding of the methods developed. These functions and their purposes are summarized in the following table.
trusvibs crossdat assemble elmstf eigc
eigsym
trifacsm
drawtrus
cubrange
reads data and guides interactive input to ani­
mate the various vibration modes function typifying the nodal and element data to define a problem
assembles the global stiffness and mass data matrices
forms the stiffness matrix and calculates the
volume of an individual member
forms the constraint equations implied when
selected displacement components are set to
zero
solves the constrained eigenvalue problem pertaining to the global stiffness and mass matrices
factors a positive definite matrix into upper and lower global triangular parts draws the truss in deflected positions a utility routine to determine a window for drawing the truss without scale distortion
The data in function crossdat contains the information for node points, element data, and constraint conditions needed to define a problem. Once the data values are read, mode shapes and frequencies are computed and the user is allowed to observe the animation of modes ordered from the lowest to the highest frequency. The num­
ber of modes produced equals twice the number of nodal points minus the number
of constraint conditions. The plot in Figure 10.3 shows mode eleven for the sample problem. This mode has no special significance aside from the interesting deflection pattern produced. The reader may find it instructive to run the program and select several modes by using input such as 3:5 or a single mode by specifying a single mode number.
10.4.1 Truss Vibration Program Program trusvibs
f u n c t i o n t r u s v i b s Exampl e: t r u s v i b s
T h i s p r o g r a m a n a l y z e s n a t u r a l v i b r a t i o n modes f o r a g e n e r a l p l a n e p i n - c o n n e c t e d t r u s s. The d i r e c t s t i f f n e s s met hod i s empl oyed i n c o n j u n c t i o n w i t h e i g e n v a l u e c a l c u l a t i o n t o e v a l u a t e t h e n a t u r a l f r e q u e n c i e s and mode s h a p e s. The t r u s s i s d e f i n e d i n t e r m s o f a s e t o f n o d a l c o o r d i n a t e s and t r u s s members c o n n e c t e d t o d i f f e r e n t n o d a l p o i n t s. Gl o b a l s t i f f n e s s and mass m a t r i c e s a r e f o r me d. Then t h e f r e q u e n c i e s and mode s h a p e s a r e comput ed w i t h p r o v i s i o n f o r i mp o s i n g z e r o d e f l e c t i o n a t s e l e c t e d n o d e s. The u s e r i s t h e n a l l o w e d t o o b s e r v e a n i m a t e d mo t i o n of t h e v a r i o u s v i b r a t i o n modes.
Us e r m f u n c t i o n s c a l l e d:
e i g s y m, c r o s s d a t, d r a w t r u s, e i g c, a s s e m b l e, e l m s t f, c u b r a n g e
g l o b a l x y i n o d e j n o d e e l a s t a r e a r h o i d u x i d u y k f = 1; i d u x = [ ]; i d u y = [ ]; d i s p (' ') d i s p ( ['M o d a l V i b r a t i o n s f o r a P i n ', ... 'C o n n e c t e d T r u s s'] ); d i s p (' ');
% A s a mp l e d a t a f i l e d e f i n i n g a p r o b l e m i s % g i v e n i n c r o s s d a t.m
d i s p ( ['G i v e t h e name of a f u n c t i o n whi ch ', ...
'c r e a t e s y o u r i n p u t d a t a'] ); d i s p ( ['D o n o t i n c l u d e .m i n t h e name ', ...
'( u s e c r o s s d a t a s an e x a m p l e )'] ); f i l e n a m e = i n p u t ('>? ','s'); e v a l ( f i l e n a m e ); d i s p (' ');
% As s embl e t h e g l o b a l s t i f f n e s s and % mass m a t r i c e s [ s t i f f,m a s m a t ] = ...
1
2
3
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
74
75
76
77
78
79
80
81
82
83
84
85
a s s e m b l e ( x,y,i n o d e,j n o d e,a r e a,e l a s t,r h o );
% Compute n a t u r a l f r e q u e n c i e s and modal v e c t o r s % ac c o u n t i n g f o r t h e f i x e d nodes i f i x e d = [ 2 * i d u x (:) - 1; 2 * i d u y (:) ]; [ m o d v c s,e i g v a l ] = e i g c ( s t i f f,m a s m a t,i f i x e d ); n a t f r e q s = s q r t ( e i g v a l );
% Set par a m e t e r s used i n modal ani ma t i on ns t eps=31; s = s i n ( l i n s p a c e ( 0,6.5 * p i,n s t e p s ) ); x = x (:); y = y (:); n p = 2*l engt h( x); b i g x y = m a x ( a b s ( [ x;y ] ) ); s c a f ac =.05*bi gxy; hi ghmod=size(modvcs,2); hm=num2str(highmod);
% Show animated p l o t s of t h e v i b r a t i o n modes whi l e 1
d i s p ('G i v e t h e mode numbers t o be a n i m a t e d?'); d i s p ( ['D o not exceed a t o t a l of ',hm, ...
' m o d e s.'] ); d i s p ('I n p u t 0 t o s t o p'); i f kf==1, d i s p ( ['T r y 1:',h m ] ); kf=kf+1; end s t r = i n p u t ('>? ','s'); n m o d e = e v a l ( ['[',s t r,']'] ); nmode=nmode( f i nd( nmode<=hi ghmod) ); i f sum(nmode)==0; b r e a k; end % Ani mat e t h e v a r i o u s v i b r a t i o n modes h o l d o f f; c l f; o v r s i z = 1.1; w = c u b r a n g e ( [ x (:),y (:) ],o v r s i z ); a x i s ( w ); a x i s ('s q u a r e'); a x i s ('o f f'); h o l d on; f o r k k = 1:l e n g t h ( n m o d e ) % Loop o v e r e a c h mode kkn=nmode( kk);
t i t l = ['T r u s s V i b r a t i o n Mode Number ', ...
n u m 2 s t r ( k k n ) ]; d d = m o d v c s (:,k k n ); md d =ma x ( a b s ( d d ) ); d x = d d ( 1:2:n p ); d y = d d ( 2:2:n p ); c l f; p a u s e ( 1 );
% Loop t h r o u g h s e v e r a l c y c l e s o f mo t i o n f o r j j = 1:n s t e p s
s f = s c a f a c * s ( j j )/m d d; xd =x +s f * d x; yd =y +s f * d y; c l f; a x i s ( w ); a x i s ('s q u a r e'); a x i s ('o f f'); d r a w t r u s ( x d,y d,i n o d e,j n o d e ); t i t l e ( t i t l ); drawnow; f i g u r e ( g c f ); end end end
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
d i s p (' ');
%=============================================
f u n c t i o n c r o s s d a t
% [ i n o d e,j n o d e,e l a s t,a r e a,r h o ] = c r o s s d a t % This f u n c t i o n c r e a t e s d a t a f o r t h e t r u s s % v i b r a t i o n program. I t can s e r v e as a model % f o r o t h e r c o n f i g u r a t i o n s by changing t h e % f u n c t i o n name and d a t a q u a n t i t i e s % Data s e t: c r o s s d a t
%.............................................
%
% Data s p e c i f y i n g a c r o s s - s h a p e d t r u s s.
%
%-----------------------------------------------------------------------------------------
g l o b a l x y inode j node e l a s t a r e a rho idux iduy
% Nodal p o i n t d a t a a r e d e f i n e d by:
% x - a v e c t o r of x c o o r d i n a t e s
% y - a v e c t o r of y c o o r d i n a t e s
x=10*[.5 2.5 1 2 0 1 2 3 0 1 2 3 1 2 ]; y=10*[ 0 0 1 1 2 2 2 2 3 3 3 3 4 4 ];
% El e me nt d a t a a r e d e f i n e d by:
% i n o d e - i n d e x v e c t o r d e f i n i n g t h e I - n o d e s
% j n o d e - i n d e x v e c t o r d e f i n i n g t h e J - n o d e s
% e l a s t - v e c t o r of e l a s t i c modul us v a l u e s
% a r e a - v e c t o r of c r o s s s e c t i o n a r e a v a l u e s
% r h o - v e c t o r of mass p e r u n i t vol ume
% v a l u e s
i n o d e = [ 1 1 2 2 3 3 4 3 4 5 6 7 5 6 6 6 7 7 7 ...
8 9 10 11 10 11 10 11 1 3 ]; j n o d e = [ 3 4 3 4 4 6 6 7 7 6 7 8 9 9 10 11 10 ...
11 12 12 10 11 12 13 13 14 14 1 4 ]; e l a s t = 3 e 7 * o n e s ( 1,2 8 ); a r e a = o n e s ( 1,2 8 ); r h o = o n e s ( 1,2 8 );
% Any p o i n t s c o n s t r a i n e d a g a i n s t d i s p l a c e m e n t % a r e d e f i n e d by:
% i d u x - i n d i c e s of n o d e s h a v i n g z e r o % x - d i s p l a c e m e n t
% i d u y - i n d i c e s of n o d e s h a v i n g z e r o % y - d i s p l a c e m e n t
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
idux=[1 2]; iduy=[1 2]; %=============================================
f u n c t i o n d r a w t r u s ( x,y,i,j )
%
% d r a w t r u s ( x,y,i,j )
%...........................................
%
% This f u n c t i o n draws a t r u s s d e f i n e d by nodal % c o o r d i n a t e s d e f i n e d i n x,y and member i n d i c e s % d e f i n e d i n i,j.
%
% U s e r m f u n c t i o n s c a l l e d: n o n e %
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
h o l d o n;
f o r k = 1:l e n g t h ( i )
p l o t ( [ x ( i ( k ) ),x ( j ( k ) ) ],[ y ( i ( k ) ),y ( j ( k ) ) ] );
e n d
% = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
f u n c t i o n [ v e c s,e i g v a l s ] = e i g c ( k,m,i d z e r o )
%
% [ v e c s,e i g v a l s ] = e i g c ( k,m,i d z e r o )
%...............................................................................
% T h i s f u n c t i o n c o m p u t e s e i g e n v a l u e s a n d % e i g e n v e c t o r s f o r t h e p r o b l e m % k * x = e i g v a l * m * x
% w i t h s o m e c o m p o n e n t s o f x c o n s t r a i n e d t o % e q u a l z e r o. T h e i m p o s e d c o n s t r a i n t i s % x ( i d z e r o ( j ) ) = 0
% f o r e a c h c o m p o n e n t i d e n t i f i e d b y t h e i n d e x % m a t r i x i d z e r o.
%
% k - a r e a l s y m m e t r i c s t i f f n e s s m a t r i x
% m - a p o s i t i v e d e f i n i t e s y m m e t r i c m a s s
% m a t r i x
% i d z e r o - t h e v e c t o r o f i n d i c e s i d e n t i f y i n g
% c o m p o n e n t s t o b e m a d e z e r o
%
% v e c s - e i g e n v e c t o r s f o r t h e c o n s t r a i n e d
% p r o b l e m. I f m a t r i x k h a s d i m e n s i o n
% n b y n a n d t h e l e n g t h o f i d z e r o i s
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
% m (wi t h m<n), t h e n vecs w i l l be a
% s e t on n-m v e c t o r s i n n space
% e i g v a l s - e i g e n v a l u e s f o r t h e c o n s t r a i n e d % problem. These a r e a l l r e a l.
%
% User m f u n c t i o n s c a l l e d: eigsym
%-------------------------------------------------------------------------------------
n = s i z e ( k,1 ); j = 1:n; j ( i d z e r o ) = [ ]; c = e y e ( n,n ); c ( j,:) = [ ];
[ v e c s,e i g v a l s ] = e i g s y m ( ( k + k')/2, ( m + m')/2, c ); % = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
f u n c t i o n [ e v e c s,e i g v a l s ] = e i g s y m ( k,m,c )
%
% [ e v e c s,e i g v a l s ] = e i g s y m ( k,m,c )
%..........................................................................
% T h i s f u n c t i o n s o l v e s t h e c o n s t r a i n e d % e i g e n v a l u e p r o b l e m % k * x = ( l a m b d a ) * m * x, w i t h c * x = 0.
% M a t r i x k m u s t b e r e a l s y m m e t r i c a n d m a t r i x % m m u s t b e s y m m e t r i c a n d p o s i t i v e d e f i n i t e;
% o t h e r w i s e, c o m p u t e d r e s u l t s w i l l b e w r o n g.
%
% k - a r e a l s y m m e t r i c m a t r i x
% m - a r e a l s y m m e t r i c p o s i t i v e
% d e f i n i t e m a t r i x
% c - a m a t r i x d e f i n i n g t h e c o n s t r a i n t
% c o n d i t i o n c * x = 0. T h i s m a t r i x i s
% o m i t t e d i f n o c o n s t r a i n t e x i s t s.
%
% e v e c s - m a t r i x o f e i g e n v e c t o r s o r t h o g o n a l
% w i t h r e s p e c t t o k a n d m. T h e
% f o l l o w i n g r e l a t i o n s a p p l y:
% e v e c s'* m * e v e c s = i d e n t i t y _ m a t r i x
% e v e c s'* k * e v e c s = d i a g ( e i g v a l s ).
% e i g v a l s - a v e c t o r o f t h e e i g e n v a l u e s % s o r t e d i n i n c r e a s i n g o r d e r
%
% U s e r m f u n c t i o n s c a l l e d: n o n e %
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
i f n a r g i n = = 3
q = n u l l ( c ); m = q'* m * q; k = q'* k * q;
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
end
u=chol(m); k = u'\k/u; k = ( k + k')/2; [ e v e c s,e i g v a l s ] = e i g ( k ); [ e i g v a l s,j ] = s o r t ( d i a g ( e i g v a l s ) ); e v e c s = e v e c s (:,j ); eve cs =u\eve cs; i f nargin==3, evecs=q*evecs; end
%=
f u n c t i o n [ s t i f,m a s m a t ] = ... a s s e m b l e ( x,y,i d,j d,a,e,r h o )
%
% [ s t i f,m a s m a t ] = a s s e m b l e ( x,y,i d,j d,a,e,r h o )
%..........................................................................................................
%
% This f u n c t i o n assembles t h e g l o b a l % s t i f f n e s s m a t r i x and mass m a t r i x f o r a % p l a n e t r u s s s t r u c t u r e. The mass d e n s i t y of % each element e q u a l s u n i t y.
%
% x,y - nodal c o o r d i n a t e v e c t o r s
% i d,j d - nodal i n d i c e s of members
% a,e - a r e a s and e l a s t i c moduli of members
% rho - mass p e r u n i t volume of members
%
% s t i f - g l o b a l s t i f f n e s s m a t r i x
% masmat - g l o b a l mass m a t r i x
%
% User m f u n c t i o n s c a l l e d: e l m s t f %-----------------------------------------------------------------------------------------
numnod=length(x); numelm=length(a); i d = i d (:); j d = j d (:); s t i f = z e r os ( 2*numnod); masmat =st i f; i j = [ 2 * i d - 1,2 * i d,2 * j d - 1,2 * j d ]; f o r k=1:numelm, k k = i j ( k,:);
[ s t f k,v o l m k ] = ...
e l m s t f ( x,y Ja ( k ) Je ( k ) Ji d ( k ),j d ( k ) ); s t i f ( k k,k k ) = s t i f ( k k Jk k ) + s t f k; masmat(kk,kk)=masmat(kk,kk)+ ...
rh o ( k ) * v o l mk/2 * e y e ( 4,4 );
end
%
2 6 6: f u n c t i o n [ k,v o l ] = e l m s t f ( x,y,a,e,i,j )
2 6 7: %
2 6 8: % [ k,v o l ] = e l m s t f ( x,y,a,e,i,j )
2 6 9: %
2 7 0: %
2 7 1: % T h i s f u n c t i o n f o r ms t h e s t i f f n e s s m a t r i x f o r 2 7 2: % a t r u s s e l e m e n t. The member vol ume i s a l s o 2 7 3: % o b t a i n e d.
2 7 4: %
2 7 5: % Us e r m f u n c t i o n s c a l l e d: none
2 7 6: %-----------------------------------------------------------------------------------------
2 7 7:
2 7 8: x x = x ( j ) - x ( i ); y y = y ( j ) - y ( i );
2 7 9: L = n o r m ( [ x x,y y ] ); v o l =a * L;
2 8 0: c=xx/L; s =y y/L; k = a * e/L * [ - c;- s;c;s ] * [ - c,- s,c,s ];
2 8 1:
2 8 2: %=============================================
2 8 3:
2 8 4: % f u n c t i o n r a n g e = c u b r a n g e ( x y z,o v r s i z )
2 8 5: % See Appe ndi x B
10.5 Buckling of Axially Loaded Columns
Computing the buckling load and deflection curve for a slender axially loaded column leads to an interesting type of eigenvalue problem. Let us analyze a column of length L subjected to a critical value of axial load P just large enough to hold the column in a deflected configuration. Reducing the load below the critical value will allow the column to straighten out, whereas increasing the load above the buckling value will result in a structural failure. To prevent sudden collapse of structures using axially loaded members, designers must be able to calculate buckling loads corresponding to various end constraints. We will present an analysis allowing the flexural rigidity E I to vary along the length. Four common types of end conditions of interest are shown in
Figure 10.4.
For each of these systems we will assume that the coordinate origin is at the left end of the column1 with y(0) = 0. Cases I and II involve statically determinate columns. Cases III and IV are different because unknown end reactions occur in the boundary conditions.
All four problems lead to a homogeneous linear differential equation subjected to homogeneous boundary conditions. All of these cases possess a trivial solu­
tion where y(x) vanishes identically. However, the solutions of practical interest involve a nonzero deflection configuration which is only possible when P equals the buckling load. Finite difference methods can be used to accurately approximate
1 Al t hough col umns ar e usua l l y posi t i oned vert i cal l y, we show t hem as hor i zont al f or conveni ence.
P
y = 0
m = 0
y = 0
m = 0
I) Pinned-Pinned
M
P
y = 0
m = 0
y = y(t) y' = 0
II) Free-Fixed
P
£ r -
V
1 4
P
y = 0
m = 0
y = 0
y' = 0
III) Pinned-Fixed
y = 0 y = 0
y' = 0 y' = 0
IV) Fixed-Fixed
Figure 10.4: Buckling Configurations
m + d m
the differential equation and boundary conditions. In this manner we obtain a lin­
ear algebraic eigenvalue probl em subjected to side constraints characterized by an underdetermined system of linear simultaneous equations.
Consider a beam element relating the bending moment m, the transverse shear v, the axial load P, and the transverse deflection y as shown in Figure 10.5. Equilibrium considerations imply
v'(x) = 0 , m'(x) + Py'(x) = v.
Si nce no t r ansver se ext er nal l oadi ng act s on t he col umn bet ween t he end suppor t s, t he shear v is constant. Differentiating the moment equation gives
m" (x) + Py''(x) = 0.
Furthermore, flexural deformation theory of slender elastic beams implies
Ely'' (x) = m(x),
which leads to the following homogeneous differential equation governing the bend­
ing moment
EIm''(x) + Pm(x) = 0.
We need to find values of P allowing nontrivial solutions of this differential equation subject to the required homogeneous boundary conditions. The four types of end conditions shown in
Figure 10.4 impose both deflection and moment conditions at the ends. Cases I and II can be formulated completely in terms of displacements because moment conditions evidently imply
Ely'' (x) = m = -Py.
To handle cases III and IV, we need to relate the displacement and slope conditions at the ends to the bending moment. Let us denote the function 1/( EI ) as k(x) so that
y'' (x) = k(x)m(x).
y'(x) = y'(0)+ ί k^) m^) άξ J 0
Integration gives
y(x)= y(0)+ y'(0)x + f (x - £)k(£)m(£) άξ. J 0
The boundary conditions for the pinned-fixed case require that
a) y(0) = 0, b) y'(L) = 0, c) y(L) = 0. Condition b) requires
y'(0) = - f k(i)m(ξ) άξ,
0
whereas a) and c) combined lead to
L L
y(L)= y(0) - L km άξ +/ (L - ξ ) ^ ά ξ.
0 0
Cons equent l y f or Cases I I I and I V t he gover ni ng equat i on is
EI m"( x) + Pm( x) = 0.
The boundary conditions for Case III are
L
and χ
m(0) = 0 and / xk( x) m( x) άx = 0.
0
The boundary conditions for Case IV are handled similarly. Since we must have y'(0) = y'(L) = 0 and y(0) = y(L) = 0, the conditions are
L L
/ k(x)m( x) άx = 0 and / xk( x) m( x) άx = 0.
0 0
The results for each case require a nontrivial solution of a homogeneous differ­
ential equation satisfying homogeneous boundary conditions as summarized in the table below.
Each of these boundary value problems can be transformed to linear algebraic form by choosing a set of evenly spaced grid points across the span and approximat­
ing y"(x) by finite differences. It follows from Taylor’s series that
y"(x) = Φ - Ι > ) - Μ * ) + ν ί * + >>) + o m For sufficiently small h, we neglect the truncation error and write
yJ-1 - 2yJ + yJ+1
y
J
h2
where y0 is the approximation to y at x = x 0 = j h for 1 < j < n, where the stepsize h = L/( n + 1). Thus we have
(ΕΙ )Αν]-ί - 2% + %+i] K2
+ P y 3 = 0
Case
Differential
Equation
Boundary
Conditions
I:
pinned-pinned
EIy"(x) + Py( x) = 0
y(0) = 0
y(L) = o
II:
free-fixed
EIy"(x ) + Py( x) = 0
y(0) = 0
y\L) = o
III:
pinned-fixed
EIm"{x) + Pm(x) = 0
m( 0) = 0
fg k{x)m(x) dx = 0
IV:
fixed-fixed
EIm"{x) + Pm(x) = 0
k{x)m{x) dx = 0 xk{x)m( x) dx = 0
Buckling Problem Summary
for Cases I or II, and
(EI)3[m3- 1- 2 m 3 + m3+1] + p m = Q
h 2
f o r C a s e s I I I o r I V. A t t h e l e f t e n d, e i t h e r y or m is zero in all cases. Case I also has y(L) = yn+i = 0. Case II requires y'(L) = 0. This is approximated in finite difference form as
4yn — yn-i Vn+1 — ^
which implies for Case II that
// 2(ΐ/η_ 1 — yn)
Vn ~ 3 h? '
Cases III and IV are slightly more involved than I and II . The condition that
r L
/ mx
l £ 7'fa = ( l
can be f or mul at ed us i ng t he t r apezoi dal r ul e t o gi ve
bi * [mi,...,mn,mn+i ] T = 0,
where the asterisk indicates matrix multiplication involving a row matrix b 1 defined by
bi = [1,1,...,1,1/2] .* [ x i,x 2,...,x n,L\ ./ [ EI i,...,EI n,EI ri+i].
Similarly, the condition
m
Έϊάι
leads to
with
b2 * [mi,
ι Τ 1
, mn\ + ~
mo m n +1 El n EIn+1
b2
1
EIn
The first of these equations involving b i allows mn+i to be eliminated in Case III, whereas the two equations involving b i and b2 allow elimination of m 0 and mn+i (the moments at x = 0 and x = L) for Case IV. Hence, in all cases, we are led to an eigenvalue problem typified as
EIj (-m—i + 2m3 — m0+i) = Xm0
wi t h λ = h?P, and we understand that the equations for j = 1 and j = n may require modification to account for pertinent boundary conditions. We are led to solve
Am = Xm
where the desired buckling loads are associated with the smallest positive eigenvalue of matrix A. Cases I and II lead directly to the deflection curve forms. However, Cases III and IV require that the deflection curve be computed from the trapezoidal rule as
x
m
~ΕΪ
and
x m x mx
y{x) = y{0) + y (0) + x J — dx - J — dx.
The def l ect i on cur ves can be nor mal i zed t o make ymax equal unity. This completes the formulation needed in the buckling analysis for all four cases studied. These solutions have been implemented in the program described later in this section. An example, which is solvable exactly, will be discussed next to demonstrate that the finite difference formulation actually produces good results.
f x m
y'(x)=y'( 0 ) + ^ — dx
10.5.1 Exampl e f or a Li ne ar l y Tapered Ci r c ul ar Cros s Sect i on
Cons i der a col umn wi t h ci r cul ar cr oss sect i on t aper ed l i near l y f r om di amet er h i at x = 0 to diameter h2 at x = L. The moment of inertia is given by
I
7T(i4
”64~’
which leads to
EI = EoIo
sx
~L
L
0
1
4
where
h-2 - hi
, I q
nh\
hi ’ q 64
and Eq is the elastic modulus which is assumed to have a constant value. The differ­
ential equation governing the moment in all cases (and for y in Case I or II) is
/ s x\4 ... . P
1 + — TO (x) + — — m(x) = 0.
V L / Eq I q
Thi s equat i on can be r educed t o a si mpl er f or m by maki ng a change of var i abl es. Let us r epl ace x and m(x) by t and g(t) defined by
t= {1 + t ) ’ 9^ =
The differential equation for g(t) is found to be
L
g"{t) + Xg{t ) = 0 where Λ = —
P
Therefore,
m(x)
sx
~L
ci sin
l + f
\s\\l EqI q ■
+ c2 cos
l + f
where ci and c2 are arbitrary constants found by imposing the boundary conditions. We will determine these constants for Cases I, II, and III. Case IV can be solved similarly and is left as an exercise for the reader.
To deal with Cases I, II, and III it is convenient to begin with a solution that vanishes at x = 0. A function satisfying this requirement has the form
w = ('+ τ ) sin (iTf ~A)
This equation can also represent the deflection curve for Cases I and II or the moment curve for Case III. Imposition of the remaining boundary conditions leads to an eigenvalue equation which is used to determine X and the buckling load P. The deflection curve for Case I is taken as
Φ ) = (i + f ™ - a)
a n d t h e r e q u i r e m e n t t h a t y(L) = 0 yields
As ( s \ ( L I P~
1 + s γ ΐ + s y y s v EqI q J
Thi s means t hat t he buckl i ng l oad is
k 2 EqIq 2 , h2 - hi
Ρ = —-τ.— (1 + s) where s = — ------.
L2 hi
X
X
Therefore the buckling load for the tapered column (s = 0) is simply obtained by multiplying the buckling load for the constant cross section column (s = 0) by a factor
(1 + S)2=
Thi s i s a l s o t r ue f o r Ca s e s I I I a n d I V, but i s n o t t r ue f o r Ca s e I I. Le t us de r i ve t he c ha r a c t e r i s t i c e q ua t i on f o r Ca s e I I I. Th e c ons t r a i nt c o n di t i on f or t he pi nne d- f i xe d c a s e r e qui r e s
f L x m( x)
J ο EI
So we need
■ dx = 0.
I χ (1 + τ ) ’“ ( i t?- λ) ^ = °
Th i s e q u a t i o n c a n b e i n t e g r a t e d u s i n g t h e s u b s t i t u t i o n ( 1 + s x/L ) = t. This leads to a characteristic equation of the form
1 + s 1 + s V EqI q
The smal l est posi t i ve r oot of t hi s equat i on i s θ = 4.4934, which yields
„ 20.1906£o/o n , „ TTT
P = -------- —r----- (1 + s)
for Case III.
L 2
Further analysis produces
Ρ = ^^ (1 + s)2 for Case IV.
L 2
The characteristic equation for Case II can be obtained by starting with the Case I deflection equation and imposing the condition y '(L) = 0. This leads to
L P
s sin θ + Θ cos θ = 0 , Θ
1 + s V EqI q
When s = 0, the smallest positive root of this equation is θ = π/2. Therefore, the buckling load (when s = 0) is
P
7t 2 E0 I 0 4 L2
for Case II, and the dependence on s found in the other cases does not hold for the free-fixed problem.
10.5.2 Numerical Results
The function colbuc, which uses the above relationships, was written to analyze variable depth columns using any of the four types of end conditions discussed. The program allows a piecewise linear variation of EI. The program employs the func­
tion lintrp for interpolation and the function trapsum to perform trapezoidal rule integration. Comparisons were made with results presented by Beer and Johnston [9] and a comprehensive handbook on stability [19]. We will present some examples to show how well the program works. It is known that a column of length L and constant cross section stiffness EqI q has buckling loads of
π2 E0 I 0 π2 EqIq π2 EqIq π2 EqIq
L2 ’ (2L ) 2 ’ (0.6992L)2 ’ (0.5L ) 2
for the pinned-pinned, the free-fixed, the pinned-fixed, and the fixed-fixed end con­
ditions respectively. These cases were verified using the program colbuc. Let us il­
lustrate the capability of the program to approximately handle a discontinuous cross section change. We analyze a column twenty inches long consisting of a ten inch section pinned at the outer end and joined to a ten inch long section which is consid­
ered rigid and fixed at the outer end. We use E qI q = 1 for the flexible section and EqI q = 10000 for the rigid section. This configuration should behave much like a pinned-fixed column of length 100 with a buckling load of (π/6.992)2 = 0.2019.
Using 100 segments (nseq=10 0) the program yields a value of 0.1976, which agrees within 2.2% of the expected value. A graph of the computed deflection con­
figuration is shown in
Figure 10.6.
The code necessary to solve this problem is:
e i = [ 1 0; 1 10; 10000 10; 10000 2 0]; nseg=100; endc=3; l en=20; [ p,y,x ] = c o l b u c ( l e n,e i,n s e g,e n d c )
For a second example we consider a ten inch long column of circular cross section which is tapered from a one inch diameter at one end to a two inch diameter at the other end. We employ a fixed-fixed end condition and use E q = 1. The theoretical results for this configuration indicate a buckling load of π
3/400 = 0.07752.
Using 100 segments the program produces a value of 0.07728, which agrees within 0.3% of the exact result. The code to generate this result utilizes function eilt:
e i = e i l t ( 1,2,1 0,1 0 1,1 );
[ p,y,x ] = c o l b u c ( 1 0,e i,1 0 0,4 );
The examples presented illustrate the effectiveness of using finite difference meth­
ods in conjunction with the intrinsic eigenvalue solver in MATLAB to compute buck-
P i n n e d - F i x e d Buckling Load = 0.1975
axial direction
Figure 10.6: Analysis of Discontinuous Pinned-Fixed Column
ling loads. Furthermore, the provision for piecewise linear E I variation provided in the program is adequate to handle various column shapes.
Program Output and Code Function colbuc
f u n c t i o n [ p,y,x ] = c o l b u c ( l e n,e i,n s e g,e n d c )
% [ p,y,x ] = c o l b u c ( l e n,e i,n s e g,e n d c )
%..................................................................................
%
% T h i s f u n c t i o n d e t e r m i n e s t h e E u l e r b u c k l i n g
% l o a d f o r a s l e n d e r col umn o f v a r i a b l e c r o s s
% s e c t i o n whi c h c a n h a v e any one of f o u r % c o n s t r a i n t c o n d i t i o n s a t t h e col umn e n d s.
%
% l e n - t h e col umn l e n g t h
% e i - t h e p r o d u c t of Yo u n g's modul us and t h e
% c r o s s s e c t i o n moment of i n e r t i a. T h i s
% q u a n t i t y i s d e f i n e d a s a p i e c e w i s e
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
% l i n e a r f u n c t i o n s p e c i f i e d a t one or
% more p o i n t s al ong t h e l e n g t h. e i (:,1 )
% c o n t a i n s e i v a l u e s a t p o i n t s
% cor r e s p o n d i n g t o x v a l u e s gi ven i n
% e i (:,2 ). Values a t i n t e r m e d i a t e p o i n t s
% a r e computed by l i n e a r i n t e r p o l a t i o n
% u s i n g f u n c t i o n l i n t r p which al l ows
% jump d i s c o n t i n u i t i e s i n e i.
% nseg - t h e number of segments i n t o which t h e
% column i s d i v i d e d t o per form f i n i t e
% d i f f e r e n c e c a l c u l a t i o n s.T h e s t e p s i z e h
% e q u a l s l e n/n s e g.
% endc - a par amet er s p e c i f y i n g t h e t ype of end % c o n d i t i o n chosen.
% endc=1, bot h ends pinned
% endc=2, x=0 f r e e, x=len f i x e d
% endc=3, x=0 pi nned, x=len f i x e d
% endc=4, bot h ends f i x e d
%
% p - t h e E u l e r b u c k l i n g l o a d of t h e column
% x,y - v e c t o r s d e s c r i b i n g t h e shape of t h e
% column i n t h e buckl ed mode. x v a r i e s
% between 0 and l e n. y i s nor mal i ze d t o
% have a maximum v a l u e of one.
%
% User m f u n c t i o n s c a l l e d: l i n t r p, trapsum
i f nargin==0;
ei =[ 1 0; 1 10; 1000 10; 1000 20]; nseg=100; endc=3; len=20; end
% I f t h e column has c o n s t a n t c r o s s s e c t i o n,
% t h e n e i can be gi ven as a s i n g l e number.
% Also, use a t l e a s t 20 segments t o a s s u r e % t h a t computed r e s u l t s w i l l be r e a s o n a b l e. i f s i z e ( e i,1 ) < 2
e i = [ e i ( 1,1 ),0; e i ( 1,1 ),l e n ]; end
nseg=max(nseg,30); i f endc==1
% pi n n e d - p i n n e d case (y=0 a t x=0 and x=len) s t r ='P i n n e d - P i n n e d Buckling Load = '; h = l e n/n s e g; n=nseg-1; x = l i n s p a c e ( h,l e n - h,n );
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
e i v = l i n t r p ( e i (:,2 ),e i (:,1 ),x );
a = - d i a g ( o n e s ( n - 1,1 ),1 );
a = a + a'+ d i a g ( 2 * o n e s ( n,1 ) );
[ y v e c s,p v a l s ] = e i g ( d i a g ( e i v/h ~ 2 ) * a );
p v a l s = d i a g ( p v a l s );
% Di s c a r d any s p u r i o u s n o n p o s i t i v e e i g e n v a l u e s j = f i n d ( p v a l s < = 0 );
i f l e n g t h ( j ) > 0, p v a l s ( j ) = [ ]; y v e c s (:,j ) = [ ]; end [ p,k ] = m i n ( p v a l s ); y = [ 0;y v e c s (:,k );0 ]; [ ym,j] =max(abs( y)); y = y/y ( j ); x = [ 0;x (:);l e n ]; e l s e i f endc==2
% f r e e - f i x e d case (y=0 a t x=0 and y'=0 a t x=len) s t r ='F r e e - F i x e d Buckling Load = '; h = l e n/n s e g; n=nseg-1; x = l i n s p a c e ( h,l e n - h,n ); e i v = l i n t r p ( e i (:,2 ),e i (:,1 ),x ); a = - d i a g ( o n e s ( n - 1,1 ),1 ); a = a + a'+ d i a g ( 2 * o n e s ( n,1 ) );
% Zero s l o p e a t x=len i m p l i e s % y ( n + 1 ) = 4/3 * y ( n ) - 1/3 * y ( n - 1 ). This % l e a d s t o y ’ ’ ( n ) = ( y ( n - 1 ) - y ( n ) ) * 2/( 3 * h ~ 2 ). a ( n,[ n - 1,n ] ) = [ - 2/3,2/3 ]; [ y v e c s,p v a l s ] = e i g ( d i a g ( e i v/h ~ 2 ) * a ); p v a l s = d i a g ( p v a l s );
% Di s c a r d any s p u r i o u s n o n p o s i t i v e e i g e n v a l u e s j = f i n d ( p v a l s < = 0 );
i f l e n g t h ( j ) > 0, p v a l s ( j ) = [ ]; y v e c s (:,j ) = [ ]; end [ p,k ] = m i n ( p v a l s ); y = y v e c s (:,k ); y = [ 0;y;4 * y ( n )/3 - y ( n - 1 )/3 ]; [ym,j] =max(abs( y)); y = y/y ( j ); x = [ 0;x (:);l e n ]; e l s e i f endc==3 % p i n n e d - f i x e d case
% (y=0 a t x=0 and x=l en, y'=0 a t x=len) s t r ='P i n n e d - F i x e d Buckling Load = '; h = l e n/n s e g; n=nseg; x = l i n s p a c e ( h,l e n,n ); e i v = l i n t r p ( e i (:,2 ),e i (:,1 ),x ); a = - d i a g ( o n e s ( n - 1,1 ),1 ); a = a + a'+ d i a g ( 2 * o n e s ( n,1 ) );
% Use a f i v e p o i n t backward d i f f e r e n c e % appr oximati on f o r t h e second d e r i v a t i v e % a t x=len.
v = - [ 3 5/1 2,- 2 6/3,1 9/2,- 1 4/3,1 1/1 2 ]; a ( n,n:- 1:n - 4 ) = v; a = d i a g ( e i v/h ~ 2 ) * a;
% Form t h e e q u a t i o n r e q u i r i n g z e r o d e f l e c t i o n % a t x=l en.
b = x (:)'.* [ o n e s ( 1,n - 1 ),1/2 ]./e i v (:)';
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
% Impose t h e homogeneous boundary c o n d i t i o n q = n u l l ( b ); [ z,p v a l s ] = e i g ( q'* a * q ); p v a l s = d i a g ( p v a l s );
% Di s c a r d any s p u r i o u s n o n p o s i t i v e e i g e n v a l u e s k = f i n d ( p v a l s < = 0 );
i f l e n g t h ( k ) > 0, p v a l s ( k ) = [ ]; z (:,k ) = [ ]; end; vecs=q*z; [ p,k ] = m i n ( p v a l s ); m o m = [ 0;v e c s (:,k ) ]; % Compute t h e s l o p e and d e f l e c t i o n from % moment v a l u e s. y p = t r a p s u m ( 0,l e n,m o m./[ 1;e i v (:) ] ); yp=yp-yp(n+1); y = t r a p s u m ( 0,l e n,y p ); [ ym,j] =max(abs( y)); y = y/y ( j ); x = [ 0;x (:) ]; e l s e
% f i x e d - f i x e d case % (y and y' bo t h z e r o a t each end) s t r ='F i x e d - F i x e d Buckling Load = '; h = l e n/n s e g; n=nseg+1; x = l i n s p a c e ( 0,l e n,n ); e i v = l i n t r p ( e i (:,2 ),e i (:,1 ),x ); a = - d i a g ( o n e s ( n - 1,1 ),1 ); a = a + a'+ d i a g ( 2 * o n e s ( n,1 ) );
% Use f i v e p o i n t for ward and backward % d i f f e r e n c e appr oximati ons f o r t h e second % d e r i v a t i v e s a t each end. v = - [ 3 5/1 2,- 2 6/3,1 9/2,- 1 4/3,1 1/1 2 ]; a ( 1,1:5 ) = v; a ( n,n:- 1:n - 4 ) = v; a = d i a g ( e i v/h ~ 2 ) * a;
% Write homogeneous e q u a t i o n s t o make t h e % s l o p e and d e f l e c t i o n v a n i s h a t x=l en. b = [ 1/2,o n e s ( 1,n - 2 ),1/2 ]./e i v (:)'; b = [ b;x (:)'.* b ];
% Impose t h e homogeneous boundary c o n d i t i o n s q = n u l l ( b ); [ z,p v a l s ] = e i g ( q'* a * q ); p v a l s = d i a g ( p v a l s );
% Di s c a r d any s p u r i o u s n o n p o s i t i v e e i g e n v a l u e s k = f i n d ( p v a l s < = 0 );
i f l e n g t h ( k > 0 ), p v a l s ( k ) = [ ]; z (:,k ) = [ ]; end; vecs=q*z; [ p,k ] = m i n ( p v a l s ); mom=vecs(:,k);
% Compute t h e moment and s l o p e from moment % v a l u e s.
y p = t r a p s u m ( 0,l e n,m o m./e i v (:) ); y = t r a p s u m ( 0,l e n,y p );
[ ym,j] =max(abs( y)); y = y/y ( j ); end
c l o s e;
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
p l o t ( x,y ); g r i d on; x l a b e l ('a x i a l d i r e c t i o n'); y l a b e l ('t r a n s v e r s e d e f l e c t i o n'); t i t l e ( [ s t r,n u m 2 s t r ( p ) ] ); f i g u r e ( g c f ); p r i n t -deps buck
%=============================================
f u n c t i o n v = t r a p s u m ( a,b,y,n )
%
% v = t r a p s u m ( a,b,y,n )
%.............................................
%
% This f u n c t i o n e v a l u a t e s:
%
% i n t e g r a l ( a = > x, y(x)*dx) f o r a<=x<=b %
% by t h e t r a p e z o i d a l r u l e (which assumes l i n e a r % f u n c t i o n v a r i a t i o n between s u c c e s i v e f u n c t i o n % v a l u e s ).
%
% a,b - l i m i t s of i n t e g r a t i o n
% y - i n t e g r a n d which can be a v e c t o r v a l ued % f u n c t i o n r e t u r n i n g a m a t r i x such t h a t
% f u n c t i o n v a l u e s var y from row t o row.
% I t can a l s o be i n p u t as a m a t r i x wi t h
% t h e row s i z e b e i ng t h e number of
% f u n c t i o n v a l u e s and t h e column s i z e
% b e i n g t h e number of components i n t h e
% v e c t o r f u n c t i o n.
% n - t h e number of f u n c t i o n v a l u e s used t o % per form t h e i n t e g r a t i o n. When y i s a
% m a t r i x t h e n n i s computed as t h e number
% of rows i n m a t r i x y.
%
% v - i n t e g r a l v al u e %
% User m f u n c t i o n s c a l l e d: none
%---------------------------------------------------------------------------------------
i f i s s t r ( y )
% y i s an e x t e r n a l l y d e f i n e d f u n c t i o n x = l i n s p a c e ( a,b,n )'; h = x ( 2 ) - x ( 1 ); Y = f e v a l ( y,x ); % Funct i on v a l u e s must var y i n % row o r d e r r a t h e r t h a n column
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
% o r d e r or computed r e s u l t s % w i l l be wrong.
m=si ze(Y,2);
e l s e
% y i s column v e c t o r or a m a t r i x Y=y; [n,m]=si ze( Y); h = ( b - a )/( n - 1 ); end
v = [ z e r o s ( 1,m ); ...
h/2*c u m s u m ( Y( 1:n - 1,:) +Y( 2:n,:) ) ];
%=============================================
f u n c t i o n e i = e i l t ( h 1,h 2,L,n,E )
%
% e i = e i l t ( h 1,h 2,L,n,E )
%...................................................
%
% This f u n c t i o n computes t h e moment of i n e r t i a % al ong a l i n e a r l y t a p e r e d c i r c u l a r c r o s s % s e c t i o n and t h e n us es t h a t va l u e t o produce % t h e p r oduc t EI.
%
% h1,h2 - column d i a m e t e r s a t each end
% L - column l e n g t h
% n - number of p o i n t s a t which e i i s
% computed
% E - Young's modulus
%
% e i - v e c t o r of EI v a l u e s al ong column %
% User m f u n c t i o n s c a l l e d: none
%-----------------------------------------------------------------------------------------
i f nar gi n< 5, E=1; end; x = l i n s p a c e ( 0,L,n )'; e i = E * p i/64*( h1+( h2- h1)/L *x).~ 4; e i = [ e i (:),x (:) ];
%=============================================
% f u n c t i o n y = l i n t r p ( x d,y d,x )
% See Appendix B
10.6 Accuracy Comparison for Euler Beam Natural Frequencies by Finite Element and Finite Difference Methods
Next we consider three different methods of natural frequency computation for a cantilever beam. Comparisons are made among results from: a) the solution of the frequency equation for the true continuum model; b) the approximation of the equations of motion using finite differences to replace the spatial derivatives; and c) the use of finite element methods yielding a piecewise cubic spatial interpolation of the displacement field. The first method is less appealing as a general tool than the last two methods because the frequency equation is difficult to obtain for geometries of variable cross section. Frequencies found using finite difference and finite ele­
ment methods are compared with results from the exact model; and it is observed that the finite element method produces results that are superior to those from finite differences for comparable degrees of freedom. In addition, the natural frequencies and mode shapes given by finite elements are used to compute and animate the sys­
tem response produced when a beam, initially at rest, is suddenly subjected to two concentrated loads.
10.6.1 Mathematical Formulation
The differential equation governing transverse vibrations of an elastic beam of constant depth is [69]
Y (X, T
) - transverse displacement,
X - horizontal position along the beam length,
T - time,
EI - product of moment of inertia and Young’s modulus,
ρ - mass per unit length of the beam,
W (X,T) - external applied force per unit length.
In the present study, we consider the cantilever beam shown in
Figure 10.7,
having end conditions which are
This problem can be expressed more concisely using dimensionless variables
E I d x i = - p dT^ + w { x ’ T) ° ^ X ^ e’ T ^ °
w h e r e
Y (0, T) = 0 , m'g°x T) = 0 , E I d^ 2T) = Me ( T) , and E I ^ ^ ’P = VE(T).
Y
W(X)
Then the differential equation becomes
d4y d2y
a? = “ a? +
and the boundary conditions reduce to
2/(0, t) = 0 , | ^ ( 0, t ) = 0, = me(t) and = we(t)
where
w = ( W£ 3 )/( EI ) , me = ( Mei )/( EI ) and ve = ( Vel 2)/( EI ).
The nat ur al f r equenci es of t he sys t em ar e obt ai ned by comput i ng homogeneous s o­
l ut i ons of t he f or m y(x, t) = f (x) sin(wt) which exist when w = m e = ve = 0. This implies
^ = A4/ where A = y/ω,
subj ect t o
f (0) = 0 , f'( 0 ) = 0 , f"( 1 ) = 0 , f",( l ) = 0.
The solution satisfying this fourth order differential equation with homogeneous boundary conditions has the form
f = [cos(Ax)—cosh(Ax)][sin(A)+sinh(A)] —[sin(Ax)—sinh(Ax)]|cos(A)+cosh(A)],
where A satisfies the frequency equation
p(A) = cos(A) + 1/cosh(A) = 0.
Although the roots cannot be obtained explicitly, asymptotic approximations exist for large n:
An = (2k — 1)π/2.
These estimates can be used as the starting points for finding approximate roots of the frequency equation using Newton’s method:
XNEW — XoLD — p(XoLD)/p'(XoLD )·
The exact sol ut i on wi l l be us ed t o compar e r el at ed r esul t s pr oduced by fi ni t e di f f er ­
ence and fi ni t e el ement met hods. Fi r st we cons i der fi ni t e di f f er ences. The f ol l owi ng di f f er ence f or mul as have a quadr at i c t r uncat i on er r or der i vabl e f r om Tayl or ’s ser i es [1]:
y'(x) — [—y(x — h) + y(x + h)]/(2h), y'( x) — [y(x — h) — 2y(x) + y(x + h)]/h2,
y'"(x) — [—y(x — 2h) + 2y(x — h) — 2y(x + h ) + y(x + 2h)]/(2h3), y"" (x) — [y(x — 2h) — 4y(x — h) + 6y(x) — 4y(x + h ) + y(x + 2h)]/h4·
The step-size is h — 1/n so that x0 — jh, 0 < j < n, where x 0 is at the left end and x n is at the right end of the beam. It is desirable to include additional fictitious points x _ i,x n+i and x n+ 2. Then the left end conditions imply
yo — yi andy_i — yi, and the right end conditions imply
yn+1 — —yn_ 1 + 2 yn 3nd yn+2 — yn_ 2 — 4 yn_ 1 + 4yn·
Using these relations, the algebraic eigenvalue problem derived from the difference approximation is
7yi — 4y2 + y3 — Ayi,
—4yi + 6 y2 — 4y3 + y4 — Xf y2,
y3 _ 2 — 4y _ i + 6 y0 — 4yJ+i + y0 + 2 — Xy3 , 2 < j < (n — 1),
yn _ 3 — 4 yn_ 2 + 5yn_i — 2yn — Ayn_i,
2 yn_ 2 4yn_i + 2 yn — Ayn,
where A — h4 X.
The fi ni t e el ement met hod l eads t o a s i mi l ar pr obl em i nvol vi ng gl obal mass and st i f f ness mat r i ces [54]. When we consi der a si ngl e be a m el ement of mass m and length t, the elemental mass and stiffness matrices found using a cubically varying displacement approximation are
Me
156
22t
t
3 1
1
4
5
6
3t
—6
3t"
m
22t
4t 2
1
CO
—
CO
to
K
’ e _ p
3t
2t 2
—3t
t 2
420
54
13t
t
2
2
—
6
5
1
—6
—3t
6
—31
t
3
1
—
1
2
t
3
—
1
2
t
4
t
2
2
—
3t
t 2
1
CO
---
1
2
t
2
and the elemental equation of motion has the form
MeY'e + KeYe — Fe
Ye — [Yi X ,Y2, Y2 ]T and Fe — [Fi, Mi, F2, M2 ]T are generalized elemental displacement and force vectors. The global equation of motion is obtained as an assembly of element matrices and has the form
MY" + K Y — F.
A s ys t em wi t h N elements involves N + 1 nodal points. For the cantilever beam studied here both Y0 and Y0 are zero. So removing these two variables leaves a system of n — 2N unknowns. The solution of this equation in the case of a non­
resonant harmonic forcing function will be discussed further. The matrix analog of the simple harmonic equation is
MY + K Y — Fi cos(wt) + F2, sin(wt)
with initial conditions
Y (0) — Y0 and Y(0) — V0.
The sol ut i on of t hi s di f f er ent i al equat i on i s t he s um of a par t i cul ar sol ut i on and a homogeneous sol ut i on:
Y — Yp + Yh ,
wher e
YH — Yi cos(wt) + Y2 sin(wt)
with
Yj — (K — ω2 M ) _i Fj j — 1, 2.
This assumes that K — w2 M is nonsingular. The homogeneous equation satisfies the initial conditions
Y
h
(0) — Y
0
— Yi , Y
h
(0) — V
0
— w
Y2.
The homogeneous sol ut i on component s have t he f or m
YjH — Uj cos(wj t + )
where wj and Uj are natural frequencies and modal vectors satisfying the eigenvalue equation
KUj — ^ MUj.
Consequent l y, t he homogeneous sol ut i on compl et i ng t he modal r es ponse is
n
^ j [ c o s ( ^ jt)Cj + sni(tUjt)dj/ Wj]
wh e r e
YH (t) — Σ Uj [cos(wj t)cj + sin(LVjt)dj/wj\
j=i
wher e Cj and dj are computed to satisfy the initial conditions which require
C — U_ i (Y0 — Yi ) and D — U_i (V0 — wY2).
The next section presents the MATLAB program. Natural frequencies from finite difference and finite element matrices are compared and modal vectors from the finite element method are used to analyze a time response problem.
A program was written to compare exact frequencies from the original continuous beam model with approximations produced using finite differences and finite ele­
ments. The finite element results were also employed to calculate a time response by modal superposition for any structure that has general mass and stiffness matrices, and is subjected to loads which are constant or harmonically varying.
The code below is fairly long because various MATLAB capabilities are applied to three different solution methods. The following function summary involves nine functions, several of which were used earlier in the text.
10.6.2 Discussion of the Code
cbfreq
cbfrqnwm
cbfrqfdm
cbfrqfem
frud
examplmo
animate
plotsave
inputv
driver to input data, call computation modules, and print results
function to compute exact natural frequencies by New­
ton’s method for root calculation forms equations of motion using finite differences and calls eig to compute natural frequencies uses the finite element method to form the equation of motion and calls eig to compute natural frequencies and modal vectors
function which solves the structural dynamics equation
by methods developed in Chapter 7
evaluates the response caused when a downward load
at the middle and an upward load at the free end are
applied
plots successive positions of the beam to animate the motion
plots the beam frequencies for the three methods. Also plots percent errors showing how accurate finite ele­
ment and finite difference methods are reads a sequence of numbers
Table 10.2: Functions Used in the Beam Code
Several characteristics of the functions assembled for this program are worth exam­
ining in detail. The next table contains remarks relevant to the code.
Routine
Line
Operation
Output
Natural frequencies are printed along with er­
ror percentages. The output shown here has been extracted from the actual output to show only the highest and lowest frequencies.
continued on next page
continued from previous page
Routine
Line
Operation
cbfrqnwm
99
Asymptotic estimates are used to start a New­
ton method iteration.
102-108
Root corrections are carried out for all roots until the correction to any root is sufficiently small.
cbfrqfdm
135-136
The equations of motion are formed without corrections for end conditions.
138-145
End conditions are applied.
149*150
eig computes the frequencies.
cbfrqfem
182-186
Form elemental mass matrix.
189-192
Form elemental stiffness matrix.
198-201
Global equations of motion are formed using an element by element loop.
205
Boundary conditions are applied requiring zero displacement and slope at the left end, and zero moment and shear at the right end.
208-214
Frequencies and modal vectors are computed. Note that modal vector computation is made optional since this takes longer than only computing frequencies.
frud
Compute time response by modal superpo­
sition. Theoretical details pertaining to this function appear in Chapter 7.
examplmo
292-296
The time step and maximum time for re­
sponse calculation is selected.
300-301
Function frud is used to compute displace­
ment and rotation response. Only displace­
ment is saved.
304-307
Free end displacement is plotted.
314-319
A surface showing displacement as a function of position and time is shown.
324-326
Function animate is called.
animate
364-369
Window limits are determined.
373-381
Each position is plotted. Then it is erased be­
fore proceeding to the next position.
plotsave
Plot and save graphs showing the frequencies and error percentages.
Table 10.3: Description of Code in Example 10.6.3 Numerical Results
The dimensionless frequency estimates from the finite difference and the finite el­
ement methods were compared for various numbers of degrees-of-freedom. Typical
Cantilever Beam Frequencies
frequency number
Figure 10.8: Cantilever Beam Frequencies
program output for n = 100 is shown at the end of this section. The frequency results and error percentages are shown in Figures 10.8 and 10.9. It is evident that the finite difference frequencies are consistently low and the finite element results are consis­
tently high. The finite difference estimates degrade smoothly with increasing order. The finite element frequencies are surprisingly accurate for ω k when k < n/2. At k = n/2 and k = n, the finite element error jumps sharply. This peculiar error jump halfway through the spectrum has also been observed in [54]. The most important and useful result seen from
Figure 10.9 is that in order to obtain a particular number of frequencies, say N, which are accurate within 3.5%, it is necessary to employ more than 2N elements and keep only half of the predicted values.
The final result presented is the time response of a beam which is initially at rest when a concentrated downward load of five units is applied at the middle and a one unit upward load is applied at the free end. The time history was computed using function frud.
Figure 10.10 shows the time history of the free end.
Figure 10.11
is a surface plot illustrating how the deflection pattern changes with time. Finally, Figure 10.12 shows successive deflection positions produced by function animate. The output was obtained by suppressing the graph clearing option for successive configurations.
end deflection percent frequency error
Can ti l ever Beam Frequency Error Percentages
frequency number
Figure 10.9: Cantilever Beam Frequency Error Percentages
Position of the Free End of the Beam
dimensionless time
Figure 10.10: Position of the Free End of the Beam versus Time
deflection
Cantilever Beam Deflection for Varying Position and Time
0.6
0.4
0.2
0
-0.2
-0.4
-0.6 0
x axis
Figure 10.11: Beam Deflection History
Beam Animation
Figure 10.12: Beam Animation
MATLAB Example Output from Example
>> cbfreq
CANTILEVER BEAM FREQUENCIES BY FINITE DIFFERENCE AND FINITE ELEMENT APPROXIMATION
Give the number of frequencies to be computed (use an even number greater than 2)
? > 100
freq.
exact.
fdif.
fd. pct.
felt.
fe. pct
number freq.
freq.
error
freq.
error
1
3.51602e+00
3.51572e+00
-0.008
3.51602e+00
0.000
2
2 .2 03 45e + 01
2 .2 02 5 0e + 01
-0.043
2 .20345e + 01
0.000
3
6.16972e+01
6.16414e+01
-0.090
6.16972e+01
0.000
4
1.20902e+02
1.20714e+02
-0.155
1 .20902e + 02
0.000
5
1.99860e+02
1.99386e+02
-0.237
1.99860e+02
0.000
6
2.98556e+02
2.97558e+02
-0.334
2.98558e+02
0.001
7
4.16991e+02
4.15123e+02
-0.448
4.16999e+02
0.002
8
5.55165e+02
5.51957e+02
-0.578
5.55184e+02
0.003
9
7.13 079e+02
7.07918e+02
-0.724
7.13119e+02
0.006
10
8.90732e+02
8.82842e+02
-0.886
8.9 08 09e+02
0.009
11
1.08812e+03
1.07 655e+03
-1.064
1.0882 6e+03
0.013
12
1 .3 052 6e + 03
1.28884e+03
-1.257
1.30550e+03
0.019
13
1.54213e+03
1.51950e+03
-1.467
1.54252e+03
0.026
14
1.79874e+03
1.7683 0e+03
-1.692
1.79937e+03
0.035
15
2.07508e+03
2.03497e+03
-1.933
2.07 605e+03
0.047
16
2.37117e+03
2 .3192 6e+03
-2.189
2 .3 72 61e + 03
0.061
17
2.68700e+03
2.62 088e+03
-2.461
2.68908e+03
0.077
18
3.02257e+03
2.93951e+03
-2.748
3.02551e+03
0.098
19
3.37787e+03
3.27486e+03
-3.050
3.38197e+03
0.121
20
3.75292e+03
3.62 657e+03
-3.367
3.75851e+03
0.149
------ INTERMEDIATE LINES
OF OUTPUT
DELETED --
90
7.9 058 0e+04
3.883 4 0e+04
-50.879
1.09328e+05
38.288
91
8.08345e+04
3.90347e+04
-51.710
1.11989e+05
38.541
92
8.2 63 08e+04
3.92169e+04
-52.540
1.14512e+05
38.582
93
8.44468e+04
3.93804e+04
-53.367
1.16860e+05
38.384
94
8.62825e+04
3.952 5 0e+04
-54.191
1.18999e+05
37.917
95
8.8138 0e+04
3.96507e+04
-55.013
1.20889e+05
37.159
96
9.00133e+04
3.97572e+04
-55.832
1.22496e+05
36.086
97
9.19 082e+04
3.98445e+04
-56.648
1.23786e+05
34.684
98
9.38229e+04
3.9912 5e+04
-57.460
1.2 473 0e+05
32.941
99
9.57574e+04
3.99 611e+04
-58.268
1.25305e+05
30.857
100
9.77116e+04
3.999 03e+04
-59.073
1.49694e+05
53.200
Evaluate the time response from two concentrated loads. One downward at the middle and one upward at the free end.
input the time step and the maximum time (0.04 and 5.0) are typical. Use 0,0 to stop
? .04,5
Evaluate the time response resulting from a concentrated downward load at the middle and an upward end load.
input the time step and the maximum time (0.04 and 5.0) are typical. Use 0,0 to stop
? 0,0
Program cbfrq
i: f u n c t i o n c b f r e q 2: % Exampl e: c b f r e q
3: %......................................................................
4: % T h i s p r o g r a m comput es a p p r o x i m a t e n a t u r a l 5: % f r e q u e n c i e s o f a u n i f o r m d e p t h c a n t i l e v e r 6: % beam u s i n g f i n i t e d i f f e r e n c e and f i n i t e 7: % e l e me n t me t h o d s. E r r o r r e s u l t s a r e p r e s e n t e d 8: % whi c h d e m o n s t r a t e t h a t t h e f i n i t e e l e me n t 9: % met hod i s much more a c c u r a t e t h a n t h e f i n i t e i o: % d i f f e r e n c e met hod when t h e same m a t r i x o r d e r s i i: % a r e u s e d i n c o m p u t a t i o n of t h e e i g e n v a l u e s.
12: %
i 3: % Us e r m f u n c t i o n s r e q u i r e d:
i 4: % cbf rqnwm, c b f r q f d m, c b f r q f e m, f r u d,
i 5: % exampl mo, beamani m, p l o t s a v e, i n p u t v
i 6:
i 7: c l e a r, f p r i n t f ('\n\n')
i 8: f pr i nt f ('CANTI LEVER BEAM FREQUENCIES BY ') i 9: f p r i n t f ('F I N I T E DIFFERENCE AND')
2 o: f p r i n t f (...
2 i: '\n FINITE ELEMENT APPROXIMATION^')
22:
2 3: f p r i n t f ('\n G i v e t h e number of f r e q u e n c i e s ')
2 4: f p r i n t f ('t o be c o mp u t e d')
2 5: f p r i n t f ('\n ( u s e an e ve n number g r e a t e r ')
2 6: f p r i n t f ('t h a n 2 )\n'), n = i n p u t ('? > ');
2 7: i f r e m ( n,2 ) ~= 0, n=n+1; end 28:
2 9: % E x a c t f r e q u e n c i e s f r o m s o l u t i o n of 30: % t h e f r e q u e n c y e q u a t i o n 3 i: wex = c b f r q n w m ( n,1 e - 1 2 );
32:
33:
34
35
36
37
38
39
40:
4 i
42:
43:
44
45:
46:
47
48:
49
50:
5 i
52:
53:
54
55:
56:
57
58:
59
60:
6 i
62:
63:
64
65:
66:
67
68:
69
70:
7 i
72:
73:
74
75:
76:
77
% F r eque nci es f o r t h e f i n i t e % d i f f e r e n c e s o l u t i o n wfd = cbf rqfdm(n);
% F r e q u e n c i e s, modal v e c t o r s, mass m a t r i x,
% and s t i f f n e s s m a t r i x from t h e f i n i t e % element s o l u t i o n.
n e l t s = n/2; [wfe,mv,mm,kk] = c b f r q f e m ( n e l t s );
pefdm=(wfd-wex)./(.01*wex);
pef em=(wf e-wex)./(.01*wex);
nl i n e s = 1 7; n l o o p = r o u n d ( n/n l i n e s ); v = [ ( 1:n )',w e x,w f d,p e f d m,w f e,p e f e m ]; d i s p (' '), lo=1;
t 1 = [' f r e q. e x a c t. f d i f.' ...
' f d. p c t.'];
t 1 = [ t 1,' f e l t. f e. p c t.'];
t 2=['numbe r f r e q. f r e q.' ...
' e r r o r '];
t 2 = [ t 2,' f r e q. e r r o r '];
whi l e l o < n
d i s p ( t 1 ),d i s p ( t 2 ) h i = m i n ( l o + n l i n e s - 1,n ); f o r j = l o:h i
s 1 = s p r i n t f ('\n %4.0f %13.5e %13.5e', ...
v ( j,1 ),v ( j,2 ),v ( j,3 ) ); s 2 = s p r i n t f (' %9.3f %13.5e % 9.3 f', ...
v ( j,4 ),v ( j,5 ),v ( j,6 ) );
f p r i n t f ( [ s 1,s 2 ] )
end
f p r i n t f ('\n\n P r e s s [Enter] t o c o n t i n u e\n\n'); pause;
l o = l o + n l i n e s;
end
pl ot save(wex,wfd,pefdm,wfe,pefem) n f e = l e n g t h ( w f e ); nmi dl=nfe/2; i f rem(nmidl,2)==0, nmidl=nmidl+1; end x 0 = z e r o s ( n f e,1 ); v0=x0; w=0; f 1 = z e r o s ( n f e,1 ); f 2=f 1; f 1 ( n f e - 1 ) = 1; f 1 ( n m i d l ) = - 5;
xsav=examplmo(mm,kk,f1,f2,x0,v0,wfe,mv); c l o s e; f p r i n t f ('A l l Done\n')
%=============================================
78: f u n c t i o n z = c b f r q n w m ( n,t o l )
7 9: %
8 0: % z = c b f r q n w m ( n,t o l )
8 1: %
8 2: % C a n t i l e v e r beam f r e q u e n c i e s by Ne wt o n's
8 3: % met hod. Ze r o s of
8 4: % f ( z ) = c o s ( z ) + 1/c o s h ( z )
8 5: % a r e comput ed.
8 6: %
8 7: % n - Number o f f r e q u e n c i e s r e q u i r e d
8 8: % t o l - E r r o r t o l e r a n c e f o r t e r m i n a t i n g
8 9: % t h e i t e r a t i o n
9 0: % z - D i m e n s i o n l e s s f r e q u e n c i e s a r e t h e 91: % s q u a r e s of t h e r o o t s of f ( z ) = 0
9 2: %
9 3: % Us e r m f u n c t i o n s c a l l e d: none
9 4: %-----------------------------------------------------------------------------------------
95:
9 6: i f n a r g i n ==1, t o l = 1.e - 5; end
97:
9 8: % Base i n i t i a l e s t i m a t e s on t h e a s y m p t o t i c 99: % f or m of t h e f r e q u e n c y e q u a t i o n 1 0 0: z b e g i n = ( ( 1:n ) -.5 )'* p i; z b e g i n ( 1 ) = 1.8 7 5; b i g = 1 0;
1 0 1:
1 0 2: % S t a r t Newton i t e r a t i o n
1 0 3: w h i l e b i g > t o l
1 0 4: t = e x p ( - z b e g i n ); t t = t.* t;
1 0 5: f = c o s ( z b e g i n ) + 2 * t./( 1 + t t );
1 0 6: f p = - s i n ( z b e g i n ) - 2 * t.* ( 1 - t t )./( 1 + t t ). ~2;
1 0 7: d e l z = - f./f p;
1 0 8: z = z b e g i n + d e l z; b i g = m a x ( a b s ( d e l z ) ); z b e g i n = z;
1 0 9: end 1 1 0: z = z.* z;
1 1 1:
1 1 2: %=============================================
1 1 3:
1 1 4: f u n c t i o n [ w f i n d i f,m a t ] = c b f r q f d m ( n )
1 1 5: %
1 1 6: % [ w f i n d i f,m a t ] = c b f r q f d m ( n )
1 1 7: %
1 1 8: % T h i s f u n c t i o n comput es a p p r o x i m a t e c a n t i l e v e r 119: % beam f r e q u e n c i e s by t h e f i n i t e d i f f e r e n c e 1 2 0: % met hod. The t r u n c a t i o n e r r o r f o r t h e 1 2 1: % d i f f e r e n t i a l e q u a t i o n and b o u n d a r y 1 2 2: % c o n d i t i o n s a r e o f o r d e r h~2.
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
%
% n - Number of f r e q u e n c i e s t o be
% computed
% w f i n d i f - Approximate f r e q u e n c i e s i n
% d i m e n s i o n l e s s form
% mat - Mat ri x havi ng e i g e n v a l u e s which
% a r e t h e s quar e r o o t s of t h e
% f r e q u e n c i e s
%
% User m f u n c t i o n s c a l l e d: none
%-----------------------------------------------------------------------------------------
% Form t h e pri mary p a r t of t h e fr e q u e n c y m a t r i x m a t = 3 * d i a g ( o n e s ( n,1 ) ) - 4 * d i a g ( o n e s ( n - 1,1 ),1 ) +... d i a g ( o n e s ( n - 2,1 ),2 ); mat=(mat+mat');
% Impose l e f t end boundary c o n d i t i o n s % y(0)=0 and y'( 0 ) = 0
m a t ( 1,[ 1:3 ] ) = [ 7,- 4,1 ]; m a t ( 2,[ 1:4 ] ) = [ - 4,6,- 4,1 ];
% Impose r i g h t end boundary c o n d i t i o n s % y''( 1 ) = 0 and y,,,(1)=0 m a t ( n - 1,[ n - 3:n ] ) = [ 1,- 4,5,- 2 ]; m a t ( n,[ n - 2:n ] ) = [ 2,- 4,2 ];
% Compute approximate f r e q u e n c i e s and % s o r t t h e s e v a l u e s w=eig(mat); w=sort(w); h=1/n; w f i n d i f = s q r t ( w )/( h * h );
%=============================================
f u n c t i o n [wfem,modvecs,mm,kk]= ...
c b f r q f e m ( n e l t s,m a s,l e n,e i )
%
% [wfem,modvecs,mm,kk]=
% c b f r q f e m ( n e l t s,m a s,l e n,e i )
%....................................................................................................................
% D e t e r m i n a t i o n of n a t u r a l f r e q u e n c i e s of a % uni form dept h c a n t i l e v e r beam by t h e F i n i t e % Element Method.
%
% n e l t s - number of el ements i n t h e beam
% mas - t o t a l beam mass
% l e n - t o t a l beam l e n g t h
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
% e i - e l a s t i c modulus t i me s moment
% of i n e r t i a
% wfem - d i m e n s i o n l e s s c i r c u l a r f r e q u e n c i e s
% modvecs - modal v e c t o r m a t r i x
% mm,kk - reduced mass and s t i f f n e s s
% m a t r i c e s
%
% User m f u n c t i o n s c a l l e d: none
%-----------------------------------------------------------------------------------------
i f nargin==1, mas=1; len=1; ei =1; end n = n e l t s; l e = l e n/n; me=mas/n; c1=6/l e~2; c 2 = 3/l e; c 3 = 2 * e i/l e;
% element mass m a t r i x masselt=me/420* ...
[ 156, 22*l e, 54, - 1 3 * l e
2 2 * l e, 4*le~2, 13*l e, -3*le~2
54, 13*l e, 156, - 2 2 * l e
- 1 3 * l e, - 3 * l e ~ 2, - 2 2 * l e, 4*l e~2];
% element s t i f f n e s s m a t r i x
c1,
c2,
- c 1,
c2
c2,
2,
- c 2,
1
- c 1,
- c 2,
c1,
-c2
c2,
1,
- c 2,
2]
ndof=2*(n+1); j j = 0:3; mm=zeros(ndof); k k = z e r o s ( n d o f );
% Assemble e q u a t i o n s f o r i = 1:n
j = 2 * i - 1 + j j; m m ( j,j ) = m m ( j,j ) + ma s s e l t; k k ( j,j ) = k k ( j,j ) + s t i f e l t; end
% Remove degr ees of freedom f o r ze ro % d e f l e c t i o n and z e r o s l o p e a t t h e l e f t end. mm=mm(3:ndof,3:ndof); k k = k k ( 3:n d o f,3:n d o f );
% Compute f r e q u e n c i e s i f n a r gout ==1
w f e m = s q r t ( s o r t ( r e a l ( e i g ( m m\k k ) ) ) );
e l s e
[modvecs,wfem]=eig(mm\kk);
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
[ wf em,i d ] = s o r t ( d i a g ( wf e m ) ); wfem=sqrt(wfem); modvecs=modvecs(:,id); end
%=============================================
f u n c t i o n [ t,x ] = ...
f r u d ( m,k,f 1,f 2,w,x 0,v 0,w n,m o d v c,h,t m a x )
%
% [ t,x ] = f r u d ( m,k,f 1,f 2,w,x 0,v 0,w n,m o d v c,h,t m a x )
%....................................................................................................................
% This f u n c t i o n employs modal s u p e r p o s i t i o n
% t o s o l v e %
% m*x'' + k*x = f1*cos(w*t ) + f 2 * s i n ( w * t )
%
% m,k - mass and s t i f f n e s s m a t r i c e s % f 1,f 2 - ampl i tude v e c t o r s f o r t h e f o r c i n g
% f u n c t i o n
% w - f o r c i n g fr equenc y not matching any
% n a t u r a l fr equenc y component i n wn
% wn - v e c t o r of n a t u r a l fr eque nc y v a l u e s % x0,v0 - i n i t i a l di s pl ace me nt and v e l o c i t y
% v e c t o r s
% modvc - m a t r i x wi t h modal v e c t o r s as i t s % columns
% h,tmax - time s t e p and maximum time f o r % e v a l u a t i o n of t h e s o l u t i o n
% t - column of t i me s a t which t h e
% s o l u t i o n i s computed
% x - s o l u t i o n m a t r i x i n which row j
% i s t h e s o l u t i o n v e c t o r a t
% time t ( j )
%
% User m f u n c t i o n s c a l l e d: none
%---------------------------------------------------------------------------
t = 0:h:t m a x; n t = l e n g t h ( t ); n x = l e n g t h ( x 0 ); wn=wn(:); wnt=wn*t;
% E val ua t e t h e p a r t i c u l a r s o l u t i o n. x12=( k- ( w*w) *m)\[ f 1,f 2]; x 1 = x 1 2 (:,1 ); x 2 = x 1 2 (:,2 ); xp=x1*cos(w*t)+x2*sin(w*t);
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
% E val ua t e t h e homogeneous s o l u t i o n. cof=modvc\[x0-x1,v0-w*x2]; c 1 = c o f (:,1 )'; c 2 = ( c o f (:,2 )./w n )'; x h = ( m o d v c.* c 1 ( o n e s ( 1,n x ),:) ) * c o s ( w n t ) +... ( m o d v c.* c 2 ( o n e s ( 1,n x ),:) ) * s i n ( w n t );
% Combine t h e p a r t i c u l a r and % homogeneous s o l u t i o n s. t = t (:); x=(xp+xh)';
%=============================================
f u n c t i o n x=examplmo(mm,kk,f1,f2,x0,v0,wfe,mv)
%
% x=examplmo(mm,kk,f1,f2,x0,v0,wfe,mv)
%.............................................................................................
% E val ua t e t h e r e s p o n s e caused when a downward % l o a d a t t h e middle and an upward l o a d a t t h e % f r e e end i s a p p l i e d.
%
% mm, kk - mass and s t i f f n e s s m a t r i c e s % f 1, f 2 - f o r c i n g f u n c t i o n magnitudes
% x0, v0 - i n i t i a l p o s i t i o n and v e l o c i t y
% wfe - f o r c i n g f u n c t i o n fr equenc y
% mv - m a t r i x of modal v e c t o r s
%
% User m f u n c t i o n s c a l l e d: f r u d, beamanim, i n p u t v
%-----------------------------------------------------------------------------------------
w=0; n = l e n g t h ( x 0 ); t0=0; x = [ ]; s 1 = ['\n E v a l u a t e t h e t ime r e s p o n s e from t w o',... '\n c o n c e n t r a t e d l o a d s. One downward a t t h e',... '\n m i d d l e and one upward a t t h e f r e e e n d.']; whi l e 1
f p r i n t f ( s 1 ), f p r i n t f ('\n\n') f p r i n t f ('I n p u t t h e time s t e p and ') f p r i n t f ('t h e maximum t ime ') f p r i n t f ('\n ( 0.0 4 and 5.0 ) a r e t y p i c a l.') f p r i n t f (' Use 0,0 t o s t o p\n')
[ h,t ma x]=i nput v;
i f norm([h,tmax])==0 | i s n a n ( h ), r e t u r n, end d i s p (' ')
[ t,x ] = ...
f r u d ( m m,k k,f 1,f 2,w,x 0,v 0,w f e,m v,h,t m a x );
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
x = x (:,1:2:n - 1 ); x = [ z e r o s ( l e n g t h ( t ),1 ),x ]; [ n t,n c ] = s i z e ( x ); h d i s t = l i n s p a c e ( 0,1,n c );
c l f, p l o t ( t,x (:,n c ),'k -')
t i t l e ('P o s i t i o n of t h e Free End of t h e Beam') x l a b e l ('d i m e n s i o n l e s s t i m e') y l a b e l ('e n d d e f l e c t i o n'), f i g u r e ( g c f ) d i s p ('P r e s s [Enter] f o r a s u r f a c e p l o t o f') d i s p ('t r a n s v e r s e d e f l e c t i o n v e r s u s x and t') pause
p r i n t -deps endpos1
x c = l i n s p a c e ( 0,1,n c ); zmax=1.2*max( a bs ( x(:) ) );
c l f, s u r f ( x c,t,x ), view(30,35) colormap([1 1 1 ] ) a x i s ( [ 0,1,0,t m a x,- z m a x,z m a x ] ) x l a b e l ('x a x i s'); y l a b e l ('t i m e') z l a b e l ('d e f l e c t i o n')
t i t l e ( ['C a n t i l e v e r Beam D e f l e c t i o n ' ...
'f o r V a r y i n g P o s i t i o n and T i m e'] ) f i g u r e ( g c f ); p r i n t - d e p s e ndpos 2
d i s p (' '), d i s p ( ['P r e s s [ E n t e r ] t o a n i m a t e',... ' t h e beam m o t i o n'] )
p a u s e
t i t l ='C a n t i l e v e r Beam A n i m a t i o n'; x l a b ='x a x i s'; y l a b ='d i s p l a c e m e n t'; b e a m a n i m ( h d i s t,x,0.1,t i t l,x l a b,y l a b ), c l o s e end
%=============================================
% f u n c t i o n b e a m a n i m ( x,u,t p a u s e,t i t l,x l a b l,y l a b l )
% See Appe ndi x B
%=============================================
f u n c t i o n p l o t s a v e ( w e x,w f d,p e f d,w f e,p e f e m )
%
% f u n c t i o n p l o t s a v e ( w e x,w f d,p e f d,w f e,p e f e m )
%..........................................................................................................
% T h i s f u n c t i o n p l o t s e r r o r s i n f r e q u e n c i e s % comput ed by two a p p r o x i m a t e me t h o d s.
%
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
% wex - e x a c t f r e q u e n c i e s
% wfd - f i n i t e d i f f e r e n c e f r e q u e n c i e s
% wfe - f i n i t e element f r e q u e n c i e s
% pef d,pef em - p e r c e n t e r r o r s by bot h methods
%
% User m f u n c t i o n s c a l l e d: none
%-----------------------------------------------------------------------------------------
% p l o t r e s u l t s comparing accuracy
% of bot h fr equenc y methods
w = [ w e x (:);w f d (:);w f d ];
wmin=min(w); wmax=max(w);
n=l engt h(wex); wht=wmin+.001*(wmax-wmin);
j = 1:n;
s e m i l o g y ( j,w e x,'k -',j,w f e,'k —',j,w f d,'k:') t i t l e ('C a n t i l e v e r Beam F r e q u e n c i e s') x l a b e l ('f r e q u e n c y number') y l a b e l ('f r e q u e n c y v a l u e s') l e g e n d ('E x a c t f r e q.','F e l t. f r e q.', ...
'F d i f. f r e q.',2 ); f i g u r e ( g c f ) d i s p ( ['P r e s s [Enter] f o r a fr equenc y ',...
'e r r o r p l o t'] ), p a u s e p r i n t - d e p s b e a m f r q 1
p l o t ( j,a b s ( p e f d ),'k —',j,a b s ( p e f e m ),'k -') t i t l e ( ['C a n t i l e v e r B e a m F r e q u e n c y ' ...
'E r r o r P e r c e n t a g e s'] ) x l a b e l ('f r e q u e n c y n u m b e r') y l a b e l ('p e r c e n t f r e q u e n c y e r r o r') l e g e n d ('F d i f. p c t. e r r o r','F e l t. p c t. e r r o r',4 ) f i g u r e ( g c f )
d i s p ( ['P r e s s [ E n t e r ] f o r a t r a n s i e n t ',...
'r e s p o n s e c a l c u l a t i o n'] )
p a u s e
p r i n t - d e p s b e a m f r q 2 % = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
% f u n c t i o n v a r a r g o u t = i n p u t v ( p r o m p t )
% S e e A p p e n d i x B
10.7 Vibration Modes of an Elliptic Membrane
10.7.1 Analytical Formulation
Examples using eigenvalues and modal functions of rectangular or circular mem­
branes were presented in chapter 9. In this section we analyze modal vibrations of an elliptic membrane. In this case the natural frequencies and modal functions can­
not be obtained easily in explicit form. The problem can be formulated in elliptical coordinates leading to Mathieu type differential equations [74]. Library routines to compute these functions are not widely available; so, a different approach is em­
ployed using least squares approximation and the MATLAB function eig. Consider a membrane with major and minor semi-diameters a and b. The analytic function ,ε = h cosh(s) where h = %/o2 — b2 and ζ = ξ + i η maps the rectangle defined by 0 < ξ < R = tanh_1(6/a), —π < η < π onto the interior of the ellipse. This transformation takes lines of constant ξ into a system of confocal ellipses and lines of constant η into hyperbolas intersecting the ellipses orthogonally. The following function was used to produce the elliptic coordinate plot in
Figure 10.13.
f u n c t i o n z = e l i p m a p ( a,b,n e t a,n x i ) h = s q r t ( a ~ 2 - b ~ 2 ); R = a t a n h ( b/a );
[ x i,e t a ] = m e s h g r i d (...
l i n s p a c e ( 0,R,n x i ),l i n s p a c e ( - p i,p i,n e t a ) ); z = h * c o s h ( x i + i * e t a ); x = r e a l ( z ); y = i ma g ( z ); p l o t ( x,y,'k',x',y','k') t i t l e ('E L L I P T I C AL COORDINATE SYSTEM') x l a b e l ('x a x i s'), y l a b e l ('y a x i s') a x i s e q u a l, g r i d o f f, shg
Transforming the wave equation to (ξ, η) coordinates gives
h2
υ ξ ξ + U v v = ^ [ c o s h ( 2£) - c o s ( 2??)] U t t,
and assuming separable solutions of the form
U = f (η)β(ξ) sin(Qi)
leads to
7(^ί + = ~ X tcosh^2^ “ cos(2i?)]’
where Λ = Ω2 h2/2. So f and g are found to satisfy the following two Mathieu type differential equations:
f "(η) + [α — Λc o s ^ ) ] f (η) = 0, —π < η < π
ELLIPTICAL COORDINATE SYSTEM
x axis
Figure 10.13: Elliptic Coordinate Grid
and
9"(ξ) -
[a - λ cosh(2£)]g(£) = 0, 0 < ξ < R
wher e t he ei genval ue par amet er s a and λ are determined to make f (η) have period 2π and make 9 (ξ) vanish at ξ = R. The modal functions can be written in terms of Mathieu functions as products of the form
ce(η, q)Ce(^,q)
for modes symmetric about the x-axis and
se(v,q)Se(£,q)
for modes anti-symmetric about the x-axis. The functions ce and se are periodic Mathieu functions pertaining to the circumferential direction, while Ce and Se are modified Mathieu functions pertaining to the radial direction. The structure of these functions motivates using the following series approximation for the functions for even modes:
N M ξ
f(v) = X]cos(i7(k - 1 ) ) ak, g(£) = ^ c o s ( ^ - ( Z - 1/2)) 6,.
k=1 l=1
The analogous approximations for the modes anti-symmetric about the x-axis are:
N M ξ
f(v) = X^sin(?7k ) ak, g(£) = ^ sin( ^ r 0 h-
k= 1 l= 1
Thus the expressions for both cases take the form:
N M
f (η) = Σ fk(rj) ak and g(£) = J 2 gi ( 0 bi ■
k=1 l=1
Let us choose a set of collocation points η i, i = l,...,n, and ξ^, j = l,...,m. Then substituting the series approximation for f (η) into the differential equation gives the following over-determined system of equations:
N N N
Y j k Mak + a ^ f k (ni)ak — λ c o s ^ i ) ^ fk (ηi)ak = 0, i = l,...,n.
k=1 k=1 k=1
Denote F as the matrix having f ) as the element in row i and column k. Then multiplying the last equation on the left by the generalized inverse of F gives a matrix equation of the form
C A + α A - ADA = 0,
where A is a column matrix consisting of the coefficients a k. A similar equation results when the series for g(£) is substituted into the differential equation for the radial direction. It reduces to
E B — aB + AGB = 0.
The parameter α can be eliminated from the last two equations to yield a single eigenvalue equation
W E' + C W = λ ( - W G' + D W )
where W = A B', and the tic mark indicates matrix transposition. By addressing the two-dimensional array W in terms of a single index, the eigenvalues λ and the modal multipliers defined by W can be computed using the function eig. Then the values of the other eigenvalue parameter α can also be obtained using the known λ, W combinations. The mathematical developments just given are implemented below in a program which animates the various natural frequency vibration modes for an elliptic membrane.
10.7.2 Computer Formulation
The program elipfreq was written to compute frequencies and mode shapes for an elliptic membrane. The primary data input includes the ellipse semi-diameters, a flag indicating whether even modes, odd modes, or both are desired, the number of
least squares points used, and the number of terms used in the approximation series. Natural frequencies and data needed to produce modal surfaces are returned. The program also animates the various mode shapes arranged in the order of increasing frequency. The modules employed are described in the following table.
elipfreq
reads data, calls other computational mod­
ules, and outputs modal plots
frqsimpl
forms the matrix approximations of the Math­
ieu equations and calls eigenrec to generate
frequencies and mode shapes
eigenrec
solves the rectangular eigenvalue problem
plotmode
generates animated plots of the modal func­
tions
modeshap
computes modal function shapes using the
approximating function series
funcxi
approximating series functions in the xi vari­
able
funceta
approximating series functions in the eta vari­
able
The accuracy of the formulation developed above was assessed by 1) comparison with circular membrane frequencies known in terms of Bessel function roots and 2) results obtained from the commercial PDE toolbox from MathWorks employing triangular finite element analysis. The elliptic coordinate formulation is singular for a circular shape, but a nearly circular shape with a = 1 and b = 0.9999 causes no numerical difficulty.
Figure 10.14 shows how well frequencies from elipfreq with nlsq=[200,200] and nfuns=[30,30] compare with the roots of J n(r). The first fifty frequencies were accurate to within 0.8 percent and the first one hundred frequencies were accurate to within 5 percent. The function pdetool from the PDE toolbox was also used to compute circular membrane frequencies with a quarter circular shape and 2233 node points. The first two hundred even mode frequencies from this model were accurate to within 1 percent for the first one hundred frequencies and to within 7 percent for the first 200 frequencies. Since the function pdetool would probably give comparable accuracy for an elliptic membrane, results from elipfreq were compared with those from pdetool using an ellipse with a = 1 and b = 0.5. The percent difference between the frequencies from the two methods appears in
Figure 10.15
. This comparison suggests that the first fifty frequencies produced by elipfreq for the elliptic membrane are probably accurate to within about 2 percent.
The various modal surfaces of an elliptic membrane have interesting shapes. The program elipfreq allows a sequence of modes to be exhibited by selecting vectors of frequency numbers such as 1:10or 10:2:20. Two typical shapes are shown in
Figures
10.16 and
10.17. The particular modes shown have no special significance besides their esthetic appeal. A listing of some interactive computer output and the source code for elipfreq follows.
Frequency Number
Figure 10.14: Comparing Elipfreq Results with Bessel Function Roots
COMPARISON OF RESULTS FROM ELIPFREQ AND PDETOOL
frequency number
Figure 10.15: Comparing Elipfreq Results with PDE Toolbox
(A‘x)n
ODD MODE 98, OMEGA = 43.85, B/A = 0.5
1
0.8
0.6
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1
0.5
y axis
-0.5 -1
Figure 10.16: Surface for Anti-Symmetric Mode Number 98
u(x,y)
EVEN MODE 99, OMEGA = 41.37, B/A = 0.5
1
0.8
0.6
0.4
0.2
0
-0.4
-0.6
-0.8
-0.5 -1
y axis
Figure 10.17: Surface for Symmetric Mode Number 99
x axis
>> e l i p f r e q;
VIBRATION MODE SHAPES AND FREQUENCIES OF AN ELLIPTIC MEMBRANE
Input the major and minor semi -di amet ers > ? 1,.5
S e l e c t t he modal form opt i on 1<=>even, 2<=>odd, 3<=>both > ? 1
The computation t akes awhile. Please w a i t.
Computation time = 44.1 seconds.
Number of modes = 312 Highest frequency = 116.979
Press r e t u r n t o see modal p l o t s.
Give a v e c t o r of mode i n d i c e s ( t r y 10:2:20) e n t e r 0 t o st op > ? 1
Give a v e c t o r of mode i n d i c e s ( t r y 10:2:20) e n t e r 0 t o st op > ? 2:6
Give a v e c t o r of mode i n d i c e s ( t r y 10:2:20) e n t e r 0 t o st op > ? [20 25 30]
Give a v e c t o r of mode i n d i c e s ( t r y 10:2:20) e n t e r 0 t o st op > ? 0 >>
Elliptic Membrane Program
i: f u n c t i o n [ f r q s,m o d e s,i n d x,x,y,a l p h a,c p t i m ] = e l i p f r e q (... 2: a,b,t y p e,n l s q,n f u n s,n o p l o t )
3: % [ f r q s,m o d e s,i n d x,x,y,a l p h a,c p t i m ] = e l i p f r e q (...
4: % a,b,t y p e,n l s q,n f u n s,n o p l o t )
5: %...........................................................................................................................................................................................................................................
6: % T h i s f u n c t i o n comput es n a t u r a l f r e q u e n c i e s and mode 7: % s h a p e s f o r an e l l i p t i c a l membrane. Modes t h a t a r e 8: % s y m m e t r i c a l o r a n t i - s y m m e t r i c a l a b o u t t h e x a x i s a r e 9: % i n c l u d e d. An a p p r o x i m a t e s o l u t i o n i s o b t a i n e d u s i n g
Interactive Input-Output for Program elipfreq
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
35
36
37
38
39
40:
41:
42
43
44
45
46
47
48
49
50:
51:
52
53:
54
% a s e p a r a t i o n of v a r i a b l e s f o r m u l a t i o n i n e l l i p t i c a l o c o o r d i n a t e s.
a,b - t h e e l l i p s e major and minor semi-
% d i a m e t e r s al ong t h e x and y axes
% n l s q - two-component v e c t o r g i v i n g t h e number
% of l e a s t s quar e p o i n t s i n t h e e t a and
% x i d i r e c t i o n s
% nfuns - two-component v e c t o r g i v i n g t h e number of
% f u n c t i o n s used t o s o l v e t h e d i f f e r e n t i a l
% e q u a t i o n s f o r t h e e t a and x i d i r e c t i o n s.
% t ype - use 1 f o r even modes symmetric about t h e
% x - a x i s. Use 2 f o r odd modes a n t i -
% symmetric about t h e x - a x i s. Use 3 t o
% combine bo t h even and odd modes.
% f r q s - a v e c t o r of n a t u r a l f r e q u e n c i e s
% a r r a n g e d i n i n c r e a s i n g o r d e r.
% modes - a t h r e e di mensi onal a r r a y i n which
% m o d e s (:,:,j ) d e f i n e s t h e modal
% d e f l e c t i o n s u r f a c e f o r f r equency
f r q s ( j ).
% indx - a v e c t o r t e l l i n g whether each
% mode i s even (1) or odd (2)
x,y - c u r v i l i n e a r c o o r d i n a t e a r r a y s of
% p o i n t s i n t h e membrane where modal
f u n c t i o n v a l u e s a r e computed.
% a l p h a - a v e c t o r of e i g e n v a l u e par a m e t e r s i n
t h e Mathieu e q u a t i o n: u''( e t a ) +... ( a l p h a - l a m b d a * c o s ( 2 * e t a ) ) * u ( e t a ) = 0 where lambda=(h*freq)~2/2 and h = a t a n h ( b/a ) cptim - t h e cpu ti me i n seconds used t o
% form t h e e q u a t i o n s and s o l v e f o r
% e i g e n v a l u e s and e i g e n v e c t o r s
n o p l o t - e n t e r any v a l u e t o s k i p mode p l o t s
% User m f u n c t i o n s c a l l e d:
f r q s i m p l e i g e n r e c plotmode modeshap f u n c x i f u n c e t a
i f nargin==0 d i s p (' ')
disp('VIBRATION MODE SHAPES AND FREQUENCIES') d i s p (' OF AN ELLIPTIC MEMBRANE ')
55
56
57:
58
59
60:
61:
62
63:
64
65
66
67:
68
69
70:
71:
72
73
74
75
76
77
78
79
80:
81:
82
83
84
85
86
87
88
89
90:
91:
92
93:
94
95
96
97:
98
99
d i s p (' ')
n l s q = [ 3 0 0,3 0 0 ]; n f u n s = [ 2 5,2 5 ];
v = i n p u t ( ['I n p u t t h e major and minor ',...
's e m i - d i a m e t e r s > ? '],'s'); v = e v a l ( ['[',v,']'] ); a = v ( 1 ); b = v ( 2 ); d i s p (' ') d i s p ('S e l e c t t h e modal f or m o p t i o n') t y p e = i n p u t (...
'1 <=>e v e n, 2<=>odd, 3<=>bot h > ? '); d i s p (' ')
d i s p ( ['T h e c o m p u t a t i o n t a k e s a w h i l e.',...
' PLEASE WAI T.'] )
end
i f t y p e ==1 | t ype ==2 % Even o r odd modes [ f r q s,m o d e s,x,y,a l p h a,c p t i m ] = f r q s i m p l (... a,b,t y p e,n l s q,n f u n s );
i n d x = o n e s ( l e n g t h ( f r q s ),1 ) * t y p e; e l s e % Bot h modes
[ f r q s,m o d e s,x,y,a l p h a,c p t i m ] = f r q s i m p l (... a,b,1,n l s q,n f u n s );
i n d x = o n e s ( l e n g t h ( f r q s ),1 ); [ f r q s o,m o d e s o,x,y,a l p h a o,c p t o ] = f r q s i m p l (... a,b,2,n l s q,n f u n s );
f r q s = [ f r q s;f r q s o ]; a l p h a = [ a l p h a;a l p h a o ]; mo d e s = c a t ( 3,mo d e s,mo d e s o );
i n d x = [ i n d x;2 * o n e s ( l e n g t h ( f r q s o ),1 ) ]; [ f r q s,k ] = s o r t ( f r q s ); m o d e s = m o d e s (:,:,k ); i n d x = i n d x ( k ); c p t i m = c p t i m + c p t o;
end
i f n a r g i n = = 6, r e t u r n, end
% P l o t a s e q u e n c e of modal f u n c t i o n s n e i g = l e n g t h ( f r q s );
d i s p (' '), d i s p ( ['C o m p u t a t i o n t i m e = ',...
n u m 2 s t r ( s u m ( c p t i m ) ),' s e c o n d s.'] ) d i s p ( ['N u m b e r o f m o d e s = ',n u m 2 s t r ( n e i g ) ] ); d i s p ( ['H i g h e s t f r e q u e n c y = ',...
n u m 2 s t r ( f r q s ( e n d ) ) ] ), d i s p (' ') d i s p ('P r e s s r e t u r n t o s e e m o d a l p l o t s.') p a u s e, p l o t m o d e ( a,b,x,y,f r q s,m o d e s,i n d x )
%
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
f u n c t i o n [ f r q s,M o d e s,x,y,a l p h a,c p t i m ] = f r q s i m p l (...
a,b,t y p e,n l s q,n f u n s ) % [ f r q s,M o d e s,x,y,a l p h a,c p t i m ] = f r q s i m p l (...
% a,b,t y p e,n l s q,n f u n s )
%....................................................................................................................................
% a,b - e l l i p s e major and minor s e m i - d i amet er s % t ype - numeri cal v a l u e s of one or two f o r modes % symmetric or a n t i - s y m m e t r i c about t h e x a x i s
% n l s q - v e c t o r [ n e t a,n x i ] g i v i n g t h e number of l e a s t % s quar e p o i n t s used f o r t h e e t a and x i
% d i r e c t i o n s
% nfuns - v e c t o r [meta,mxi] g i v i n g t h e number of % appr oxima ti ng f u n c t i o n s used f o r t h e e t a and
% x i d i r e c t i o n s
% f r q s - n a t u r a l f r e q u e n c i e s a r r a n g e d i n i n c r e a s i n g % o r d e r
% Modes - modal s u r f a c e shapes i n t h e e l l i p s e % x,y - c o o r d i n a t e p o i n t s i n t h e e l l i p s e % a l p h a - v e c t o r of v a l u e s f o r t h e e i g e n v a l u e s i n t h e % Mathieu d i f f e r e n t i a l e q u a t i o n:
% u''( e t a ) + ( a l p h a - l a m b d a * c o s ( 2 * e t a ) ) * u ( e t a ) = 0
% cptim - v e c t o r of computation t i mes %
% User m f u n c t i o n s c a l l e d: f u n c e t a f u n c x i % e i g e n r e c modeshap
i f nargin==0
a=cos h( 2); b = s i n h ( 2 ); type=1;
n l s q = [ 2 0 0,2 0 0 ]; n f u n s = [ 3 0,3 0 ]; end
h = s q r t ( a ~ 2 - b ~ 2 ); R = a t a n h ( b/a ); n e t a = n l s q ( 1 ); a l p h a = [ ]; n x i = n l s q ( 2 ); meta=nf uns(1); mxi =nfuns(2); e t a = l i n s p a c e ( 0,p i,n e t a )'; x i = l i n s p a c e ( 0,R,n x i )'; [ X i,E t a ] = m e s h g r i d ( x i,e t a ); z=h*cosh(Xi +i *Et a); x = r e a l ( z ); y=imag(z); c p t i m = z e r o s ( 1,3 );
% Form t h e Mathieu e q u a t i o n f o r t h e c i r c u m f e r e n t i a l % d i r e c t i o n a s: A*E+alpha*E-lambda*B*E=0 t i c; [ V e t a,A ] = f u n c e t a ( m e t a,t y p e,e t a ); A = V e t a\[ A,r e p m a t ( c o s ( 2 * e t a ),1,m e t a ).* V e t a ]; B=A(:,meta+1:end); A=A(:,1:met a);
% Form t h e modi fi ed Mathieu e q u a t i o n f o r t h e r a d i a l % d i r e c t i o n a s: P*F-alpha*F+lambda*Q*F=0
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
[ V x i,P ] = f u n c x i ( a,b,m x i,t y p e,x i ); P = V x i\[ P,r e p m a t ( c o s h ( 2 * x i ),1,m x i ).* V x i ]; Q=P(:,mxi+1:end); P = P (:,1:m x i ); c p t i m ( 1 ) = t o c; t i c
% Solve t h e e i g e n v a l u e problem. This t a k e s most % of t h e computation time [ f r q s,m o d e s ] = e i g e n r e c ( P',A,- Q',B );
% Keep only h a l f of t h e modes and f r e q u e n c i e s n m a x = f i x ( l e n g t h ( f r q s )/2 ); f r q s = f r q s ( 1:n m a x ); modes=modes(:,:,1:nmax); cp t i m ( 2 ) = t o c;
% Compute v a l u e s of t h e second ei g e n v a l u e % par amet er i n M a t h i e u's e q u a t i o n al pha= zer os( 1,nma x); t i c; s =s i ze ( mode s ); s = s ( 1:2 ); Vxi=Vxi';
% Obtain t h e modal s u r f a c e shapes Neta=91; Nxi=25; Modes=zeros(Neta,Nxi,nmax); f o r k=1:nmax
Mk=modes(:,:,k); [dmk,K]=max(abs(Mk(:))); [ I,J ] = i n d 2 s u b ( s,K ); E j =Mk (:,J); a l p h a ( k ) = ( B ( I,:) * E j * f r q s ( k ) - A ( I,:) * E j )/M k ( K ); [ M o d e s (:,:,k ),x,y ] = m o d e s h a p ( a,b,t y p e,M k,N x i,N e t a ); end
f r q s = s q r t ( 2 * f r q s )/h; cpt i m ( 3 ) = t o c; %==============================================
f u n c t i o n [eigs,vecs,Amat,Bmat ]=ei genrec(A,B,C,D)
% [eigs,vecs,Amat,Bmat ]=ei genrec(A,B,C,D)
% Solve a r e c t a n g u l a r e i g e n v a l u e problem of t h e % form: X*A+B*X=lambda*(X*C+D*X)
%
% A,B,C,D - s quar e m a t r i c e s d e f i n i n g t h e problem.
% A and C have t h e same s i z e. B and D
% have t h e same s i z e.
% e i g s - v e c t o r of e i g e n v a l u e s
% vecs - a r r a y of e i g e n v e c t o r s where v e c s (:,:,j )
% c o n t a i n s t h e r e c t a n g u l a r e i g e n v e c t o r
% f o r ei g e n v a l u e e i g s ( j )
% Amat,
% Bmat - m a t r i c e s t h a t e x p r e s s t h e ei g e n v a l u e
% problem as Amat*V=lambda*Bmat*V
%
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
n = s i z e ( B,1 ); m=size(A,2); s=[n,m]; N=n*m; Amat=zeros(N,N); Bmat=Amat; kn=1:n; km=1:m; f o r i = 1:n
I K = s u b 2 i n d ( s,i * o n e s ( 1,m ),k m );
Bi kn=B( i,kn); Di kn=D(i,kn); f o r j=1:m
I = s u b 2 i n d ( s,i,j );
Am at ( I,I K ) =A( k m,j )'; B m a t ( I,I K ) = C ( k m,j )'; K J = s u b 2 i n d ( s,k n,j * o n e s ( 1,n ) ); Amat(I,KJ)=Amat(I,KJ)+ Bikn; Bmat(I,KJ)=Bmat(I,KJ)+ Dikn; end
end
[ v e cs,e i gs ] =ei g( B mat\Amat );
[ e i g s,k ] = s o r t ( d i a g ( e i g s ) );
v e c s = r e s h a p e ( v e c s (:,k ),n,m,N );
%===========================================
f u n c t i o n p l o t m o d e ( a,b,x,y,e i g s,m o d e s,i n d x )
%
% p l o t d m o d e ( a,b,x,y,e i g s,m o d e s,i n d x )
%.....................................................................................
% This f u n c t i o n makes animated p l o t s of t h e % mode shapes of an e l l i p t i c membrane f o r % v a r i o u s f r e q u e n c i e s
% a,b - major and minor s emi - d i a m e t e r s
% x,y - a r r a y s of p o i n t s d e f i n i n g t h e
% c u r v i l i n e a r c o o r d i n a t e g r i d
% e i g s - v e c t o r of s o r t e d f r e q u e n c i e s
% modes - a r r a y of modal s u r f a c e s f o r
% t h e c or r e s p o n d i n g f r e q u e n c i e s
% indx - v e c t o r of i n d i c e s d e s i g n a t i n g
% each mode as even (1) or odd (2)
r a n g e = [ - a,a,- b,b,- a,a ]; nf=25; f t = c o s ( l i n s p a c e ( 0,4 * p i,n f ) ); b o a = [', B/A = ',n u m 2 s t r ( b/a,4 ) ]; whi l e 1
j l i m = [ ];
whi l e i s e m p t y ( j l i m ), d i s p (' ')
d i s p ( ['G i v e a v e c t o r of mode ',...
'i n d i c e s ( t r y 1 0:2:2 0 ) > ? '] ); j l i m = i n p u t ('( i n p u t 0 t o s t o p > ? '); end
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
i f any(jlim==0)
d i s p (' '), d i s p ('A l l d o n e'), b r e a k, end f o r j = j l i m
i f i n d x ( j ) = = 1, type='EVEN'; f=1; e l s e, t y p e ='ODD '; f = - 1; end u = a/2 * m o d e s (:,:,j );
f o r kk=1:nf
s u r f ( x,y,f t ( k k ) * u ) a x i s e q u a l, a x i s ( r a n g e ) x l a b e l ('x a x i s'), y l a b e l ('y a x i s') z l a b e l ('u ( x,y )')
t i t l e ( [ t y p e,' MODE ',n u m 2 s t r ( j ),...
', OMEGA = ',n u m 2 s t r ( e i g s ( j ),4 ),b o a ] ) %colormap([127/255 1 212/255]) colormap([1 1 0 ] ) drawnow, s hg
end
p a u s e ( 1 );
end
end
%==================================================
f u n c t i o n [ u,x,y ] = m o d e s h a p (...
a,b,t y p e,m o d e m a t,n x i,n e t a,H )
%
% [ u,x,y ] = m o d e s h a p ( a,b,t y p e,m o d e m a t,n x i,n e t a,H )
%..................................................................................................................
% T h i s f u n c t i o n u s e s t h e e i g e n v e c t o r s p r o d u c e d by % t h e r e c t a n g u l a r e i g e n v a l u e s o l v e r t o f or m modal % s u r f a c e s h a p e s i n c a r t e s i a n c o o r d i n a t e s.
% a,b - ma j o r and mi n o r s e m i - d i a m e t e r s
% t y p e - 1 f o r e v e n, 2 f o r odd % modemat - e i g e n v e c t o r m a t r i x o u t p u t by e i g e n r e c % n x i,n e t a - number o f r a d i a l and c i r c u m f e r e n t i a l % c o o r d i n a t e v a l u e s
% H - maximum h e i g h t o f t h e modal s u r f a c e s.
% The d e f a u l t v a l u e i s o ne.
% u,x,y - modal s u r f a c e a r r a y a nd c o r r e s p o n d i n g % c a r t e s i a n c o o r d i n a t e m a t r i c e s. u (:,:j )
% g i v e s t h e m o d a l s u r f a c e f o r t h e j't h
% n a t u r a l f r e q u e n c y.
i f n a r g i n < 7, H = 1; e n d
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
i f nar gi n< 6, neta=81; end; i f nar gi n< 5, nxi=22; end h = s q r t ( a ~ 2 - b ~ 2 ); r = a t a n h ( b/a ); x = [ ]; y = [ ]; x i = l i n s p a c e ( 0,r,n x i ); e t a = l i n s p a c e ( - p i,p i,n e t a ); i f nargout>1
[ X i,E t a ] = m e s h g r i d ( x i,e t a ); z=h*cosh(Xi +i *Et a); x = r e a l ( z ); y=imag(z); end
[Neta,Nxi]=size(modemat);
m a t e t a = f u n c e t a ( N e t a,t y p e,e t a );
m a t x i = f u n c x i ( a,b,N x i,t y p e,x i );
u=mateta*modemat*matxi'; [ u max,k ] =max ( ab s ( u (:) ) ); u=H/u(k)*u;
%==================================================
f u n c t i o n [ f,f 2 ] = f u n c x i ( a,b,n,t y p e,x i )
%
% [ f,f 2 ] = f u n c x i ( a,b,n,t y p e,x i )
%.....................................................................
% This f u n c t i o n d e f i n e s t h e appr oxima ti ng f u n c t i o n s % f o r t h e r a d i a l d i r e c t i o n
% a,b - e l l i p s e major and minor h a l f - d i a m e t e r s % n - number of s e r i e s terms used
% t ype - 1 f o r even v a l u e d, 2 f o r odd v a l ued
% x i - v e c t o r of r a d i a l c o o r d i n a t e v a l u e s
% f,f 2 - m a t r i x of f u n c t i o n and s e c o n d d e r i v a t i v e
% v a l u e s
x i = x i (:); n x i = l e n g t h ( x i ); R = a t a n h ( b/a ); i f t y p e = = 1, N = p i/R * ( 1/2:n ); f = c o s ( x i * N ); e l s e, N = p i/R * ( 1:n ); f = s i n ( x i * N ); end f 2 = - r e p m a t ( N.~ 2,n x i,1 ).* f;
%==================================================
f u n c t i o n [ f,f 2 ] = f u n c e t a ( n,t y p e,e t a )
%
% [ f,f 2 ] = f u n c e t a ( n,t y p e,e t a )
%................................................................
% T h i s f u n c t i o n d e f i n e s t h e a p p r o x i m a t i n g f u n c t i o n s % f o r t h e c i r c u m f e r e n t i a l d i r e c t i o n % n - number of s e r i e s t e r m s u s e d
% t y p e - 1 f o r e v e n v a l u e d, 2 f o r odd v a l u e d
% x i - v e c t o r of c i r c u m f e r e n t i a l c o o r d i n a t e v a l u e s
% f,f 2 - m a t r i x of f u n c t i o n and s e c o n d d e r i v a t i v e
325
326
327
328
329
330
% v a l u e s
e t a = e t a (:); n e t a = l e n g t h ( e t a ); i f type==1, N=0:n-1; f= c o s ( e t a * N ); e l s e, N=1:n; f = s i n ( e t a * N ); end f 2 = - r e p m a t ( N.~ 2,n e t a,1 ).* f;
Chapiter 11
Bending Analysis of Beams of General Cross Section
11.1 Introduction
Elastic beams are important components in many types of structures. Conse­
quently methods to analyze the shear, moment, slope, and deflection in beams with complex loading and general cross section variation are of significant interest. A typical beam of the type considered is shown in
Figure 11.1
. The study of Euler beam theory is generally regarded as an elementary topic dealt with in undergradu­
ate engineering courses. However, simple analyses presented in standard textbooks usually do not reveal difficulties encountered with statically indeterminate problems and general geometries [115]. Finite element approximations intended to handle ar­
bitrary problems typically assume a piecewise constant depth profile and a piecewise cubic transverse deflection curve. This contradicts even simple instances such as a constant depth beam subjected to a linearly varying distributed load which actually leads to a deflection curve which is a fifth order polynomial. Exact solutions of more involved problems where the beam depth changes linearly, for example, are more complicated. Therefore, an exact analysis of the beam problem is desirable to handle depth variation, a combination of concentrated and distributed loads, and static inde­
terminacy providing for general end conditions and multiple in-span supports. The current formulation considers a beam carrying any number of concentrated loads and linearly varying distributed loads. The equations for the shear and moment in the beam are obtained explicitly. Expressions for slope and deflection are formulated for evaluation by numerical integration allowing as many integration steps as neces­
sary to achieve high accuracy. A set of simultaneous equations imposing desired constraints at the beam ends and at supports is solved for support reactions and any unknown end conditions. Knowledge of these quantities then allows evaluation of internal load and deformation quantities throughout the beam. The analytical formu­
lation is implemented in a program using a concise problem definition specifying all loading, geometry, and constraint conditions without reference to beam elements or nodal points as might be typical in a finite element formulation. The program and example problem are discussed next.
Figure 11.1: General Beam
o
11.1.1 Analytical Formulation
Solution of beam problems utilizes some mathematical idealizations such as a con­
centrated load, which implies infinite load intensity acting over an infinitesimal area. Also of importance are linearly varying distributed loads, or ramp loads. Treatment of these entities is facilitated by use of singularity functions [9]. The singularity function of order n is denoted by < x — x 0 >n and is defined as
< x — xo > =
For n > 0, the function satisfies
0, x < xo
(x — xo)n x > xo.
Γ n , < x — xo >n+ 1
< x — xo > dx = ---------------------.
Jo n + 1
The special case where n = — 1 is appropriate for describing a concentrated load. The term < x — x o >- 1 means the limit as e ^ 0 of the following function
0 x < xo,
< x — xo > ~ i = ^ j xo < x < (xo + e),
0 x > (xo + e).
Consequent l y, i n t he l i mi t as e approaches zero the integral becomes
f χ
/ < x — xo >- 1 dx = < x — xo >o .
o
Anal yzi ng t he l oads and def or mat i ons i n t he bea m r equi r es comput at i on of t he shear, moment, sl ope, and def l ect i on des i gnat ed as v(x), m(x), y '(x), and y(x). The beam lies in the range 0 < x < L. A total of four end conditions are imposed at x = 0 and x = L. Normally, two conditions will be specified at each end; so, two un­
known conditions applicable at x = 0 need to be found during the solution process. Along with the end conditions, interior supports may exist at x = r 3, 1 < j < Ns. Displacements y0 will occur at supports, and the reactions R 0, as well as four end
conditions, needed to cause the deflections will have to be determined during the analysis. Within the beam span, the applied loading will consist of known external loads described as we(x) and the support reactions. Fundamentals of Euler beam theory developed in standard textbooks [9, 102] imply the following differential and integral relations:
I) Load
Ns
II) Shear
v'(x)= we(x) + Rj <x — r3 > 1;
3 = 1
Ns
v(x) = vo + Ve(x) + ^ 2 Rj < x — rj >
3=1
f x
ve(x) = we(x) dx;
o
III) Mo me n t a n d Second Der i vat i ve
m'(x) = v,
Ns
m(x) = mo + vox + me(x) + R3 < x — r3 > 1;
3=1
, χ
me(x) = / ve(x) dx, o
y'' (x) = k(x)
Ns
mo
+ vox + me(x) + R3 < x — r3 > 1
3=1
k(x)
E(x) I(x)’
IV) Slope
y'(x)
ρ X ρ X
yo + mo k(x) dx + vo xk( x) dx +
o o
rχ Ns rχ
/ k(x) me(x) dx + Rj < x — r3 >1 k(x) dx;
o o
1
V) Deflection
y(x) = yo + y'0 x + mo
nX nX
mo / k(x) dxdx + o o
o
X
o
X
X X
xk( x) dxdx + / k(x) me(x) dxdx +
o o
vo / o
Ns
N s
Σ Β -3
X
< x — r3 > 1 k(x) dx dx
wher e E( x) I ( x) is the product of the Young’s modulus and the cross section mo­
ment of inertia, y0, y'0, v0, m0, are the left-end values of the deflection, slope, shear and moment respectively. The property k(x) will be spatially variable unless E I is constant, which yields the following simple formulas
The external loading conditions employed here can handle most practical situations. It is assumed that several concentrated loads F3 act at positions f 3, 1 < j < N f. Distributed loads are described by linearly varying ramp loads. A typical ramp load starts at position p
3
with intensity P
3
and varies linearly to magnitude Q 3
at position q
3
.
The ramp load is zero unless p
3
< x < q
3
.
A total of Nr
ramp loads may be present. Instances where P
3
= Q
3
can also occur, implying a uniformly distributed load. The general external loading chosen can be represented as
Ely(x) = EI (yo + y'0 x) + + ί [ me(x) dx dx+
2 6 Jo Jo
Jo Jo
Nf
We(x) = Σ F3 < x — f 3 >- 1 +
3=1
Nr
^ ^ P < x — P3 > o —Q3 < x — q3 > o +
S3 (< x — P3 > — < x — q3 > )]
where
β _ Qo P3
° %- Pj
and each summation extends over the complete range of pertinent values. Similarly, integration using the properties of singularity functions yields
Nf
ve(x) = Σ Fj <x — fj > 0 +
j=1
Nr
^ ^ \Pj < x — Pj > 1 —Qj < x — Qj > 1 +
- y ( < x — Pj > 2 - < x — q3 > 2 ) ]
and
Nf
me(x) = Y Fj < x — fj > 1 +
j = 1
The single and double integrals given earlier involving m e(x) and k(x) can easily be evaluated exactly when E I is constant, but these are not needed here. Since k(x) will generally be spatially variable in the target problem set, the integrations to compute y 0(x) and y(x) are best performed numerically. Leaving the number of integration increments as an independent parameter allows high accuracy evaluation of all integrals whenever this is desirable. Typically, problems using several hundred integration points only require a few seconds to solve using a personal computer.
Completing the problem solution requires formulations and solution of a system of simultaneous equations involving v 0, m0, y'0, y0, R 1, ..., RNs. The desired equations are created by specifying the displacement constraints at the supports, as well as four of eight possible end conditions. To present the equations more concisely the following notation is adopted:
/ k(x) dx = K 1 (x) , / k(x) dxdx = K 2 (x),
J 0 J 0 J 0
and it is evident from their definitions that both J 1 (x, rj ) and J2 (x, rj ) both equal zero for x < rj.
At a t ypi cal suppor t l ocat i on r %, the deflection will have an imposed value y t. Consequently, the displacement constraints require
Ns
y0 + rty'0 + K 2 (rt ) m-0 + L2 W V0 + ^ J2 (rt,rj) Rj = yt — h ( n )
j=i+ 1
for 1 < i < Ns. The remaining four end conditions can specify any legitimate com­
bination of conditions yielding a unique solution. For example, a beam cantilevered at x = 0 and pin supported at x = L would require y(0) = 0, y °(0) = 0, m(L) = 0, and y(L) = 0. In general, conditions imposed at x = 0 have an obvious form since only v0, m0, y0, or y'0 are explicitly involved. To illustrate a typical right end condition, let us choose slope, for example. This yields
Ns
y0 + y0 + K 1 (L) m0 + L 1 (L) v0 + J1 ( L, rj ) Rj = y 0(L) — I 1 (L).
j = 1
Equations for other end conditions have similar form, and all eight possibilities are implemented in the computer program listed at the end of the chapter. Once the reactions and any initially unknown left-end conditions have been determined, load and deformation quantities anywhere in the beam can be readily found.
11.1.2 Program to Analyze Beams of General Cross Section
A program to solve general beam problems was written which tabulates and plots the shear, moment, slope, and deflection. The driver program vdb defines the data, calls the analysis functions, and outputs the results. Six functions that implement the methods given in this section were written. Understanding the program details can best be achieved by studying the code closely. The program was checked extensively using examples from several texts and reference books. The three span beam having parabolically tapered haunches shown in
Figure 11.2 was analyzed previously by Arbabi and Li [5]. The program vdb was used to analyze the same problem and produces the results in
Figure 11.3
, which agree well with the paper.
We believe that the computer program is general enough to handle a wide variety of practical problems. Some readers may want to extend the program by adding interactive input or input from a data file. Such a modification is straightforward.
11.1.3 Program Output and Code Output from Arbabi and Li Example
Analysis of a Variable Depth Elastic Beam
Title: Problem from Arbabi and Li
Slope
P
q
Η*
Η*
J?h
Figure 11.2: Parabolic Beam from Arbabi and Li
Sh e a r Di a g r a m
Mo me n t Di a g r a m
x a x i s Sl o p e Cu r v e
y a x i s
Figure 11.3: Results for Arbabi and Li Example
x a x i s
x a x i s
Beam Length: 3
Number of integration segments: 3 01 Print frequency for results: 10
Interior Supports: (2)
|#
| --- - | --- -
X-location
Deflection
| 1
1.0000e+000
0.0000e+000
| 2
2.0000e+000
0.0000e+000
Concentrated Forces:
(1)
|#
| --- - | --- -
X-location
Force
| 1
5.0000e-001
-1.0000e+000
Ramp loads: (1)
|#
| --- - | --- -
X-start
Load
| 1
1.0000e+000
-1.0000e+000 :
End conditions:
| End
I
Function
Value
| -----
| left
slope
0.0000e+000
| left
deflection
0.0000e+000
| right
slope
0.0000e+000
| right
deflection
0.0000e+000
EI values
are specified
|#
| --- - | --- -
X-start
EI-value
| 1
0.0000e+000
7.997 6e+000
| 2
1.0101e-002
7.5273e+000
| 3
2 .0202e-002
7.0848e+000
| 4
3 .0303e-002
6.6688e+000
| 5
4.0404e-002
6.2 77 6e+000
Material deleted for publication
| 296
2.959 6e+000
6.2776e+000
| 297
2.9697e+000
6.6688e+000
| 298
2.9798e+000
7.0848e+000
| 299
2.9899e+000
7.52 73e+000
| 300
3.0000e+000
7.9976e+000
X-end
Solution time was 0.55 secs.
Reactions at Internal Supports: | X-location Reaction
| --------------
| 1 1.0782e+000
| 2 4.75 06e-001
Load
1.0000e+000
Table of Results:
X-location
Shear
Moment
Theta
Delta
0
5.2494e-001
-1.7415e-001
0.0000e+000
0.0000e+000
0.1
5.2494e-001
-1.2166e-001
-2.4859e-003
-1.1943e-004
0.2
5.2494e-001
-6.9164e-002
-5.32 62e-003
-5.0996e-004
0.3
5.2494e-001
-1.667 0e-002
-7.42 51e-003
-1.1612e-003
0.4
5.2494e-001
3.582 4e-002
-6.5761e-003
-1.8965e-003
0.5
-4.75 06e-001
8.8318e-002
-5.5 68 0e-004
-2 .3 003e-003
0.6
-4.75 06e-001
4.0812e-002
5.6976e-003
-1.9998e-003
0.7
-4.75 06e-001
-6.6940e-003
7.1119e-003
-1.3258e-003
0.8
-4.75 06e-001
-5.42 00e-002
5.6441e-003
-6.7385e-004
0.9
-4.75 06e-001
-1.0171e-001
3 .33 02e-003
-2 .2402e-004
1
6.0309e-001
-1.4921e-001
1 .2242e-003
-2.42 8 6e-017
1.1
5.0309e-001
-9.3903e-002
-7.9439e-004
2.3707e-005
1.2
4.0309e-001
-4.8593e-002
-2.8814e-003
-1.6165e-004
1.3
3.03 09e-001
-1.3284e-002
-4.3574e-003
-5.3250e-004
1.4
2.03 09e-001
1 .2025e-002
-4.2883e-003
-9.8078e-004
1.5
1.0309e-001
2.7334e-002
-2.3 015e-003
-1.3242e-003
1.6
3.0918e-003
3 .2643e-002
6.5694e-004
-1.4078e-003
1.7
-9.6908e-002
2.7953e-002
3.0625e-003
-1.2125e-003
1.8
-1.9691e-001
1.3262e-002
4.1954e-003
-8.3907e-004
1.9
-2.9 691e-001
-1.1429e-002
4.2843e-003
-4.0860e-004
2
7.8151e-002
-4.6120e-002
3.8358e-003
-1.1102e-016
2.1
7.8151e-002
-3.8305e-002
3 .1202e-003
3.5021e-004
2.2
7.8151e-002
-3.0490e-002
2.0801e-003
6.1308e-004
2.3
7.8151e-002
-2.2675e-002
7.2881e-004
7.5555e-004
2.4
7.8151e-002
-1.4860e-002
-6.9898e-004
7.5597e-004
2.5
7.8151e-002
-7.0445e-003
-1.7447e-003
6.2865e-004
2.6
7.8151e-002
7.7058e-004
-2.0539e-003
4.3228e-004
2.7
7.8151e-002
8.5857e-003
-1.7105e-003
2.4008e-004
2.8
7.8151e-002
1.6401e-002
-1.0840e-003
9.9549e-005
2.9
7.8151e-002
2.4216e-002
-4.7454e-004
2 .2493e-005
3
7.8151e-002
3 .2031e-002
-4.4409e-016
-2.2204e-016
Variable Depth Beam Program
i: f u n c t i o n vdb 2: % Exampl e: vdb
4: %
5: % T h i s p r o g r a m c a l c u l a t e s t h e s h e a r, moment, 6: % s l o p e, and d e f l e c t i o n of a v a r i a b l e d e p t h 7: % i n d e t e r m i n a t e beam s u b j e c t e d t o compl ex 8: % l o a d i n g and g e n e r a l end c o n d i t i o n s. The 9: % i n p u t d a t a a r e d e f i n e d i n t h e p r o g r a m i o: % s t a t e m e n t s be l ow.
i i: %
i 2: % Us e r m f u n c t i o n s r e q u i r e d:
i 3: % bmvar de p, e x t l o a d, l i n t r p, o n e o v r e i,
i 4: % s n g f, t r a p s u m
i 5
i 6
i 7:
i 8
i 9
2o:
2 i:
22
23:
24:
25
26
27:
28
29
3o:
3 i
32
33:
34
35
36
37
38
39
4o:
4 i
42
43:
44
45
46
47
48
49
5o:
5 i:
52
53:
54:
55
56
57:
58
59
c l e a r a l l; Problem=1; i f Problem == 1
T i t l e = ['P r o b l e m from Arbabi and L i']; P r i n t o u t = 1 0; % Ou t p u t f r e q u e n c y BeamLength=3; % Beam l e n g t h NoSegs=301; % # o f beam d i v i s i o n s f o r % i n t e g r a t i o n % E x t e r n a l c o n c e n t r a t e d l o a d s and l o c a t i o n E x t F o r c e = [ - 1 ]; E x t F o r c e X = [.5 ];
% E x t e r n a l ramp l o a d s and r a n g e % q1 q2 x1 x2
Ext Ramp=[ - 1 - 1 1 2 ];
% I n t e r i o r s u p p o r t s: i n i t i a l d i s p l a c e m e n t % and l o c a t i o n
I nt SupX= [1; 2 ]; I n t S u p D e l t a = [ 0; 0 ];
% End ( l e f t and r i g h t ) c o n d i t i o n s EndCondVal= [0; 0; 0; 0 ]; % ma g n i t u d e
% 1 = s h e a r,2 = m o m e n t,3 = s l o p e,4 = d e l t a EndCondFunc=[3; 4; 3; 4 ];
% 1 = l e f t e n d,2 = r i g h t end EndCondEnd= [1; 1; 2; 2 ];
% EI o r beam d e p t h s p e c i f i c a t i o n EI o r De p t h =1; % 1=EI v a l u e s s p e c i f i e d
% 2 = d e p t h v a l u e s s p e c i f i e d i f E I o r De p t h == 1
% D i s c r e t i z e t h e p a r a b o l i c h a u n c h f o r t h e
% t h r e e
s p a n s
Wi dth=1
E=1;
a = 0.5 ~ 2; Npt s =100;
h 1 = 0.5;
k1=1;
x 1 = l i n s p a c e ( 0,1,N p t s );
h 2 = 1.5;
k2=1;
x 2 = l i n s p a c e ( 1,2,N p t s );
h 3 = 2.5;
k3=1;
x 3 = l i n s p a c e ( 2,3,N p t s );
y 1 = ( x 1 - h 1 ).~ 2/a + k 1; y 2 = ( x 2 - h 2 ).~ 2/a + k 2; y 3 = ( x 3 - h 3 ).~ 2/a + k 3;
EI x=[ x1 x2 x 3 ]'; h=[ y1 y2 y 3 ]'; EI v a l u e = E * Wi d t h/1 2 * h.~ 3; mn = mi n ( E I v a l u e ); E I v a l u e = E I v a l u e./m n; e l s e
% Beam w i d t h and Yo u n g's modul us BeamWi dt h=[ ]; BeamE=[]; D e p t h = [ ]; De pt hX=[ ]; end
e l s e i f P r o b l e m == 2
T i t l e = ['F r o m Ti moshenko and Y o u n g,', ...
' p 434, ha u n c h b e a m'];
P r i n t o u t = 1 2; NoSegs=144*4+1; BeamLength=144;
60:
6 i:
62
63:
64:
65
66
67:
68
69
70:
7 i
72
73:
74:
75
76
77
78
79
80:
8 i
82
83:
84:
85
86
87
88
89
90:
9 i:
92
93:
94:
95
96
97:
98
99
i 0 0:
i 0 i:
i 0 2
i 0 3:
i 0 4:
E x t For ce= [ ]; ExtForceX=[];
ExtRamp=[-1 -1 0 108];
IntSupX=[36; 108]; I nt SupDel t a=[ 0; 0]; EndCondVal=[0; 0; 0; 0];
EndCondFunc=[2; 4; 2; 4];
EndCondEnd= [1; 1; 2; 2]; EIorDepth=2; i f EIorDepth == 1 E I v a l u e = [ ]; EIx=[ ]; e l s e
BeamWidth=[1]; BeamE=[1];
% D i s c r e t i z e t h e p a r a b o l i c s e c t i o n s a=36~2/5; k=2.5; h1=0; h2=72; h3=144;
N1=36; N2=72; N3=36;
x 1 = l i n s p a c e ( 0, 36,N1); y1=(x1- h1).~2/a+k; x 2 = l i n s p a c e ( 36,108,N2); y2=(x2- h2).~2/a+k; x3=l i n s p a c e ( 1 0 8,1 4 4,N3 ); y3=(x3- h3).~2/a+k; Depth=[y1 y2 y 3 ]'; DepthX=[x1 x2 x 3 ]';
% Comparison v a l u e s
I=BeamWidth*Depth.~3/12; Imin=min(I); L1=36; k1=BeamE*Imin/L1; k2=k1/2; k3=k1; t 0 =1 0.4 6/k 1; t 1=1 5.3 3/k 1; t 2 = 22.24/k1; t 3 = 27.95/k1;
f p r i n t f ('\n\n V a l u e s from r e f e r e n c e');
f p r i n t f ('\n Thet a (x= 0)
f p r i n t f ('\n Thet a (x= 36) f p r i n t f ('\n Thet a (x=108) f p r i n t f ('\n Thet a (x=144)
% 1 2.4 e',t 0 ) % 1 2.4 e',t 1 ) % 1 2.4 e',t 2 ) % 1 2.4 e\n',t 3 );
end
end
% Load i n p u t p a r amet er s i n t o m a t r i c e s Force=[Ext Force,Ext For ceX]; NoExt For ce =l engt h( Ext For ce); [NoExtRamp,ncol]=size(ExtRamp); Int S u p = [ I n t S u p D e l t a,I n t S u p X ]; NoIntSup=length(IntSupX);
EndCond=[EndCondVal,EndCondFunc,EndCondEnd]; i f EIorDepth == 1
BeamProp=[]; NoEI orDepths=length(EIx); E I d a t a = [ E I v a l u e EIx]; e l s e
BeamProp=[BeamWidth BeamE]; NoEIorDepths=length(DepthX);
EIdata=[Depth DepthX]; end
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
% more on
% Output i n p u t d a t a
l a b e l 1 = ['s h e a r ';'moment '; ...
's l o p e ';'d e f l e c t i o n'];
l a b e l 2 = ['l e f t ';'r i g h t ']; f p r i n t f ('\n\n A n a l y s i s of a V a r i a b l e Depth '); f p r i n t f ('E l a s t i c Beam');
f p r i n t f ('\n --------------------------------------------------------------');
f p r i n t f ('-----------------');
f p r i n t f ('\n\n'); d i s p ( ['T i t l e: ' T i t l e ] ); f p r i n t f...
('\nBeam Length: %g', ...
BeamLength); f p r i n t f...
('\nNumber of i n t e g r a t i o n segments: %g', ... NoSegs); f p r i n t f...
('\n P r i n t fr equenc y f o r r e s u l t s: %g', ...
P r i n t o u t );
f p r i n t f ('\n\n I n t e r i o r Suppor t s: (%g)', ...
NoIntSup); i f NoIntSup > 0
f p r i n t f ('\n | # X - l o c a t i o n D e f l e c t i o n');
f p r i n t f ('\n | ---------------------------------------------------------');
f o r i=1:NoIntSup
f p r i n t f ('\n |%4.0f %12.4e %12.4e', ... i,I n t S u p ( i,2 ),I n t S u p ( i,1 ) );
end
end
f p r i n t f ('\n\n C o n c e n t r a t e d Force s: (%g)', ...
NoExtForce); i f NoExtForce > 0
f p r i n t f ('\n | # X - l o c a t i o n F o r c e');
f p r i n t f ('\n | ---------------------------------------------------------');
f o r i=1:NoExtForce
f p r i n t f ('\n |%4.0f %12.4e %12.4e', ... i,F o r c e ( i,2 ),F o r c e ( i,1 ) );
end
end
f p r i n t f ('\n\n R a m p l o a d s: (%g)', NoExtRamp); i f NoExtRamp > 0
f p r i n t f ('\n | # X - s t a r t L o a d');
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
f p r i n t f (' X-end L o a d');
f p r i n t f ('\n | ---------------------------------------------------------');
f p r i n t f (' -------------------------------------------------');
f o r i=1:NoExtRamp
f p r i n t f ('\n |%4.0f %12.4e %12.4e ', ...
i,E x t R a m p ( i,3 ),E x t R a m p ( i,1 ) ); f p r i n t f ('% 1 2.4 e %12.4e', ...
E x t R a m p ( i,4 ),E x t R a m p ( i,2 ) );
end
end
f p r i n t f ('\n\n E n d c o n d i t i o n s:');
f p r i n t f ('\n | End F u nct i on V a l u e');
f p r i n t f ('\n ');
f p r i n t f ('| ---------------------------------------------- \n');
f o r i = 1:4
j =EndCond(i,3); k=EndCond(i,2); s t r g = s p r i n t f (' % 1 2.4 e',E n d C o n d ( i,1 ) ); d i s p ( [' | ' l a b e l 2 ( j,:) l a b e l 1 ( k,:) s t r g ] ); end
i f EIorDepth == 1
f p r i n t f ('\n E I v a l u e s a r e s p e c i f i e d'); f p r i n t f ('\n | # X - s t a r t E I - v a l u e')
f p r i n t f ('\n | ---------------------------------------------------------');
f o r i=1:NoEIorDepths
f p r i n t f ('\n |%4.0f %12.4e %12.4e', ... i,E I d a t a ( i,2 ),E I d a t a ( i,1 ) );
end
e l s e
f p r i n t f ('\n D e p t h v a l u e s a r e s p e c i f i e d f o r '); f p r i n t f ('r e c t a n g u l a r c r o s s s e c t i o n'); f p r i n t f ('\n | Beam wi dt h: %12.4e', ...
BeamProp(1)); f p r i n t f ('\n | Y o u n g''s modulus: %12.4e', ...
BeamProp(2)); f p r i n t f ('\n |');
f p r i n t f ('\n | # X - s t a r t D e p t h')
f p r i n t f ('\n | - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -');
f o r i = 1:N o E I o r D e p t h s
f p r i n t f ('\n | % 4.0 f % 1 2.4 e % 1 2.4 e', ... i,E I d a t a ( i,2 ),E I d a t a ( i,1 ) );
e n d
e n d
d i s p (' ');
% B e g i n a n a l y s i s
i 9 5
i 9 6
i 9 7
i 9 8
i 9 9
200
2 0 i
202
203
204
205
206
207
208
209
2 i 0
2 i i
2 i 2
2 i 3
2 i 4
2 i 5
2 i 6
2 i 7
2 i 8
2 i 9
220
2 2 i
222
223
224
225
226
227
228
229
230
2 3 i
232
233
234
235
236
237
238
239
x=l i nspace(0,BeamLengt h,NoSegs)'; t = c l o c k; [ V,M,T h e t a,D e l t a,R e a c t i o n s ] = ... bmvardep(NoSegs,BeamLength,Force,ExtRamp, ... EndCond,I ntSup,EIdat a,BeamProp); t = e t i m e ( c l o c k,t );
% Output r e s u l t s d i s p (' ');
d i s p ( ['S o l u t i o n time was ',n u m 2 s t r ( t ),' s e c s.'] ); i f NoIntSup > 0
f p r i n t f ('\n R e a c t i o n s a t I n t e r n a l S u p p o r t s:'); f p r i n t f ('\n | X - l o c a t i o n R e a c t i o n');
f p r i n t f ('\n | -------------------------------------------------');
f o r i=1:NoIntSup
f p r i n t f ('\n | %12.8g %12.4e', ...
I n t S u p ( i,2 ),R e a c t i o n s ( i ) );
end
end
f p r i n t f ('\n\n T a b l e of R e s u l t s:'); f p r i n t f ('\n | X - l o c a t i o n S h e a r');
f p r i n t f (' Moment');
f p r i n t f (' Thet a D e l t a');
f p r i n t f ('\n | ---------------------------------------------- ');
f p r i n t f ('-----------------------');
f p r i n t f (' -------------------------------------------------');
i f P r i n t o u t > 0
f o r i = 1:P r i n t o u t:N o S e g s
f p r i n t f ('\n |%12.4g %12.4e %12.4e', ...
x ( i ),V ( i ),M ( i ) ); f p r i n t f (' %12.4e % 1 2.4 e',T h e t a ( i ),D e l t a ( i ) ); end
d i s p (' '); e l s e
i=1; j=NoSegs;
f p r i n t f ('\n |%12.4g %12.4e %12.4e', ...
x ( i ),V ( i ),M ( i ) ); f p r i n t f (' %12.4e % 1 2.4 e',T h e t a ( i ),D e l t a ( i ) ); f p r i n t f ('\n |%12.8g %12.4e %12.4e', ...
x ( j ),V ( j ),M ( j ) ); f p r i n t f (' %12.4e % 1 2.4 e',T h e t a ( j ),D e l t a ( j ) ); end
f p r i n t f ('\n\n');
s u b p l o t ( 2,2,1 );
p l o t ( x,V,'k -'); g r i d; x l a b e l ('x a x i s'); y l a b e l ('S h e a r'); t i t l e ('S h e a r Di agr a m');
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
s u b p l o t ( 2,2,2 );
p l o t ( x,M,'k -'); g r i d; x l a b e l ('x a x i s'); y l a b e l ('M o m e n t'); t i t l e ('M o m e n t Diagram') s u b p l o t ( 2,2,3 );
p l o t ( x,T h e t a,'k -'); g r i d; x l a b e l ('x a x i s'); y l a b e l ('S l o p e'); t i t l e ('S l o p e C u r v e'); s u b p l o t ( 2,2,4 );
p l o t ( x,D e l t a,'k -'); g r i d; x l a b e l ('y a x i s'); y l a b e l ('D e f l e c t i o n'); t i t l e ('D e f l e c t i o n C u r v e'); s u b p l o t drawnow; f i g u r e ( g c f )
%print -deps vdb
% more o f f
%=============================================
f u n c t i o n [ V,M,T h e t a,D e l t a,R e a c t i o n s ] = ...
bmvardep(NoSegs,BeamLength,Force,ExtRamp, ... EndCond,IntSup,EIdata,BeamProp)
% [V,M,Thet a,Del t a,React i ons]=bmvardep ...
% (NoSegs,BeamLength,Force,ExtRamp,EndCond, ... % IntSup,EIdata,BeamProp)
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
%
% This f u n c t i o n computes t h e s h e a r, moment,
% s l o p e, and d e f l e c t i o n i n a v a r i a b l e dept h % e l a s t i c beam havi ng s p e c i f i e d end c o n d i t i o n s, % i n t e r m e d i a t e s u p p o r t s wi t h gi ven % d i s p l a c e m e n t s, and g e n e r a l a p p l i e d l o a d i n g,
% al l o wi n g c o n c e n t r a t e d l o a d s and l i n e a r l y % v a r y i n g ramp l o a d s.
%
% NoSegs - number of beam d i v i s i o n s f o r
% i n t e g r a t i o n
% BeamLength - beam l e n g t h
% Force - m a t r i x c o n t a i n i n g t h e magnitudes
% and l o c a t i o n s f o r c o n c e n t r a t e d
% l oads
% ExtRamp - m a t r i x c o n t a i n i n g t h e end % magnitudes and end l o c a t i o n s
% f o r ramp l oa ds
% EndCond - m a t r i x c o n t a i n i n g t h e t y p e of
% end c o n d i t i o n s, t h e magni t udes,
% and whether val ues a r e f o r t h e
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
l e f t or r i g h t ends IntSup - m a t r i x c o n t a i n i n g t h e l o c a t i o n
and d e l t a f o r i n t e r i o r s u p p o r t s E I d a t a - e i t h e r EI or dept h v a l u e s
BeamProp - e i t h e r n u l l or beam wi dths
V - v e c t o r of s h e a r val ues
M - v e c t o r of moment val ues
Thet a - v e c t o r of s l o p e v a l u e s
D e l t a - v e c t o r of d e f l e c t i o n val ues
Re a c t i o n s - r e a c t i o n s a t i n t e r i o r s u p p o r t s
User m f u n c t i o n s r e q u i r e d:
o n e o v r e i, e x t l o a d, s n g f, trapsum
i f n a r g i n < 8, BeamProp=[]; end % E val ua t e f u n c t i o n v a l u e c o o r d i n a t e s and 1/EI x=l i nspace (0,BeamLengt h,NoSegs)'; kk =o n e o v r ei ( x,E I d a t a,B eamP r o p );
% E x t e r n a l l o a d c o n t r i b u t i o n s t o s h e a r and % moment i n t e r i o r t o span and a t r i g h t end [ve,me]=ext l oad(x,For ce,Ext Ramp); [vv,mm]=extload(BeamLength,Force,ExtRamp);
% D e f l e c t i o n s and p o s i t i o n of i n t e r i o r s u p p o r t s
n s = s i z e ( I n t S u p,1 );
i f ns > 0
y s p r t = I n t S u p (:,1 ); r = I n t S u p (:,2 ); s n f = s n g f ( x,r,1 ); e l s e
y s p r t = [ ]; r =[ ]; s n f = z e r o s ( N o S e g s,0 ); end
% Form m a t r i x g o v e r n i n g y''( x ) s m a t = k k (:,o n e s ( 1,n s + 3 ) ).* ...
[ x,o n e s ( N o S e g s,1 ),s n f,m e ];
% I n t e g r a t e t w i c e t o g e t s l o p e a nd d e f l e c t i o n % m a t r i c e s
s m a t = t r a p s u m ( 0,B e a m L e n g t h,s ma t );
y m a t = t r a p s u m ( 0,B e a m L e n g t h,s m a t );
% E x t e r n a l l o a d c o n t r i b u t i o n s t o
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
% s l o p e/d e f l e c t i o n a t t h e r i g h t end ss=smat(NoSegs,ns+3); yy=ymat(NoSegs,ns+3);
% Equat i ons t o s o l v e f o r l e f t end c o n d i t i o n s % and i n t e r n a l r e a c t i o n s ns4=ns+4; j = 1:4; a = z e r o s ( n s 4,n s 4 ); b = z e r o s ( n s 4,1 ); j s = 1:n s; j s 4 = j s + 4;
% Account f o r f o u r independent boundary % c o n d i t i o n s. Us ual l y two c o n d i t i o n s w i l l be % imposed a t each end. f o r k=1:4
val=EndCond(k,1); typ=EndCond(k,2); wchend=EndCond(k,3); i f wchend==1
b ( k ) = v a l; r o w = z e r o s ( 1,4 ); row(typ)=1; a ( k,j ) = r o w; e l s e
i f typ==1 % Shear
a ( k,j ) = [ 1,0,0,0 ]; b ( k ) = v a l - v v; i f ns>0
a ( k,j s 4 ) = s n g f ( B e a m L e n g t h,r,0 );
end
e l s e i f typ==2 % Moment
a ( k,j ) = [ B e a m L e n g t h,1,0,0 ]; b(k)=val-mm; i f ns>0
a ( k,j s 4 ) = s n g f ( B e a m L e n g t h,r,1 );
end
e l s e i f typ==3 % Slope
a ( k,j ) = [ s m a t ( N o S e g s,1:2 ),1,0 ];
b ( k ) = v a l - s s;
i f ns>0
a ( k,j s 4 ) = s m a t ( N o S e g s,3:n s + 2 );
end
e l s e % D e f l e c t i o n
a ( k,j ) = [ y m a t ( N o S e g s,1:2 ),B e a m L e n g t h,1];
b ( k ) = v a l - y y;
i f ns>0
a( k,j s 4 ) = y m a t ( N o S e g s,3:n s + 2 );
end
end
end
end
% I n t e r p o l a t e t o a s s e s s h o w s u p p o r t d e f l e c t i o n s
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
% a r e a f f e c t e d by end c o n d i t i o n s, e x t e r n a l % l o a d s, and s u p p o r t r e a c t i o n s. i f ns>0
a ( j s 4,1 ) = i n t e r p 1 ( x,y m a t (:,1 ),r ); a ( j s 4,2 ) = i n t e r p 1 ( x,y m a t (:,2 ),r ); a ( j s 4,3 ) = r; a ( j s 4,4 ) = o n e s ( n s,1 ); f o r j = 1:n s - 1
a ( j + 5:n s + 4,j + 4 ) = ...
i n t e r p 1 ( x,y m a t (:,j + 2 ),r ( j + 1:n s ) );
end
end
b ( j s 4 ) = y s p r t - i n t e r p 1 ( x,y m a t (:,n s + 3 ),r );
% S o l v e f o r unknown r e a c t i o n s and end c o n d i t i o n s c = a\b; v 0 = c ( 1 ); m 0 = c( 2); s 0 = c ( 3 ); y 0 = c ( 4 ); R e a c t i o n s = c ( 5:n s + 4 );
% Compute t h e s h e a r, moment, s l o p e, d e f l e c t i o n % f o r a l l x i f n s > 0
V = v 0 + v e + s n g f ( x,r,0 ) * R e a c t i o n s; M = m 0 + v 0 * x + m e + s n g f ( x,r,1 ) * R e a c t i o n s; T h e t a = s 0 + s m a t (:,n s + 3 ) + s m a t (:,1:n s + 2 ) * ...
[ v 0;m 0;R e a c t i o n s ]; D e l t a = y 0 + s 0 * x + y m a t (:,n s + 3 ) + ...
y m a t (:,1:n s + 2 ) * [ v 0;m 0;R e a c t i o n s ];
e l s e
R e a c t i o n s = [ ]; V=v0+ve; M=m0+v0*x+me; T h e t a = s 0 + s m a t (:,n s + 3 ) + s m a t (:,1:2 ) * [ v 0;m 0 ]; D e l t a = y 0 + s 0 * x + y m a t (:,n s + 3 ) + ... y m a t (:,1:2 ) * [ v 0;m 0 ];
end
%=============================================
f u n c t i o n [ V,M,E I T h e t a,E I D e l t a ] = e x t l o a d ...
( x,F o r c e,E x t R a m p )
% [ V,M,E I T h e t a,E I D e l t a ] = e x t l o a d ...
% ( x,F o r c e,E x t R a m p )
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
%
% T h i s f u n c t i o n computes t h e s h e a r, moment,
% s l o p e, and d e f l e c t i o n i n a u n i f o r m d e p t h % E u l e r beam whi ch i s l o a d e d by a s e r i e s of % c o n c e n t r a t e d l o a d s and ramp l o a d s. The v a l u e s
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
o f s h e a r, moment, s l o p e and d e f l e c t i o n a l l e q u a l z e r o when x=0.
x - l o c a t i o n a l o n g beam
F o r c e - c o n c e n t r a t e d f o r c e m a t r i x
ExtRamp - d i s t r i b u t e d l o a d m a t r i x
V - s h e a r
M - moment
E I T h e t a - s l o p e E I D e l t a - d e f l e c t i o n
U s er m f u n c t i o n s r e q u i r e d: s n g f
n f = s i z e ( F o r c e,1 ); n r = s i z e ( E x t R a m p,1 ); n x = l e n g t h ( x ); V = z e r o s ( n x,1 ); M=V;
EITheta=V; EID el ta =V;
% C o n c e n t r a t e d l o a d c o n t r i b u t i o n s i f n f > 0
F = F o r c e (:,1 ); f = F o r c e (:,2 ); V = V + s n g f ( x,f,0 ) * F;
M = M + s n g f ( x,f,1 ) * F;
i f n a r g o u t > 2
E I T h e t a = E I T h e t a + s n g f ( x,f,2 ) * ( F/2 );
E I D e l t a = E I D e l t a + s n g f ( x,f,3 ) * ( F/6 );
end
end
% Ramp l o a d c o n t r i b u t i o n s i f n r > 0
P = E x t R a m p (:,1 ); Q = E x t R a m p (:,2 ); p = E x t R a m p (:,3 ); q = E x t R a m p (:,4 );
S = ( Q - P )./( q - p ); s p 2 = s n g f ( x,p,2 ); s q 2 = s n g f ( x,q,2 ); s p 3 = s n g f ( x,p,3 ); s q 3 = s n g f ( x,q,3 ); s p 4 = s n g f ( x,p,4 ); s q 4 = s n g f ( x,q,4 );
V = V + s n g f ( x,p,1 ) * P - s n g f ( x,q,1 ) * ... % S h e a r Q + ( s p 2 - s q 2 ) * ( S/2 );
M=M+sp2*(P/2)-sq2*( Q/2)+ ... % Moment
( s p 3 - s q 3 ) * ( S/6 ); i f n a r g o u t > 2
E I T h e t a = E I T h e t a + s p 3 * ( P/6 ) - ... % E I * T h e t a
s q 3 * ( Q/6 ) + ( s p 4 - s q 4 ) * ( S/2 4 ); E I D e l t a = E I D e l t a + s p 4 * ( P/2 4 ) - ... % E I * D e l t a s q 4 * ( Q/2 4 ) + ( s n g f ( x,p,5 ) - ... s n g f ( x,q,5 ) ) * ( S/1 2 0 );
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
end
end
%=============================================
f u n c t i o n v a l = o n e o v r e i ( x,E I d a t a,B e a m P r o p )
% [ v a l ] = o n e o v r e i ( x,E I d a t a,B e a m P r o p )
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
%
% T h i s f u n c t i o n computes 1/E I by p i e c e w i s e % l i n e a r i n t e r p o l a t i o n t h r o u g h a s e t o f d a t a % v a l u e s.
%
% x - l o c a t i o n a l o n g beam
% E l d a t a - EI o r d e p t h v a l u e s
% BeamProp - n u l l o r w i d t h v a l u e s
%
% v a l - computed v a l u e f o r 1/E I
%
% U s er m f u n c t i o n s r e q u i r e d: none %---------------------------------------------------------------------------------------
i f s i z e ( E I d a t a,1 ) < 2 % u n i f o r m d e p t h c a s e
v = E I d a t a ( 1,l );
E I d a t a = [ v,m i n ( x );v,m a x ( x ) ];
end
i f ( n a r g i n > 2 ) & ( s u m ( s i z e ( B e a m P r o p ) ) > 0) % Compute p r o p e r t i e s a s s u m i n g t h e c r o s s % s e c t i o n i s r e c t a n g u l a r and E I d a t a (:,1 )
% c o n t a i n s d e p t h v a l u e s w i d t h = B e a m P r o p ( 1 ); E=BeamProp(2); E I d a t a (:,1 ) = E * w i d t h/1 2 * E I d a t a (:,1 ).~ 3; end
v a l = 1./l i n t r p ( E I d a t a (:,2 ),E I d a t a (:,1 ),x );
%=============================================
f u n c t i o n y = s n g f ( x,x 0,n )
% y = s n g f ( x,x 0,n )
%% ~~~~~~~~~~~~~~
% T h i s f u n c t i o n computes t h e s i n g u l a r i t y % f u n c t i o n d e f i n e d by % y=<x-x0>~n f o r n = 0,1,2,...
%
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
% U s e r m f u n c t i o n s r e q u i r e d: n o n e
%
-----------------------------------------------------------
i f n a r g i n < 3, n=0; end
x = x (:); n x = l e n g t h ( x ); x 0 = x 0 (:)'; n 0 = l e n g t h ( x 0 ); x = x (:,o n e s ( 1,n 0 ) ); x 0 = x 0 ( o n e s ( n x,1 ),:); d = x - x 0; s = ( d > = z e r o s ( s i z e ( d ) ) ); v = d.* s; i f n==0
y=s;
e l s e
y=v;
f o r j = 1:n - 1; y = y.* v; end end
%=============================================
f u n c t i o n v = t r a p s u m ( a,b,y,n )
%
% v = t r a p s u m ( a,b,y,n )
%~~~~~~~~~~~~~~~~~~
%
% T h i s f u n c t i o n e v a l u a t e s:
%
% i n t e g r a l ( a = > x, y ( x ) * d x ) f o r a<=x<=b %
% by t h e t r a p e z o i d a l r u l e (w hi c h assumes l i n e a r % f u n c t i o n v a r i a t i o n b e t w e e n s u c c e s i v e f u n c t i o n % v a l u e s ).
%
% a,b - l i m i t s o f i n t e g r a t i o n
% y - i n t e g r a n d t h a t ca n be a v e c t o r - v a l u e d % f u n c t i o n r e t u r n i n g a m a t r i x s u c h t h a t
% f u n c t i o n v a l u e s v a r y fr o m row t o row.
% I t c a n a l s o be i n p u t a s a m a t r i x w i t h
% t h e row s i z e b e i n g t h e number of
% f u n c t i o n v a l u e s and t h e column s i z e
% b e i n g t h e number o f components i n t h e
% v e c t o r f u n c t i o n.
% n - t h e number o f f u n c t i o n v a l u e s u s e d t o % p e r f o r m t h e i n t e g r a t i o n. When y i s a
% m a t r i x t h e n n i s computed a s t h e number
% o f rows i n m a t r i x y.
%
% v - i n t e g r a l v a l u e %
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
% U s e r m f u n c t i o n s c a l l e d: n o n e
% ------------------------------------------------------------------------------------------------------------------
i f i s s t r ( y )
% y i s an e x t e r n a l l y d e f i n e d f u n c t i o n x = l i n s p a c e ( a,b,n )'; h = x ( 2 ) - x ( 1 ); Y = f e v a l ( y,x ); % F u n c t i o n v a l u e s must v a r y i n % row o r d e r r a t h e r t h a n column % o r d e r o r computed r e s u l t s % w i l l be wrong.
m = s i z e ( Y,2 );
e l s e
% y i s column v e c t o r o r a m a t r i x Y=y; [ n,m ] = s i z e ( Y ); h = ( b - a )/( n - 1 ); end
v = [ z e r o s ( 1,m ); ...
h/2 * c u m s u m ( Y ( 1:n - 1,:) + Y ( 2:n,:) ) ];
%=============================================
% f u n c t i o n y = l i n t r p ( x d,y d,x )
% See Appe ndix B
Chapiter 12
Applications of Analytic Functions
12.1 Properties of Analytic Functions
Complex valued functions of a single complex variable are useful in various dis­
ciplines such as physics and numerical approximation theory. The current chap­
ter summarizes a number of attractive properties of analytic functions and presents some applications in which MATLAB is helpful. Excellent textbooks presenting the theory of analytic functions [18, 75, 119] are available which fully develop various theoretical concepts employed in this chapter. Therefore, only the properties which may be helpful in subsequent discussions are included.
12.2 Definition of Analyticity
We consider a complex valued function
F (z) = u(x,y) +iv(x,y) , z = x + iy
wh i c h d e p e n d s o n t h e c o mp l e x v a r i a b l e z. Th e f u n c t i o n F(z) is analytic at point z if it is differentiable in the neighborhood of z. Differentiability requires that the limit
'F( z + Δz) - F( z )'
lim
|Δζ|^ϋ
= F '(z)
Δz
e xi s t s i n d e p e n d e n t o f h o w \Δz\ approaches zero. Necessary and sufficient conditions for analyticity are continuity of the first partial derivatives of u and v and satisfaction of the Cauchy-Riemann conditions (CRC)
du dv du dv
dx dy ’ dy dx
These conditions can be put in more general form as follows. Let n denote an ar­
bitrary direction in the z-plane and let s be the direction obtained by a 90 ° counter­
clockwise rotation from the direction of n. The generalized CRC are:
du dv du dv
dn ds ’ ds dn
Satisfaction of the CRC implies that both u and v are solutions of Laplace’s equation
2 d2u d2u
ί Γ~2 ί Γ~2 = dx2 dy2
a n d
d2v d2v dx2 dy2
Th e s e f u n c t i o n s a r e c a l l e d h a r mo n i c. F u n c t i o n s r e l a t e d b y t h e CRC a r e a l s o s a i d t o b e h a r mo n i c c o n j u g a t e s. Wh e n o n e f u n c t i o n u is known, its harmonic conjugate v can be found within an additive constant by using
ί τ ί dv f dv f ( du du \
v = dv = dx-\- dy = — dx + dy + constant
J J dx J dy y J V dy dx y)
Ha r mo n i c c o n j u g a t e s a l s o h a v e t h e p r o p e r t i e s t h a t c u r v e s u = constant and v = constant intersect orthogonally. This follows because u = constant implies is zero in a direction tangent to the curve. However so v = constant along a
curve intersecting u = constant orthogonally.
Sometimes it is helpful to regard a function of x and y as a function of z = x + iy
a n d z = x — iy. The inverse is x = (z + z )/2 and y = (z — z)/( 2i). Chain rule
differentiation applied to a general function φ yields
d φ dφ dφ dφ ,d φ ,d φ
dx d z ^ dz ’ dy * dz 1 dz
d .d\, dφ ( d .d\ dφ
s o t h a t (
( d x d y ) Ύ dz
’ \d x ' dy J Ύ dz
So L a p l a c e ’s e q u a t i o n b e c o me s
d2φ d2φ d2φ
t: 77 4-
dx2 dy2 dzdz
It is straightforward to show the condition that a function F be an analytic function of z is expressible as
dF „
~di ~
It is important to note that most of the functions routinely employed with real argu­
ments are analytic in some part of the z-plane. These include:
zn, \fz, log(z), ez, sin(z), cos(z), arctan(z),
to mention a few. The real and imaginary parts of these functions are harmonic and they arise in various physical applications. The integral powers of z are especially significant. We can write
z = reιθ , r = \J x 2 + y 2 , Θ = tan 1 j
zn = u + iv , u = rn cos(nO) , v = rn 8ΐη(ηθ)
The reader can verify by direct differentiation that both u and v are harmonic.
Points where F(z) is nondifferentiable are called singular points and these are categorized as isolated or nonisolated. Isolated singularities are termed either poles or essential singularities. Branch points are the most common type of nonisolated singularity. Singular points and their significance are discussed further below.
and get
12.3 Series Expansions
If F(z) is analytic inside and on the boundary of an annulus defined by a < \z — z0\ <b then F (z) is representable in a Laurent series of the form
tt
F (z) = ^2 an(z — zo)n , a <\z — zo\< b
n=-tt
where
F(z) = — f F{t) *
( 1 2m JL (t - z0)”+1
and L represents any closed curve encircling z 0 and lying between the inner circle \z — z0\ = a and the outer circle \z — z 0\ = b. The direction of integration along the curve is counterclockwise. If F( z ) is also analytic for \z — z 0\ < a, the negative powers in the Laurent series drop out to give Taylor’s series
tt
F(z) = ^2 an(z — z 0 )n , \z — z0\<b
n=0
Sp e c i a l c a s e s o f t h e La u r e n t s e r i e s l e a d t o c l a s s i f i c a t i o n o f i s o l a t e d s i n g u l a r i t i e s as po l e s o r e s s e n t i a l s i n g u l a r i t i e s. S u p p o s e t h e i n n e r r a d i u s c a n b e ma d e a r b i t r a r i l y s ma l l b ut n o n z e r o. I f t h e c o e f f i c i e n t s b e l o w s o me or de r, s a y —m, vanish but a - m = 0, we classify z0 as a pole of order m. Otherwise, we say z0 is an essential singularity.
Another term of importance in connection with Laurent series is a - 1, the coeffi­
cient of (z — z0)- 1. This coefficient, called the residue at z0, is sometimes useful for evaluating integrals.
Analytic functions have many useful integral properties. One of these properties that concerns integrals around closed curves is:
12.4 Integral Properties
Cauchy-Goursat Theorem: If F(z) is analytic at all points in a simply connected region R, then
J F(z) dz = 0
L
for every closed curve L in the region.
An immediate consequence of this theorem is that the integral of F(z) along any path between two end points z 1 and z2 is independent of the path (this only applies for simply connected regions).
12.4.1 Cauchy Integral Formula
If F(z) is analytic inside and on a closed curve L bounding a simply connected region R then
F(z) = — ^ for 2 inside L
2ττι Jl t — z
F(z) = 0 for z outside L
Th e Ca u c h y i n t e g r a l f o r mu l a p r o v i d e s a s i mp l e me a n s f o r c o mp u t i n g F (z) at interior points when its boundary values are known. We refer to any integral of the form
= 1 r F M *
2ττι J l t — z
as a Cauchy integral, regardless of whether F(t) is the boundary value of an ana­
lytic function. I(z) defines a function analytic in the complex plane cut along the curve L. When F(t ) is the boundary value of a function analytic inside a closed curve L, I ( z ) is evidently discontinuous across L since I(z) approaches F( z ) as z approaches L from the inside but gives zero for an approach from the outside. The theory of Cauchy integrals for both open and closed curves is extensively developed in Muskhelishvili’s texts [72, 73] and is used to solve many practical problems.
12.4.2 Residue Theorem
If F( z ) is analytic inside and on a closed curve L except at isolated singularities z1,z2,...,z n where it has Laurent expansions, then
j F(z) dz = 2πι
j=n
Σ β
j=1
where Bj is the residue of F(z) at z = zj . In the instance where z* is a pole of order m, the residue can be computed as
1 ( dm —1
12.5 Physical Problems Leading to Analytic Functions
Several physical phenomena require solutions involving real valued functions sat­
isfying Laplace’s equation. Since an analytic function has harmonic real and imag­
inary parts, a harmonic function can often be expressed concisely as the real part of an analytic function. Useful tools such as Taylor series can yield effective com­
putational devices. One of the simplest practical examples involves determining a function u harmonic inside the unit disk \z\ < 1 and having boundary values de­
scribed by a Fourier series. In the following equations, and in subsequent articles, we will often refer to a function defined inside and on the unit circle in terms of polar coordinates as u(r, θ) while we may, simultaneously, think of it as a function of the complex variable z = rσ where σ = e%θ. Hence we write the boundary condition for the circular disk as
tt
u(1, θ)= ^ n n , σ = e%e
n=-tt
with c- n = cn because u is real. The desired function can be found as
u(r, θ) = mboxreal( F(z))
where
tt
F (z) = co + Cnzn , \z\ < 1
n=1
Th i s s o l u t i o n i s u s e f u l b e c a u s e t h e F a s t F o u r i e r Tr a n s f o r m ( FFT) c a n b e e mp l o y e d t o g e n e r a t e F o u r i e r c o e f f i c i e n t s f o r q u i t e g e n e r a l b o u n d a r y c o n d i t i o n s, a n d t h e s e r i e s f o r F(z) converges rapidly when \z \ < 1. This series will be employed below to solve both the problem where boundary values are given (the Dirichlet problem) and where normal derivative values are known on the boundary (the Neumann problem). Several applications where analytic functions occur are mentioned below.
12.5.1 Steady-State Heat Conduction
The steady-state temperature distribution in a homogeneous two-dimensional body is harmonic. We can take u = Real[F(z)]. Boundary curves where u = constant lead to conditions
F(z) + F(z) = constant
in the complex plane. Boundary curves insulated to prevent transverse heat flow lead to | ^ = 0, which implies
F(z) — F(z) = constant
12.5.2 Incompressible Inviscid Fluid Flow
Some flow problems for incompressible, nonviscous fluids involve velocity com­
ponents obtainable in terms of the first derivative of an analytic function. A complex velocity potential F(z) exists such that
u — iv = F' (z)
At impermeable boundaries the flow normal to the boundary must vanish which im­
plies
F(z) — F(z) = constant.
Furthermore, a uniform flow field with u = U, v = V is easily described by
F (z) = (U — iV )z
12.5.3 Torsion and Flexure of Elastic Beams
The distribution of stresses in a cylindrical elastic beam subjected to torsion or bending can be computed using analytic functions [90]. For example, in the torsion problem shear stresses τ χζ and τ γζ can be sought as
τχζ — iTYz = μ ε[ί '(z) — ic] and the condition of zero traction on the lateral faces of the beam is described by
f{z) ~ f(z) = izz
If the function z = ω(ζ) which maps \ζ\ < 1 onto the beam cross section is known, then an explicit integral formula solution can be written as
H Q = ± ( ω ί σ Μ σ.) ά α
J |σ| = 1 σ — ζ
Co ns e q ue nt l y, t h e t o r s i o n p r o b l e m f o r a b e a m o f s i mp l y c o n n e c t e d c r o s s s e c t i o n i s r e p r e s e n t e d c o n c i s e l y i n t e r ms o f t h e f u n c t i o n wh i c h ma p s a c i r c u l a r d i s k o n t o t h e c r os s s e c t i on.
12.5.4 Pl ane El as t os t at i c s
An a l y z i n g t h e e l a s t i c e q u i l i b r i u m o f t wo - d i me n s i o n a l b o d i e s s a t i s f y i n g c o n d i t i o n s o f p l a n e s t r e s s o r p l a n e s t r a i n c a n b e r e d u c e d t o d e t e r mi n i n g t wo a n a l y t i c f un c t i o n s. Th e f o r mu l a s t o f i n d t h r e e s t r e s s c o mp o n e n t s a n d t wo d i s p l a c e me n t c o mp o n e n t s a r e mo r e i n v o l v e d t h a n t h e on e s j u s t s t a t e d. Th e y wi l l b e i n v e s t i g a t e d l a t e r wh e n s t r e s s c o n c e n t r a t i o n s i n a p l a t e ha v i n g a c i r c u l a r o r e l l i p t i c h o l e a r e d i s c u s s e d.
12.5.5 Electric Field Intensity
Electromagnetic field theory is concerned with the field intensity e which is de­
scribed in terms of the electrostatic potential E [92] such that
£ — Ex + i Ey — ——-----
θφ ,d φ
dx dy
where φ is a harmonic function at all points not occupied by charge. Consequently a complex electrostatic potential Q(z) exists such that
E = —Q'(z)
The electromagnetic problem is analogous to inviscid incompressible fluid flow prob­
lems. We will also find that harmonic functions remain harmonic under the geometry change of a conformal transformation, which will be discussed later. This produces interesting situations where solutions for new problems can sometimes be derived by simple geometry changes.
12.6 Branch Points and Multivalued Behavior
Before specific types of maps are examined, we need to consider the concept of branchpoints. A type of singular point quite different from isolated singularities such as poles arises when a singular point of F(z) cannot be made the interior of a small circle on which F(z) is single valued. Such singularities are called branch points and the related behavior is typified by functions such as z — zq and log(z — zq). To define p = log(z — z0), we accept any value p such that ep produces the value z — z0. Using polar form we can write
(z — z0) = \z — z0\el^ +2'*k) where θ = arg(z — z0)
wi t h k being any integer. Taking
p = log\z — z0\ + ί(θ + 2nk)
y i e l d s a n i n f i n i t y o f va l u e s a l l s a t i s f y i n g ep = z — z0. Furthermore, if z traverses a counterclockwise circuit around a circle \z — z 0 \ = δ, θ increases by 2π and log(z — z0) does not return to its initial value. This shows that log(z — z 0) is discontinuous on a path containing zq. A similar behavior is exhibited by z — zq, which changes sign for a circuit about \z — z 0 \ = δ.
Fu n c t i o n s wi t h b r a n c h p o i n t s ha v e t h e c h a r a c t e r i s t i c b e h a v i o r t h a t t h e r e l e v a n t f u n c t i o n s a r e d i s c o n t i n u o u s o n c o n t o u r s e n c l o s i n g t h e b r a n c h p o i n t s. Co mp u t i n g t h e f u n c t i o n i nvo l ve s s e l e c t i o n a mo n g a mu l t i p l i c i t y o f p o s s i b l e va l u e s. He n c e a/4 c a n e qu a l +2 or —2, and choosing the proper value depends on the functions involved.
For sake of definiteness MATLAB uses what are called principal branch definitions such that
\[z = \z\ll2 e*0/2 , —π < Θ = tan-1 j < π
and
log(z) = log \z\ + ΐθ
Th e f u n c t i o n s d e f i n e d t h i s wa y ha ve d i s c o n t i n u i t i e s a c r os s t h e n e g a t i v e r e a l axi s. Fu t h e r mo r e, log(z) becomes infinite at z = 0.
Dealing carelessly with multivalued functions can produce strange results. Con­
sider the function
p = \J z2 — 1
which will have discontinuities on lines such that z 2 — 1 = —\h\ , where h is a general parameter. Discontinuity trouble occurs when
z = ±\/l - \h\
Ta ki n g 0 < \h\ < 1 gives a discontinuity line on the real axis between —1 and +1, and taking \h\ > 1 leads to a discontinuity on the imaginary axis.
Figure 12.1
illustrates the odd behavior exhibited by s q r t ( z.~ 2 - 1 ). The reader can easily verify that using
s q r t ( z - 1 ).* s q r t ( z + 1 )
defines a different function that is continuous in the plane cut along a straight line between —1 and +1.
Multivalued functions arise quite naturally in solutions of boundary value prob­
lems, and the choices of branch cuts and branch values are usually evident from physical circumstances. For instance, consider a steady-state temperature problem for the region \z \ < 1 with boundary conditions requiring
u(
1, θ) = I
,O < 0 < 7 T and — ^ —- = 0 , π < θ
< 2π.
dr
It can be shown that the desired solution is
u = real < — [log(z + 1) - log(2: - 1)] 1 + ^ y^i ) 2
wh e r e t h e l o g a r i t h ms mu s t b e d e f i n e d s o u is continuous inside the unit circle and u equals 1/2 at z = 0. Appropriate definitions result by taking
—π < arg(z + 1) < π , 0 < arg(z — 1) < 2π
MATLAB do e s n o t p r o v i d e t hi s d e f i n i t i o n i n t r i n s i c a l l y; s o, t h e u s e r mu s t h a n d l e e a c h p r o b l e m i n d i v i d u a l l y wh e n b r a n c h p o i n t s a r i s e.
Discontinuous Surface for imag( sqrt( z2 - 1 ) )
2
Figure 12.1: Discontinuous Surface for imag (sqrt ( z2 — 1)1/2)
12.7 Conformal Mapping and Harmonic Functions
A transformation of the form
x = χ( ξ,η) , y = y (C,v)
i s s a i d t o b e c o n f o r ma l i f t h e a n g l e b e t we e n i n t e r s e c t i n g c u r v e s i n t h e (ξ, η) plane remains the same for corresponding mapped curves in the (x, y) plane. Consider the transformation implied by z = ω(ζ) where ω is an analytic function of ζ. Since
dz = ω'(ζ) dζ
it follows that
\dz \ = |ω'(ζ)| |dC | and arg(dz) = arg( ω'(ζ)) + a r g d )
Th i s i mp l i e s t ha t t h e e l e me n t o f l e n g t h dC\ is stretched by a factor of ^ '(ζ) \ and the line element dC is rotated by an angle arg^'(ζ)]. The transformation is conformal at all points where ω '(ζ) exists and is nonzero.
Much of the interest in conformal mapping results from the fact that harmonic functions remain harmonic under a conformal transformation. To see why this is true, examine Laplace’s equation written in the form
2 d 2u
V l „ u = 4-
xy dzdz
For a conformal map we have
ζ = ω(0 > ζ = ω ( ζ )
du 1 du du 1 du
dz ω’(ζ) δζ ’ dz ω'(ζ) δζ Since z depends only on ζ and z depends only on ζ we find that
y 2 _ λ 1_______ 32U _ _ J _ V 2
xyU~ ω>(ζγΑζ)8ζ3ζ- \ω>(ζ)\2 U
It follows that
d2u d2u d2u d2u
+ ΊΓ^ϊ = 0 lmPlles = 0
dx2 dy2 ϊ)ξ2 ^η2
wherever ω'(ζ) = 0. The transformed differential equation in the new variables is identical to that of the original differential equation. Hence, when u(x, y) is a har­
monic function of (x, y), then u( x(ξ, η), y (ξ, η)) is a harmonic function of (ξ, η), provided ω(ζ) is an analytic function. This is a remarkable and highly useful prop­
erty. Normally, changing the independent variables in a differential equation changes the form of the equation greatly. For instance, with the polar coordinate transforma­
tion
x = r cos(0), y = r sin(0) the Laplace equation becomes
2 92u 1 du 1 d2u
dr2 r dr r2 d02
Th e a p p e a r a n c e o f t hi s e q u a t i o n i s v e r y d i f f e r e n t f r o m t h e Ca r t e s i a n f o r m b e c a u s e x+i y is not an analytic function of r +ίθ. On the other hand, using the transformation
z = log(C) = log(|C
D + i arg(ζ
)
gives
v Xyu = (cC)^I vu
and V 2xyu = 0 implies y ^ u = 0 at points other than ζ = 0 or ζ = t t.
Be c a u s e s o l u t i o n s t o La p l a c e ’s e q u a t i o n a r e i mp o r t a n t i n p h y s i c a l a pp l i c a t i o ns, a n d s u c h f u n c t i o n s r e ma i n h a r mo n i c u n d e r a c o n f o r ma l ma p, a n a n a l o g y b e t we e n p r o b l e ms i n t wo r e g i o n s o f t e n c a n b e u s e f u l. Th i s i s p a r t i c u l a r l y a t t r a c t i v e f o r p r o b ­
l e ms wh e r e t h e h a r mo n i c f u n c t i o n h a s c o n s t a n t v a l u e s o r z e r o n o r ma l g r a d i e n t on c r i t i c a l b o u n d a r i e s. An i n s t a n c e p e r t a i n i n g t o i n v i s c i d f l u i d f l ow a b o u t a n e l l i p t i c c y l i n d e r wi l l b e u s e d l a t e r t o i l l u s t r a t e t h e h a r mo n i c f u n c t i o n a na l ogy. I n t h e s u b ­
s e q u e n t s e c t i o ns we d i s c u s s s e v e r a l t r a n s f o r ma t i o n s a n d t h e i r r e l e v a n t g e o me t r i c a l i n t e r p r e t a t i o n.
12.8 Mapping onto the Exterior or the Interior of an Ellipse
We will examine in some detail the transformation
C+ ( x ) c 1=j?(c + mi'1) > C > i
wh e r e R = (a + b)/2 and m = (a — b)/(a + b). The derivative
z'(C ) = R(1 — mC-2)
becomes nonconformal when ζ'(ζ) = 0 or ζ = ±i/m. For sake of discussion, we temporarily assume a, > b to make λ/to real rather than purely imaginary. A circle ζ = p0 βιθ transforms into
x + iy = R(p0 + mp-1) cos(O) + iR(p0 — mp-1) sin^)
yielding an ellipse. When p0 = 1 we get x = acos^), y = bsin^). This mapping function is useful in problems such as inviscid flow around an elliptic cylinder or stress concentration around an elliptic hole in a plate. Furthermore, the mapping function is easy to invert by solving a quadratic equation to give
ζ = ί±νΕΞ3ΕΕ3 , α=ν^τρ
a+b
The radical should be defined to have a branch cut on the x-axis from —a to a and to behave like +z for large |z|. Computing the radical in MATLAB as
s q r t ( z - a l p h a ).* s q r t ( z + a l p h a )
works fine when a is real because MATLAB uses
—π < arg(z ± α) < π
a n d t h e s i g n c h a n g e d i s c o n t i n u i t i e s e x p e r i e n c e d b y b o t h f a c t or s o n t h e n e g a t i v e r e a l a xi s c a n c e l t o ma k e t h e p r o d u c t o f r a d i c a l s c o n t i n u o u s. Ho we ve r, wh e n a, < b the branch points occur at ± z o where zq = i^/b2 — a2, and a branch cut is needed along the imaginary axis. We can give a satisfactory definition by requiring
π 3π
- - < &rg(z ± zo) < —
Th e f u n c t i o n e l i p i n v r p r o v i d e d b e l o w h a n d l e s g e n e r a l a and b.
Before leaving the problem of ellipse mapping we mention the fact that mapping the interior of a circle onto the interior of an ellipse is rather complicated but can be formulated by use of elliptic functions [75]. However, a simple solution to compute boundary point correspondence between points on the circle and points on the ellipse
appears in [52]. This can be used to obtain mapping functions in rational form which are quite accurate. The function elipdplt produces the mapping. Results showing how a polar coordinate grid in the ζ-plane maps onto a two to one ellipse appears in
Figure 12.2.
In these examples and other similar ones, grid networks in polar coordinates always use constant radial increments and constant angular increments. Only the region corresponding to 0.3 < |£| < 1 andO < axg(C) < f is shown. Note that the distortion of line elements at different points of the grid is surprisingly large. This implies that the stretching effect, depending on Ιω '(ζ) | ,varies more than might at first be expected.
Often it is desirable to see how a rectangular or polar coordinate grid distorts under a mapping transformation. This is accomplished by taking the point arrays and simultaneously plotting rows against rows and columns against columns as computed by the following function gridview which works for general input arrays x,y. If the input data are vectors instead of arrays, then the routine draws a single curve instead of a surface. When gridview is executed with no input, it generates the plot in Figure 12.3 which shows how a polar coordinate grid in the ζ-plane maps under the transformation
The new grid consists of a system of confocal ellipses orthogonally intersecting a system of hyperbolas.
y axis
Mappi ng abs( ZETA) <1 onto an E l li p t i c Di sk
x axis
Figure 12.2: Mapping |z| < 1
onto an Elliptic Disk
5
4
3
2
1
0
1
2
3
4
5
C i r c u l a r A n n u l u s M a p p e d o n t o a n E l l i pt i c al A n n u l u s
5 - 4 - 3 - 2 - 1 0 1 2 3 4 5
real axi s
rcular Annulus Mapped onto an Elliptic Annulus
12.8.1 Program Output and Code Function sqrtsurf
f u n c t i o n s q r t s u r f %
% s q r t s u r f %
% T h i s f u n c t i o n i l l u s t r a t e s t h e d i s c o n t i n u i t y % i n t h e f u n c t i o n w = s q r t ( z * z - 1 ).
x x = l i n s p a c e ( - 2,2,4 1 ); [ x,y ] = m e s h g r i d ( x x,x x ); z = x + i * y; w = s q r t ( z.* z - 1 ); c l o s e s u r f ( x,y,i m a g ( w ) ); v i e w ( - 4 0,5 0 ); x l a b e l ('r e a l a x i s'); y l a b e l ('i m a g i n a r y a x i s'); z l a b e l ('i m a g ( s q r t ( z ~ 2 - 1 ) )'); t i t l e ( ['D i s c o n t i n u o u s S u r f a c e f o r imag( s q r t', '( z~2 - 1 ) )'] ); g r i d on; f i g u r e ( g c f );
% p r i n t - d e p s s q r t s u r f
Function elipinvr
f u n c t i o n z e t a = e l i p i n v r ( a,b,z )
%
% z e t a = e l i p i n v r ( a,b,z )
%~~~~~~~~~~~~~~~~~~~~
%
% T h i s f u n c t i o n i n v e r t s t h e t r a n s f o r m a t i o n % z = ( a + b )/2 * z e t a + ( a - b )/2/z e t a whi ch maps % a b s ( z e t a ) > = 1 o n t o ( x/a ).~ 2 + ( y/b ).~ 2 >= 1 %
% a - s e m i - d i a m e t e r on x - a x i s
% b - s e m i - d i a m e t e r on y - a x i s
% z - a r r a y o f complex v a l u e s
%
% z e t a - a r r a y o f complex v a l u e s f o r t h e
% i n v e r s e mapping f u n c t i o n
%
% U s e r m f u n c t i o n s c a l l e d: n o n e
19: z 0 = s q r t ( a ~ 2 - b ~ 2 ); ab=a+b;
20: i f a==b 21: z e t a = z/a;
22: e l s e i f a>b % b r a n c h c u t a l o n g t h e r e a l a x i s 23: z e t a = ( z + s q r t ( z - z 0 ).* s q r t ( z + z 0 ) )/a b;
24: e l s e % b r a n c h c u t a l o n g t h e i m a g i n a r y a x i s
25: a p = a n g l e ( z + z 0 ); a p = a p + 2 * p i * ( a p < = - p i/2 );
26: a m = a n g l e ( z - z 0 ); am=a m+ 2*pi*( am <=-pi/2);
27: z e t a = ( z + s q r t ( a b s ( z.~ 2 - z 0. ~2) ).* e x p (. ..
28: i/2 * ( a p + a m ) ) )/a b;
29: end
Function elipdplt
1: f u n c t i o n [ z,a,b ] = e l i p d p l t ( r x,r y )
2: % [ z,a,b ] = e l i p d p l t ( r x,r y )
3: % ~~~~~~~~~~~~~~~~~~~~~~~
4: % T h i s f u n c t i o n p l o t s c o n t o u r l i n e s showing
5: % how a p o l a r c o o r d i n a t e g r i d i n a c i r c u l a r
6: % d i s k maps o n t o an e l l i p t i c d i s k.
7: %
8: % U s er m f u n c t i o n s c a l l e d: e l i p d i s k, g r i d v i e w
9:
1 0: i f n a r g i n = = 0, r x = 2; r y = 1; end 11: z e t a = l i n s p a c e (.3,1,1 2 )'* ...
12: e x p ( i * l i n s p a c e ( 0,p i/2,6 1 ) );
13: [ z,a,b ] = e l i p d i s k ( z e t a,r x,r y );
14: x = r e a l ( z ); y = i m a g ( z );
15: g r i d v i e w ( x,y,'x a x i s','y a x i s',...
16: 'Mapping abs(ZETA)<1 o n t o an E l l i p t i c D i s k');
17: c o l o r m a p ( [ 1 1 1 ] ); s h g 18: p r i n t - d e p s e l i p d i s k
19:
20: %=============================================
21:
2 2: f u n c t i o n g r i d v i e w ( x,y,x l a b l,y l a b l,t i t l )
23: %
24: % g r i d v i e w ( x,y,x l a b l,y l a b l,t i t l )
25: % ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
26: %
27: % T h i s f u n c t i o n v i e w s a s u r f a c e f r o m t h e t o p
28:
29:
30:
31:
32
33:
34
35
36
37:
38
39
40:
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
% t o show t h e c o o r d i n a t e l i n e s o f t h e s u r f a c e.
% I t i s u s e f u l f o r i l l u s t r a t i n g how c o o r d i n a t e % l i n e s d i s t o r t u n d e r a c o n f o r m a l t r a n s f o r m a t i o n. % C a l l i n g g r i d v i e w w i t h no a r g u m e n t s d e p i c t s t h e % mapping o f a p o l a r c o o r d i n a t e g r i d map u n d e r % a t r a n s f o r m a t i o n o f t h e for m % z = R * ( z e t a + m/z e t a ).
%
% x,y - r e a l m a t r i c e s d e f i n i n g a
% c u r v i l i n e a r c o o r d i n a t e s y s t e m
% x l a b l,y l a b l - l a b e l s f o r x and y a x e s % t i t l - t i t l e f o r t h e g r a p h
%
% U s er m f u n c t i o n s c a l l e d: c u b r a n g e
%-----------------------------------------------------------------------------------------
% c l o s e i f n a r g i n < 5
x l a b l ='r e a l a x i s'; y l a b l ='i m a g i n a r y a x i s'; t i t l =''; end
% D e f a u l t example u s i n g z = R * ( z e t a + m/z e t a ) i f n a r g i n = = 0
z e t a = l i n s p a c e ( 1,3,1 0 )'* ...
e x p ( i * l i n s p a c e ( 0,2 * p i,8 1 ) ); a=2; b=1; R = ( a + b )/2; m = ( a - b )/( a + b ); z = R * ( z e t a + m./z e t a ); x = r e a l ( z ); y = i m a g ( z ); t i t l = ['C i r c u l a r Annulus Mapped o n t o an ', ...
'E l l i p t i c a l A n n u l u s'];
end
r a n g e = c u b r a n g e ( [ x (:),y (:) ],1.1 );
% The d a t a d e f i n a c u r v e i f s i z e ( x,1 ) = = 1 | s i z e ( x,2 ) = = 1
p l o t ( x,y,'- k'); x l a b e l ( x l a b l ); y l a b e l ( y l a b l ); t i t l e ( t i t l ); a x i s ('e q u a l'); a x i s ( r a n g e ); g r i d on; f i g u r e ( g c f ); i f n a r g i n = = 0
p r i n t - d e p s g r i d v i e w l end
% The d a t a d e f i n a s u r f a c e e l s e
p l o t ( x,y,'k -',x',y','k -')
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
x l a b e l ( x l a b l ); y l a b e l ( y l a b l ); t i t l e ( t i t l ); a x i s ('e q u a l'); a x i s ( r a n g e ); g r i d on; f i g u r e ( g c f ); i f n a r g i n = = 0
p r i n t - d e p s g r i d v i e w end end
%=============================================
f u n c t i o n [ z,a,b ] = e l i p d i s k ( z e t a,r x,r y )
%
% [ z,a,b ] = e l i p d i s k ( z e t a,r x,r y )
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~
%
% T h i s f u n c t i o n computes a r a t i o n a l f u n c t i o n % mapping a b s ( z e t a ) < = 1 o n t o an e l l i p t i c a l d i s k % d e f i n e d by ( x/r x ) ~ 2 + ( y/r y ) ~ 2 < = 1. Boundary % p o i n t s a r e computed u s i n g t h e o r y fr o m % P. H e n r i c i, A p p l i e d Complex A n a l y s i s,
% Vol 3, p391.
% The r a t i o n a l f u n c t i o n a p p r o x i m a t i o n h a s t h e % f or m:
% z = s u m ( a ( j ) * z e t a ~ ( 2 * j - 1 ) ) /
% ( 1 + s u m ( b ( j ) * z e t a ~ ( 2 * j ) );
%
% z e t a - m a t r i x o f p o i n t s w i t h a b s ( z e t a ) < = 1
% r x,r y - e l l i p s e s e m i d i a m e t e r s on x and y
% a x e s
%
% z - p o i n t s i n t o whi ch z e t a maps
% a,b - c o e f f i c i e n t s i n t h e r a t i o n a l
% f u n c t i o n d e f i n i n g t h e map
%
% U s er m f u n c t i o n s c a l l e d: r a t c o f %
-----------------------------------------------------------------------------------------
n t r m s = 1 0 0; n t h e t a = 2 5 1;
t a u = ( 0:2 * p i/n t h e t a:2 * p i )';
e p = ( r x - r y )/( r x + r y );
z = e x p ( i * t a u ); z = z + e p * c o n j ( z );
j = 1:n t r m s; e p = e p.~ j; e p = e p./( j.* ( 1 + e p.* e p ) );
t h e t a = t a u + 2 * ( s i n ( ( 2 * t a u + p i ) * j ) * e p');
z t a = e x p ( i * t h e t a ); z = r x/m a x ( r e a l ( z ) ) * z;
[ a,b ] = r a t c o f ( z t a.~ 2,z./z t a,8 );
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
a = f i x ( r e a l ( 1 e 8 * a ) )/1 e 8; b = f i x ( r e a l ( 1 e 8 * b ) )/1 e 8; a f = f l i p u d ( a (:) ); b f = f l i p u d ( [ 1;b (:) ] ); z t a 2 = z e t a.~ 2;
z = z e t a.* p o l y v a l ( a f,z t a 2 )./p o l y v a l ( b f,z t a 2 ); %=============================================
f u n c t i o n [ a,b ] = r a t c o f ( x d a t a,y d a t a,n t o p,n b o t )
%
% [ a,b ] = r a t c o f ( x d a t a,y d a t a,n t o p,n b o t )
%..........................................................................................
%
% D e t e r m i n e a and b t o a p p r o x i m a t e y d a t a a s % a r a t i o n a l f u n c t i o n o f t h e v a r i a b l e x d a t a.
% The f u n c t i o n h a s t h e f or m:
%
% y ( x ) = sum(1=>ntop) ( a ( j ) * x ~ ( j - 1 ) ) /
% ( 1 + sum(1=>nbot) ( b ( j ) * x ~ ( j ) ) )
%
% x d a t a,y d a t a - i n p u t d a t a v e c t o r s ( r e a l o r % complex)
% n t o p,n b o t - number o f s e r i e s t e r m s u s e d i n
% t h e n u m e r a t o r and t h e
% d e n o m i n a t o r.
%
% U s er m f u n c t i o n s c a l l e d: none %-----------------------------------------------------------------------------------------
y d a t a = y d a t a (:); x d a t a = x d a t a (:);
m = l e n g t h ( y d a t a );
i f n a r g i n = = 3, n b o t = n t o p; en d;
x = o n e s ( m,n t o p + n b o t ); x (:,n t o p + 1 ) = - y d a t a.* x d a t a; f o r i = 2:n t o p, x (:,i ) = x d a t a.* x (:,i - 1 ); end f o r i = 2:n b o t
x (:,i + n t o p ) = x d a t a.* x (:,i + n t o p - 1 ); end
a b = x\y d a t a;
a = a b ( 1:n t o p ); b = a b ( n t o p + 1:n t o p + n b o t ); %==============================================
% f u n c t i o n r a n g e = c u b r a n g e ( x y z,o v r s i z )
% See Appe ndix B
12.9 Linear Fractional Transformations
The mapping function defined by
az + b cz + d
w =
i s c a l l e d a l i n e a r f r a c t i o n a l, o r b i l i n e a r, t r a n s f o r ma t i o n wh e r e a, b, c, a n d d are con­
stants. It can be inverted to yield
-dw + b
z = -----------
cw - a
If c is zero the transformation is linear. Otherwise, we can divide out c to get
Az + B w =
-------—
z + D
The three remaining constants can be found by making three points in the z -plane map to three given points in the w-plane. Note that z = t o maps to w = A and z = —D maps to w = to.
Th e t r a n s f o r ma t i o n ha s t h e a t t r a c t i v e p r o p e r t y t h a t c i r c l e s o r s t r a i g h t l i n e s ma p i n t o c i r c l e s o r s t r a i g h t l i ne s. An e q u a t i o n de f i n i n g a c i r c l e o r s t r a i g h t l i n e i n t h e z - p l a n e h a s t h e f o r m
Pz z + Qz + Qz + S = 0
where P and S are real. A straight line is obtained when P is zero. Expressing z in terms of w and clearing fractions leads to an equation of the form
Po ww + Qow + Q owo + So = 0
which defines a circle in the w-plane when Po
is nonzero. Otherwise, a straight line in the w-plane results.
Determining the bilinear transformation to take three z-points to three w-points is straightforward except for special cases. Let
Z = [ z 1;z 2;z 3 ] and W=[w1;w2;w3]
If d e t ( [ Z,W,o n e s ( 3,1 ) ] ) vanishes then a linear transformation with c = 0 and d = 1 applies. If z = t o maps to wi we take a = wi, c = 1. If z = zi maps to w = t o we take c = 1, d = —z 1. In the usual situation we simply write w(z + D) = Az + B and solve the system
[ Z,o n es (3,1 ),-W ] * [A;B;D ]= W.* Z
Function linfrac, used to compute the coefficients in the transformation, is pro­
vided at the end of this section. Points at infinity are handled by including t o (repre­
sented in MATLAB by i n f ) as a legitimate value in the components of z or w. For example, the transformation w = (2z + 3)/(z — 1) takes z = t o to w = 2, z = 1 to w = to, and z = 1 + i to w = 2 — 5i. The expression
c z = l i n f r a c ( [ i n f,1,1 + i ],[ 2,i n f,2 - 5 i ] );
produces the coefficients in the transformation. Similarly, the transformation is in­
verted by
c w = l i n f r a c ( [ 2,i n f,2 - 5 i ],[ i n f,1,1 + i ] );
or equivalently by
c w = l i n f r a c ( [ 0,1,2 i ],[ - 1.5,- 4,- 0.2 5 - 1.2 5 i ] );
Another type of problem of interest in connection with a known bilinear transfor­
mation is to find the circle or straight line into which a given circle or straight line maps. Function crc2crc performs this task. The coefficients c are given along with three points lying on a circle or a straight line. Then parameters w o,r o pertaining to the w-plane are computed. If parameter t y p e equals 1, then w o and ro specify the center and radius of a circle. Otherwise, w o and ro are two points defining a straight line.
The linear fractional transformation can be used to map an eccentric annulus such as that in
Figure 12.4 onto a concentric annulus. Suppose a region 1 < \z\ < R is to be mapped onto the region defined by
\w\ > Ri , \w — wo\< Ro
Th e r a d i u s R and mapping coefficients c can be obtained by solving a system of non­
linear simultaneous equations. Function ecentric accomplishes the task. A function call of
[ c,r ] = e c e n t r i c ( 0.2 5,- 0.2 5,1 );
produces
3.4821s+ 0.25 D o ^
ιυ = ------------------- , R = 3.7321
s + 13.9282 ’
and the plot in Figure 12.4 shows the mapped image of a polar coordinate grid using
C o n c e n t r i c An n u l u s M appe d on t o Ec c e n t r i c A n n u l u s
Figure 12.4: Concentric Annulus Mapped onto Eccentric Annulus
constant radial and angular increment in the z plane.
To demonstrate the utility of the transformation just discussed, consider the prob­
lem of determining the steady-state temperature field in an eccentric annulus with the inner and outer boundaries held at u i and u0, respectively. The temperature field will be a harmonic function that remains harmonic under a conformal transforma­
tion. The related problem for the concentric annulus has the simple form
u = ui +
(m0 - mi ) ln(r) ln(i?)
1 < r < R
r e a l a x i s
By a na l og y, e x p r e s s i n g r = \z\
in terms of w
gives the temperature distribution at points in the w-plane.
12.9.1 Program Output and Code Function linfrac
f u n c t i o n c = l i n f r a c ( z,w )
%
% c = l i n f r a c ( z,w )
%% ~~~~~~~~~~~~~~
% T h i s f u n c t i o n d e t e r m i n e s t h e l i n e a r % f r a c t i o n a l t r a n s f o r m a t i o n t o map any t h r e e % p o i n t s i n t h e z - p l a n e i n t o any t h r e e p o i n t s % i n t h e w p l a n e. Not more t h a n one p o i n t i n % e i t h e r t h e z o r w p l a n e may be l o c a t e d a t % i n f i n i t y.
%
% z - v e c t o r o f complex v a l u e s [ z 1,z 2,z 3 ]
% w - v e c t o r o f complex v a l u e s [w1,w2,w3]
%
% c - v e c t o r d e f i n i n g t h e b i l i n e a r % t r a n s f o r m a t i o n
% w = ( c ( 1 ) * z + c ( 2 ) )/( c ( 3 ) * z + c ( 4 ) )
%
% U s er m f u n c t i o n s c a l l e d: none
%---------------------------------------------------------------------------------------
z = z (:); w =w (:); c = o n e s ( 4,1 ); k = f i n d ( z = = i n f ); j = f i n d ( w = = i n f ); k j = [ k;j ];
% z and w b o t h c o n t a i n p o i n t s a t i n f i n i t y i f l e n g t h ( k j ) = = 2
c ( 1 ) = w ( k ); c ( 4 ) = - z ( j ); w ( k j ) = [ ]; z ( k j ) = [ ]; c ( 2 ) = ( w - c ( 1 ) ) * z + w * c ( 4 ); r e t u r n end
% z = i n f i n i t y maps t o a f i n i t e w p o i n t i f ~ i s e m p t y ( k ) & i s e m p t y ( j ) c ( 1 ) = w ( k ); z ( k ) = [ ]; w(k) = [ ]; c ( [ 2 4 ] ) = [ [ 1;1 ],- w ]\[ ( w - c ( 1 ) ).* z ]; r e t u r n end
% a f i n i t e z p o i n t maps t o w = i n f i n i t y
41: i f ~ i s e m p t y ( j ) & i s e m p t y ( k )
42: c ( 4 ) = - z ( j ); z ( j ) = [ ]; w ( j ) = [ ];
43: c ( [ 1 2 ] ) = [ z,[ 1;1 ] ]\[ w.* ( z + c ( 4 ) ) ] ;
44: r e t u r n
45: end
46:
47: % c a s e where a l l p o i n t s a r e f i n i t e 48: m a t = [ z,o n e s ( 3,1 ),- w ];
49:
50: % c a s e f o r a g e n e r a l t r a n s f o r m a t i o n
51: i f d e t ( m a t ) ~ = 0
5 2: c ( [ 1 2 4 ] ) = m a t\[ w.* z ];
53: % c a s e where t r a n s f o r m a t i o n i s l i n e a r 54: e l s e
5 5: c ( 3 ) = 0; c ( [ 1 2 ] ) = [ z,o n e s ( 3,1 ) ]\w;
56: end
Function crc2crc
f u n c t i o n [ w 0,r 0,t y p e ] = c r c 2 c r c ( c,z ) %
% [ w 0,r 0,t y p e ] = c r c 2 c r c ( c,z )
%................................................................
%
T h i s f u n c t i o n d e t e r m i n e s t h e c i r c l e o r s t r a i g h t l i n e i n t o whi ch a c i r c l e o r s t r a i g h t l i n e maps u n d e r a l i n e a r f r a c t i o n a l t r a n s f o r m a t i o n.
c - c o e f f i c i e n t s d e f i n i n g a l i n e a r
f r a c t i o n a l t r a n s f o r m a t i o n
w = ( c ( 1 ) * z + c ( 2 ) )/( c ( 3 ) * z * c ( 4 ) ) where c ( 2 ) * c ( 3 ) - c ( 1 ) * c ( 4 ) i s n o n z e r o z - a v e c t o r o f t h r e e complex v a l u e s
l y i n g on a c i r c l e o r a s t r a i g h t l i n e
w0
r 0
t y p e
c e n t e r o f a c i r c l e i n t h e w p l a n e i f t y p e = 1, o r a p o i n t on a s t r a i g h t l i n e i f t y p e = 2
r a d i u s o f a c i r c l e i n t h e w p l a n e i f t y p e = 1, o r a p o i n t on a s t r a i g h t l i n e i f t y p e = 2
e q u a l s 1 t o d e n o t e a c i r c l e o r 2 t o
25: % d e n o t e a s t r a i g h t l i n e i n t h e w p l a n e
26: %
2 7: % U s er m f u n c t i o n s c a l l e d: none
28: %---------------------------------------------------------------------------------------------------------------------------------------------------------
29:
30: % c h e c k f o r d e g e n e r a t e t r a n s f o r m a t i o n 31: i f c ( 2 ) * c ( 3 ) = = c ( 1 ) * c ( 4 )
3 2: d i s p ( ['D e g e n e r a t e t r a n s f o r m a t i o n i n ', ...
33: 'f u n c t i o n c r c 2 c r c'] );
34: w 0 = [ ]; r 0 = [ ]; t y p e = [ ]; r e t u r n;
35: end
36:
37: % e v a l u a t e t h e mapping o f t h e z p o i n t s 38: w = ( c ( 1 ) * z (:) + c ( 2 ) )./( c ( 3 ) * z (:) + c ( 4 ) );
39:
40: % c h e c k w h e t h e r a p o i n t p a s s e s t o i n f i n i t y o r 41: % t h e t h r e e z p o i n t s d e f i n e a s t r a i g h t l i n e 42: k = f i n d ( w = = i n f );
43: d t = d e t ( [ r e a l ( w ),i m a g ( w ),o n e s ( 3,1 ) ] );
44: i f ~ i s e m p t y ( k ); w(k) = [ ]; end
45:
46: % c a s e f o r a s t r a i g h t l i n e i n t h e w p l a n e
47: % d e f i n e d by two p o i n t s on t h e l i n e
48: i f dt==0 | ~ i s e m p t y ( k )
49: t y p e = 2; w0=w(1); r 0 = w ( 2 );
50: % c a s e f o r a c i r c l e i n t h e w p l a n e d e f i n e d by
51: % a c e n t e r p o i n t and t h e c i r c l e r a d i u s
5 2: e l s e 53: t y p e =1;
54: v = [ 2 * r e a l ( w ),2 * i m a g ( w ),o n e s ( 3,1 ) ]\a b s ( w ) .~ 2;
55: w 0 = v ( 1 ) + i * v ( 2 ); r 0 = s q r t ( v ( 3 ) + a b s ( w 0 ) ~ 2 );
56: end
Function ecentric
i: f u n c t i o n [ c,r ] = e c e n t r i c ( r i,w o,r o,n o p l )
2: %
3: % [ c,r ] = e c e n t r i c ( r i,w o,r o,n o p l )
4: %...........................................................................................................
5: %
6: % T h i s f u n c t i o n d e t e r m i n e s t h e b i l i n e a r 7: % t r a n s f o r m a t i o n whi ch maps t h e r e g i o n 8: % 1 < = a b s ( z ) < = r o n t o an e c c e n t r i c a n n u l u s
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
35
36
37:
38
39
40:
41:
42
43:
44
45
46
47:
48
% d e f i n e d by
% a b s ( w ) > = r i & a bs ( w -w o) <=ro
%
% The c o e f f i c i e n t s c i n t h e t r a n s f o r m a t i o n % w = ( c ( 1 ) * z + c ( 2 ) )/( c ( 3 ) * z + c ( 4 ) )
% must be f o u n d a s w e l l a s t h e o u t e r r a d i u s r % o f t h e a n n u l u s i n t h e z p l a n e.
%
% r i - r a d i u s o f i n n e r c i r c l e a b s ( w ) = r i
% wo - c e n t e r o f o u t e r c i r c l e a b s ( w - w o ) = r o
% r o - r a d i u s o f o u t e r c i r c l e
%
% c - c o e f f i c i e n t s i n t h e mapping f u n c t i o n
% r - r a d i u s o f o u t e r c i r c l e a b s ( z ) = r
% n o p l - no p l o t i s g i v e n i f n o p l i s i n p u t %
% U s er m f u n c t i o n s c a l l e d: g r i d v i e w i f n a r g i n = = 0, r i =.2 5; w o = -.2 5; r o = 1; end i f wo~=0
c 1 = ( w o + r o )/r i; c 2 = ( w o - r o )/r i; c 3 = 2/( c 1 + c 2 ); c 4 = ( c 2 - c 1 )/( c 1 + c 2 ); c 5 = c 3 - c 1 - c 1 * c 4; c 6 = 1 - c 1 * c 3; r t = s q r t ( c 5 ~ 2 - 4 * c 4 * c 6 ); r 1 = ( - c 5 + r t )/( 2 * c 4 ); r 2 = ( - c 5 - r t )/( 2 * c 4 ); r = m a x ( [ r 1,r 2 ] ); d = c3 + c 4 * r; c = [ r i * d;r i;1;d ]; e l s e
c = [ r i;0;0;1 ]; r = r o/r i; end
i f n a r g i n > 3, r e t u r n, end
% Show t h e r e g i o n o n t o whi ch a p o l a r c o o r d i n a t e % g r i d i n t h e z - p l a n e maps.
z = l i n s p a c e ( 1,r,2 0 )'* e x p ( i * l i n s p a c e ( 0,2 * p i,8 1 ) ); w = ( c ( 1 ) * z + c ( 2 ) )./( c ( 3 ) * z + c ( 4 ) ); t i t l = ['C o n c e n t r i c Annulus Mapped o n t o ', ...
'E c c e n t r i c A n n u l u s']; g r i d v i e w ( r e a l ( w ),i m a g ( w ),...
'r e a l a x i s','i m a g i n a r y a x i s',t i t l ); s h g % p r i n t - d e p s e c e n t r i c
12.10 Schwarz-Christoffel Mapping onto a Square
The Schwarz-Christoffel transformation [75] provides integral formulas defining transformations to map the interior of a circle onto the interior or exterior of a poly­
gon. Special cases obtained by allowing selected vertices to pass to infinity lead to a variety of results [58]. In general situations, evaluating the parameters and inte­
grals in the Schwarz-Christoffel transformation is difficult and requires use of special software [35]. We will examine only two cases: a) where the interior of a circle is mapped onto the interior of a square, and b) where the exterior of a circle is mapped onto the exterior of a square. The function
A reasonably good approximation to the mapping function can be obtained by tak­
ing several hundred terms in the mapping function and adjusting the constant c to make C = 1 match z = 1. This series expansion converges slowly and rounds the corners of the square because the derivative of the mapping function behaves like
where c0 and ci are arbitrary constants. Using the binomial expansion again and term by term integration leads to
where C is a scaling constant, maps |C | < 1 inside the square defined by
( M < 1 ) n (IyI<1).
Ex p a n d i n g t hi s r a d i c a l b y t h e b i n o mi n a l e x p a n s i o n a n d i n t e g r a t i n g gi ves
(C - Co)-1/2 at Co = ±e±ln/4.
Th e t r a n s f o r ma t i o n t o ma p | C | > 1 o n t o t h e s q u a r e e x t e r i o r d e f i n e d b y
( XI > 1) U (IyI > 1)
has the form
The function swcsqmap provides both interior and exterior polynomial maps. Once again, truncating the series after a specified number of terms and making C = 1 map to z = 1 gives an approximate mapping function which converges much more
rapidly than the series for the interior problem. Rounding of the square corners is greatly reduced because the mapping function derivative behaves like (C — C o)1/2 at Co = ±e±in/4. Figure 12.5 illustrates results produced by the ten term series for both interior and exterior regions. Using rational functions to produce better results than polynomials was discussed earlier in Chapter 3. The function squarat, which provides both interior and exterior maps, appears below.
It should be noted that inverting a mapping function z = ^(C) to get C = g(z) explicitly is often difficult, if not impossible. For example, consider the form
C (a + bC4 + cC8)
ICI<1
1 + dC4 + eC8 which requires solving the polynomial
cC9 — ezC8 + bC5 — dzC4 + aC — z = 0
and picking the root inside or on the unit circle. Although the MATLAB function roots efficiently factors polynomials with complex coefficients, inverting the map­
ping function for hundreds or thousands of values can be time consuming.
Figure 12.5:
Interior Map of a Square Using a 10-term Series
0 0.5 1
x axis
Exterior Map of a Square Using a 10-term Series
x axis
Square Maps Using a 10-term Series
12.10.1 Program Output and Code Function swcsq10
i: f u n c t i o n swcsq10 2: % Example: swcsq10
3: %......................................................................
4: %
5: % T h i s example d e m o n s t r a t e s s q u a r e map 6: % a p p r o x i m a t i o n s p e r t a i n i n g t o t r u n c a t e d 7: % S c h w a r z - C h r i s t o f f e l t r a n s f o r m a t i o n s.
8: %
9: % U s er m f u n c t i o n s c a l l e d: swcsqmap, g r i d v i e w
10:
i i: z e t a = l i n s p a c e ( 0.2,1,8 )'* ... i 2: e x p ( i * l i n s p a c e ( 0,p i/2,6 1 ) );
i 3: [ z,a ] = s w c s q m a p ( z e t a,1 0 ); i 4: s u b p l o t ( 2 1 1 )
i 5: g r i d v i e w ( r e a l ( z ),i m a g ( z ),'x a x i s','y a x i s', ... i 6: ['I n t e r i o r Map o f a S q u a r e U s i n g', ...
i 7: ' a 1 0 - t e r m S e r i e s'] );
i 8: s u b p l o t ( 2 1 2 )
i 9: z e t a = l i n s p a c e ( 1,1.2 5,8 )'* ...
2 0: e x p ( i * l i n s p a c e ( 0,p i/2,6 1 ) );
2 i: [ z 0,a ] = s w c s q m a p ( z e t a,1 0,1 );
2 2: g r i d v i e w ( r e a l ( z 0 ),i m a g ( z 0 ),'x a x i s','y a x i s', ... 23: ['E x t e r i o r Map o f a S q u a r e U s i n g ', ...
24: 'a 1 0 - t e r m S e r i e s'] );
25: p r i n t - d e p s s q r p l t 1 0 2 6: s u b p l o t
27:
28: %=============================================
29:
30: f u n c t i o n [ z,a ] = s w c s q m a p ( z e t a,n t r m s,i f o u t )
3 i: %
3 2: % [ z,a ] = s w c s q m a p ( z e t a,n t r m s,i f o u t )
33: %
34: %
35: % T h i s f u n c t i o n e v a l u a t e s power s e r i e s
36: % a p p r o x i m a t i o n s f o r mapping e i t h e r t h e i n s i d e
37: % o f a c i r c l e o n t o t h e i n s i d e o f a s q u a r e, o r
38: % mapping t h e o u t s i d e o f a c i r c l e o n t o t h e
3 9: % o u t s i d e o f a s q u a r e. The S c h w a r z - C h r i s t o f f e l
40: % i n t e g r a l s d e f i n i n g t h e mapping f u n c t i o n s a r e
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
74
75
76
77
78
79
80
81
82
83
84
% ex p a n d ed i n T a y l o r s e r i e s and a r e t r u n c a t e d % t o p r o d u c e a p p r o x i m a t i o n s i n t h e f o l l o w i n g % p o l y n o m i a l f o r m s:
%
% F o r t h e i n t e r i o r p r o b l e m:
% z = s u m ( a ( n ) * z e t a ~ ( 4 * n - 3 ),n = 1:n t r m s )
%
% F o r t h e e x t e r i o r p r o b l e m:
% z = s u m ( a ( n ) * z e t a ~ ( - 4 * n + 5 ),n = 1:n t r m s )
%
% The s i d e l e n g t h o f t h e s q u a r e i s a d j u s t e d % t o e q u a l 2.
%
% z e t a - complex v a l u e s where t h e mapping % f u n c t i o n i s e v a l u a t e d
% n t r m s - number o f t e r m s u s e d i n t h e % t r u n c a t e d s e r i e s
% i f o u t - a p a r a m e t e r o m i t t e d i f an i n t e r i o r % map a p p l i e s. i f o u t ca n h a v e any
% v a l u e ( s u c h a s 1) t o show t h a t an
% e x t e r i o r map i s t o be p e r f o r m e d.
%
% z - v a l u e s o f t h e mapping f u n c t i o n
% a - c o e f f i c i e n t s i n t h e mapping s e r i e s
%
% U s er m f u n c t i o n s c a l l e d: none
%---------------------------------------------------------------------------------------
n = 0:n t r m s - 2;
i f n a r g i n = = 2 % r e c u r s i o n f o r m u l a f o r mapping % i n t e r i o r on i n t e r i o r p 1 = ( n + 1/2 )./( n + 1 ); p 2 = ( n + 1/4 )./( n + 5/4 ); e l s e % r e c u r s i o n f o r m u l a f o r mapping
% e x t e r i o r on e x t e r i o r p 1 = ( n - 1/2 )./( n + 1 ); p 2 = ( n - 1/4 )./( n + 3/4 );
end
a = [ 1,c u m p r o d ( - p 1.* p 2 ) ]; a = a (:)/s u m ( a ); z 4 = z e t a.~ 4;
i f n a r g i n ==3, z 4 = 1./z 4; en d; z = z e t a.* p o l y v a l ( f l i p u d ( a (:) ),z 4 );
%=============================================
% f u n c t i o n g r i d v i e w ( x,y,x l a b l,y l a b l,t i t l )
85: % See Appendix B
Function squarat
f u n c t i o n [ z,a,b ] = s q u a r a t ( z e t a,i f o u t )
%
% [ z,a,b ] = s q u a r a t ( z e t a,i f o u t )
%.....................................................................
%
% T h i s f u n c t i o n maps e i t h e r t h e i n t e r i o r o f a % c i r c l e o n t o t h e i n t e r i o r o f a s q u a r e, o r maps % t h e e x t e r i o r o f a c i r c l e o n t o t h e e x t e r i o r of % a s q u a r e u s i n g a r a t i o n a l f u n c t i o n h a v i n g t h e % a p p r o x i m a t e f or m:
%
% z ( z e t a ) = z e t a *
%
% S u m ( a ( j ) * z e t a 4 ~ j )/( 1 + S u m ( b ( j ) * z e t a 4 ~ j ),
%
% where z e t a 4 = z e t a ~ 4 f o r an i n t e r i o r p r o b l e m,
% o r z e t a 4 = z e t a ~ ( - 4 ) f o r an e x t e r i o r p r o b l e m.
%
% z e t a - m a t r i x o f complex v a l u e s s u c h t h a t
% a b s ( z e t a ) < = 1 f o r an i n t e r i o r map,
% o r a b s ( z e t a ) > = 1 f o r an e x t e r i o r map
% i f o u t - p a r a m e t e r p r e s e n t i n t h e c a l l l i s t
% o n l y when an e x t e r i o r mapping i s
% r e q u i r e d
%
% z - m a t r i x o f v a l u e s o f t h e mapping % f u n c t i o n
% a,b - c o e f f i c i e n t s o f t h e p o l y n o m i a l s
% d e f i n i n g t h e r a t i o n a l mapping
% f u n c t i o n
%
% U s er m f u n c t i o n s c a l l e d: none %
-----------------------------------------------------------------------------------------
z e t a 4 = z e t a.~ 4;
i f n a r g i n = = 1 % map i n t e r i o r on i n t e r i o r
a = [ 1.0 7 8 3 5, 1.3 7 7 5 1,- 0.0 2 6 4 2, - 0.0 9 1 2 9, ... 0.1 3 4 6 0,- 0.1 5 7 6 3, 0.0 7 4 3 0, 0.1 4 8 5 8, ...
0.0 1 8 7 8,- 0.0 0 3 5 4 ]'; b = [ 1.3 7 7 4 3, 0.0 7 1 5 7,- 0.1 1 0 8 5, 0.1 2 7 7 8, .. - 0.1 3 7 5 0, 0.0 5 3 1 3, 0.1 4 9 3 1, 0.0 2 6 8 3, .. - 0.0 0 3 5 0,- 0.0 0 0 1 2 0 ]'; e l s e % map e x t e r i o r on e x t e r i o r
a = [ 1.1 8 0 3 8, 1.1 0 8 9 2, 0.1 3 3 6 5, - 0.0 2 9 1 0 ]'; b = [ 1.1 0 6 1 2, 0.2 7 9 7 2, 0.0 0 7 8 8 ]'; z e t a 4 = 1./z e t a 4; end
% E v a l u a t e t h e mapping f u n c t i o n a f = f l i p u d ( a ); b f = f l i p u d ( [ 1;b ] ); z = z e t a.* p o l y v a l ( a f,z e t a 4 )./p o l y v a l ( b f,z e t a 4 );
12.11 Determining Harmonic Functions in a Circular Disk
The problem of determining a function that is harmonic for \z\ < 1 and satisfies certain boundary conditions can be analyzed effectively using series methods. In problems pertaining to the unit circle, it is often convenient to consider a function u, in polar cordinates, and write u(r, θ). Simultaneously, we may wish to think in terms of the related complex variable z = r σ where σ = e%θ. Three basic problems will be considered.
I) Dirichlet Problem
V2u
= 0 , \z\ < 1
υ„(1,θ) = f (θ) , 0 < θ < 2π
We assume f (θ) is a real piecewise continuous function expandable in a Four­
ier series as
tt
1(0)= Σ ^ > f - n = l n
n=- t t
Th e n u is given by the series
tt
u =
fo + 2 real( ^ f nz n) , \z\< 1
n=1
II) Neumann Problem
V2u = 0 , \z\ < 1
dUg' θ) = 9 {θ) , ο < θ < 2 π
We assume that the gradient function g is expandable in a Fourier series as
tt
g(0) = 9 n ( j n > 9 - n = g„.
n=-tt
The solution only exists if the integral of g(O) with respect to arc length around the boundary is zero. Hence, when
1 [ 2 go = ^ j g(0) άθ = o,
then the series solution is
tt
u = 2real( z") + c > N — 1
n=1
where c is an arbitrary real constant.
III) Mixed Problem
In the third type of problem the function value is specified on one part of the boundary and the normal gradient is specified on the remainder. In the general situation a solution can be constructed by methods using Cauchy integrals [73]. Only a simple case will be examined here. We require
V2 u = 0
u(1,O)= f (O) du(1, O)
dr
= g(0)
For convenience use the notation
L :
αιθ
\z\ < 1
Oi < O < O2 < O < (2π + Oi)
?i < O < O2 h <O< (2π + Oi)
Th e mi x e d p r o b l e m c a n b e r e d u c e d t o a c a s e wh e r e g is zero by first solving a Neumann problem for a harmonic function v such that
dv
— - g(6) , z e L'
dv
dr
r 2π+θι
g(O) dO
-Oi
z G L
Then we replace f (O) by f (O) — v(1, O) to getaproblemwhere
= f (O) — v(1, (
z G L
L : z = eιθ
u
du τ,
~Ξ~ = ^ ’ ζ ξζ L dr
Th e c o mp l e t e s o l u t i o n t h e n e q u a l s t h e s u m o f u and v. Consequently, no loss of generality results in dealing with the problem
u = f , z G L
du T,
— = 0 , z G L
dr
Co n s i d e r t h e f u n c t i o n
R(z) = \J (z — a)(z — b) , a = βιθι , b = e102
defined in the complex plane cut along L. We choose the branch of R satisfy­
ing
R(0) = βί(θι+θ2)/2 The solution to the mixed boundary value problem can be expressed as
„ = reai( g M [ m * , , i = e.. ,
πϊ Jl R+(t)(t — z)
where R +(t) means the boundary value of R(z) on the inside of the arc. As an example take
6»i = — — , θ2 = - 1 2 2
R(z) = Vz2 + 1 , R( 0) = 1
π π
u = cos(<9) , —— < Θ < —
Carrying out the integration gives
u = real( F( z ) )
wh e r e
F M =" + ^ ‘ + ( 1 ~ ^ 1 ) ^ T + T , | z | < l
a n d t h e s q u a r e r o o t e q u a l s + 1 a t z = 0. Thi s f u n c t i o n i s e mp l o y e d as a t e s t c a s e i n s u b s e q u e n t c a l c u l a t i o n s. Th e e x a c t s o l u t i o n i s e v a l u a t e d i n f u n c t i o n mb v t e s t.
12.11.1 Nume r i c al Res ul t s
Th e f u n c t i o n l a p c r c l s ol ve s e i t h e r Di r i c h l e t o r Ne u ma n n p r o b l e ms f o r t h e u n i t di s k. Th e b o u n d a r y v a l u e s a r e s p e c i f i e d as p i e c e wi s e l i n e a r f u n c t i o n s o f t h e p o l a r a ngl e. Th e n f u n c t i o n l i n t r p i s u s e d t o o b t a i n a d e n s e s e t o f b o u n d a r y v a l u e s wh i c h a r e t r a n s f o r me d b y t h e F F T t o p r o d u c e c o e f f i c i e n t s i n t h e s e r i e s s o l u t i o n. Wh e n
lapcrcl is executed with no input data, a Dirichlet problem is solved having the boundary condition
77 < θ < ~
π
2
π
2
Thi s c h o s e n b o u n d a r y c o n d i t i o n p r o d u c e s t h e i n t e r e s t i n g s u r f a c e p l o t s ho wn i n F i g ­
u r e 12.6 wh e r e t h e s o l u t i o n wa s e v a l u a t e d on a p o l a r c o o r d i n a t e g r i d e mp l o y i n g c o n s t a n t r a d i a l a n d a n g u l a r i n c r e me n t s.
Th e mi x e d b o u n d a r y v a l u e p r o b l e m i s mo r e d i f f i c ul t t o h a n d l e t h a n t h e Di r i c h l e t o r Ne u ma n n p r o b l e ms b e c a u s e n u me r i c a l e v a l u a t i o n o f t h e Ca u c h y i n t e g r a l mu s t b e p e r f o r me d c a ut i ou s l y. As z a p p r o a c h e s a p o i n t on L, t h e i n t e g r a n d b e c o me s s i ngul ar. Th e o r e t i c a l d e v e l o p me n t s i n vo l v i n g Ca u c h y p r i n c i p a l v a l u e i n t e g r a l s a n d t h e Pl e me l j f o r mu l a s a r e n e e d e d t o h a n d l e t hi s s i t u a t i o n t h o r o u g h l y [ 73]. Ev e n wh e n z i s c l o s e t o t h e b ou nd a r y, l a r g e i n t e g r a n d ma g n i t u d e ma y c a u s e i n a c c u r a t e n u me r i c a l i n t e g r a t i o n. F u r t h e r mo r e, t h e i n t e g r a n d wi l l h a v e s q u a r e r o o t t y p e s i n g u l a r i t i e s a t t h e e n d s o f L unless f (a) = f (b) = 0. Regularization procedures that can cope fully with these difficulties [26] will not be investigated in this text. Instead a simplified approach is presented.
The function cauchint was written to evaluate a contour integral involving a gen­
eral density function f (ζ) defined on a curve L of general shape.We consider
with both the density function f and the shape of L being defined using cubic spline interpolation. A set of points
are given. Spline functions ζ (t), f (t) are defined for 1 < t < m such that
[ζ1,ζ2,· · ·,ζ,η ] , ζ = ξ + ίη
l y i n g o n L, along with boundary values
[f ^ l ),m ),...,f ^ m)] = [fl,f2,...,fm]
ζ (j) = ζ] and f (j) = f 3 j =1, 2,...,n
Th e i n t e g r a n d i n p a r a me t r i c f o r m be c o me s
F( ) = _ L Γ f ( t ) W( t ) + i'n,(t )}dt
( 1 2πί Λ C(t) - z
a n d t hi s i n t e g r a l i s e v a l u a t e d u s i n g f u n c t i o n g c q u a d wh i c h c o mp u t e s Ga u s s i a n b a s e p o i n t s a n d we i g h t f a c t or s u s i n g e i g e n v a l u e me t h o ds. I t s h o u l d b e r e me mb e r e d t h a t
Dirichlet Problem Inside the Unit Circle
Figure 12.6: Dirichlet Problem Inside the Unit Circle
1 -1
y axis
x axis
when z is a point on the contour of integration, the integrand has a first order sin­
gularity. Hence, procedures to regularize the integrand would be needed to achieve accurate numerical integration in such cases.
Function cauchtst was employed to produce an approximate solution of the prob­
lem cited above. A surface plot of the exact solution appears in
Figure 12.7.
A plot of the difference between the exact and approximate solutions for 0 < r < 0.99 is shown in Figure 12.8
. This error is about three orders-of-magnitude smaller than the maximum function values in the solution. The reader can verify that using r = 0.999 and - π/2 < θ < π/2 leads to much larger errors. The authors have found function cauchint to be helpful if proper caution is exercised for results involving points near the boundary.
Approximate Solution to a Mixed Boundary Value Problem
Figure 12.7:
Approximate Solution to a Mixed Boundary Value Problem
Difference Between Exact and Approximate Solutions
Figure 12.8: Difference Between Exact and Approximate Solutions
12.11.2 Program Output and Code Function lapcrcl
T h i s f u n c t i o n s o l v e s L a p l a c e's e q u a t i o n i n s i d e a c i r c l e o f u n i t r a d i u s. E i t h e r a D i r i c h l e t p r o b l e m o r a Neumann p r o b l e m c a n be a n a l y z e d u s i n g b o u n d a r y v a l u e s d e f i n e d by p i e c e w i s e l i n e a r i n t e r p o l a t i o n o f d a t a s p e c i f i e d i n t e r m s o f t h e p o l a r a n g l e.
b v t y p - p a r a m e t e r d e t e r m i n i n g what t y p e
o f b o u n d a r y v a l u e p r o b l e m i s s o l v e d. I f b v t y p e q u a l s o n e, b o u n d a r y d a t a s p e c i f y f u n c t i o n v a l u e s and a D i r i c h l e t p r o b l e m i s s o l v e d. O t h e r w i s e, t h e b o u n d a r y d a t a s p e c i f y v a l u e s o f n o r m a l g r a d i e n t, and a Neumann p r o b l e m i s s o l v e d i f, i n a c c o r d w i t h t h e e x i s t e n c e c o n d i t i o n s f o r t h i s p r o b l e m, t h e a v e r a g e v a l u e o f g r a d i e n t on t h e b o u n d a r y i s z e r o ( n e g l i g i b l y s m a l l i n an a p p r o x i m a t e s o l u t i o n ). b v d a t - a m a t r i x o f b o u n d a r y d a t a. Each
b v d a t ( j,:) g i v e s a f u n c t i o n v a l u e and p o l a r a n g l e ( i n d e g r e e s ) o f a d a t a p o i n t u s e d by f u n c t i o n l i n t r p t o l i n e a r l y i n t e r p o l a t e f o r a l l o t h e r b o u n d a r y v a l u e s n e e d e d t o g e n e r a t e t h e s o l u t i o n. r v e c,t h v e c - v e c t o r s o f r a d i i and p o l a r
c o o r d i n a t e v a l u e s u s e d t o f o r m a p o l a r c o o r d i n a t e g r i d o f p o i n t s i n s i d e t h e u n i t c i r c l e. No v a l u e s o f r e x c e e d i n g u n i t y a r e a l l o w e d. nsum - t h e number o f t e r m s summed i n t h e
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
74
75
76
77
78
79
80
81
82
83
84
85
%
%
%
%
%
%
% u
%
%
%
- v a l u e s o f t h e h a r m o n i c f u n c t i o n e v a l u a t e d a t a s e t o f p o i n t s on a p o l a r c o o r d i n a t e g r i d i n s i d e t h e u n i t c i r c l e.
s e r i e s e x p a n s i o n o f t h e a n a l y t i c f u n c t i o n whi ch h a s u a s i t s r e a l p a r t. T y p i c a l l y, no more t h a n one h u n d r e d t e r m s a r e n e e d e d t o
p r o d u c e a good s o l u t i o n.
% r,t h
- t h e g r i d o f p o l a r c o o r d i n a t e
%
%
%
v a l u e s i n whi ch t h e f u n c t i o n i s e v a l u a t e d
% U s er m f u n c t i o n s c a l l e d: l i n t r p
% D e f a u l t t e s t c a s e s o l v e s a D i r i c h l e t p r o b l e m % f o r a f u n c t i o n h a v i n g t h e f o l l o w i n g e x a c t % s o l u t i o n:
% - 1/2 + i m a g ( l o g ( ( z - i )/( z + i ) )/p i ) + r e a l ( z ~ 1 6 )/1 0
i f n a r g i n ==0
b v t y p = 1; t h = l i n s p a c e ( 0,2 * p i,2 0 1 )'; b v = 1 - ( t h > p i/2 ) + ( t h > 3 * p i/2 ) + c o s ( 1 6 * t h )/1 0; b v d a t = [ b v,1 8 0/p i * t h ]; r v e c = l i n s p a c e ( 1,0,1 0 ); t h v e c = l i n s p a c e ( 0,3 6 0,1 6 1 ); nsum=200;
n f t = 5 1 2;
t h f f t = l i n s p a c e ( 0,2 * p i * ( n f t - 1 )/n f t,n f t ); i f n a r g i n < 5, nsum=200; en d; n s u m = m i n ( n s u m,n f t/2 - 1 ); f b v = b v d a t (:,1 ); t h b v = p i/1 8 0 * b v d a t (:,2 ); n e v = s i z e ( b v d a t,1 ); n r = l e n g t h ( r v e c ); n t h = l e n g t h ( t h v e c ); n e v a l = n r * n t h; [ R,T h ] = m e s h g r i d ( r v e c,p i/1 8 0 * t h v e c ); r = R (:); t h = T h (:);
% Check f o r any e r r o n e o u s p o i n t s o u t s i d e t h e
% u n i t c i r c l e
r v e c = r v e c (:);
k o u t = f i n d ( r v e c > 1 ); n o u t = l e n g t h ( k o u t ); i f l e n g t h ( k o u t ) > 0
%
%
end
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
p r i n t ('I n p u t d a t a a r e i n c o r r e c t. The '); p r i n t ('f o l l o w i n g r v a l u e s l i e o u t s i d e t h e '); p r i n t ('u n i t c i r c l e:'); d i s p ( r v e c ( k o u t )'); r e t u r n end
i f bvtyp==1 % S o l v e a D i r i c h l e t p r o b l e m % Check f o r p o i n t s on t h e b o u n d a r y where % f u n c t i o n v a l u e s a r e known. I n t e r p o l a t e % t h e s e d i r e c t l y
k o n b d = f i n d ( r = = 1 ); o n b n d r y = l e n g t h ( k o n b d ); i f o n b n d r y > 0
u ( k o n b d ) = l i n t r p ( t h b v,f b v,t h ( k o n b d ) ); end
% E v a l u a t e t h e s e r i e s s o l u t i o n k i n s i d = f i n d ( r < 1 ); i n s i d e = l e n g t h ( k i n s i d );
i f i n s i d e > 0
a = f f t ( l i n t r p ( t h b v,f b v,t h f f t ) );
a = a ( 1:n s u m )/( n f t/2 );
a ( 1 ) = a ( 1 )/2; Z = r ( k i n s i d ).* e x p ( i * t h ( k i n s i d ) ); u ( k i n s i d ) = r e a l ( p o l y v a l ( f l i p u d ( a (:) ),Z ) ); end
t i t l = ...
'D i r i c h l e t P r o b l e m I n s i d e t h e U n i t C i r c l e';
e l s e % S o l v e a Neumann p r o b l e m g b v = l i n t r p ( t h b v,f b v,t h f f t ); a = f f t ( g b v )/( n f t/2 ); e r c h e k = a b s ( a ( 1 ) )/s u m ( a b s ( g b v ) ); i f e r c h e k > 1 e - 3 d i s p (' ');
disp('ERROR DUE TO NONZERO AVERAGE VALUE'); d i s p ('O F NORMAL GRADIENT ON THE BOUNDARY.'); disp('CORRECT THE INPUT DATA AND RERUN.'); d i s p (' '); u = [ ]; r = [ ]; t h = [ ]; r e t u r n; end
a = a ( 2:n s u m )./( 1:n s u m - 1 )'; z = r.* e x p ( i * t h ); u = r e a l ( p o l y v a l ( f l i p u d ( [ 0;a (:) ] ),z ) ); t i t l ='N e u m a n n P r o b l e m I n s i d e t h e U n i t C i r c l e'; end
u = r e s h a p e ( u,n t h,n r ); r=R; th=Th;
1 3 1: s u r f ( r.* c o s ( t h ),r.* s i n ( t h ),u );
132: x l a b e l ('x a x i s'); y l a b e l ('y a x i s'); 133: z l a b e l ('f u n c t i o n u'); t i t l e ( t i t l ); 134: c o l o r m a p ('d e f a u l t');
135: g r i d on; f i g u r e ( g c f );
136: % p r i n t - d e p s d i r i c h
137:
138: %==================================
139:
1 4 0: % f u n c t i o n y = l i n t r p ( x d,y d,x )
141: % See Appe ndix B
Function cauchtst
f u n c t i o n u = c a u c h t s t ( z,n q u a d )
%
% u = c a u c h t s t ( z,n q u a d )
%................................................
%
% T h i s f u n c t i o n s o l v e s a mixed b o u n d a r y % v a l u e p r o b l e m f o r t h e i n t e r i o r o f a c i r c l e % by n u m e r i c a l l y e v a l u a t i n g a Cauchy i n t e g r a l.
%
% z - m a t r i x o f complex c o o r d i n a t e s where
% f u n c t i o n v a l u e s a r e computed
% nquad - o r d e r o f Gauss q u a d r a t u r e u s e d t o
% p e r f o r m n u m e r i c a l i n t e g r a t i o n
%
% u - computed v a l u e s o f t h e a p p r o x i m a t e
% s o l u t i o n
%
% U s er m f u n c t i o n s c a l l e d: c a u c h i n t, m b v t e s t,
% g c q u a d, s p l i n e d
i f n a r g i n < 2, nquad=50; e n d; n b d a t = 6 1; i f n a r g i n = = 0
z = l i n s p a c e ( 0,.9 9,1 0 )'* ... e x p ( i * l i n s p a c e ( 0,2 * p i,9 1 ) );
end
t h = l i n s p a c e ( - p i/2,p i/2,n b d a t ); z b = e x p ( i * t h ); f b = s q r t ( z b - i ).* s q r t ( z b + i ); f b ( 1 ) = 1; f b ( n b d a t ) = 1;
28
29
30
31
32
33
34
35
36
37
38
39
40
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
f b = c o s ( t h )./f b; f b ( 1 ) = 0; f b ( e n d ) = 0; F = c a u c h i n t ( f b,z b,z,n q u a d ); F = F.* s q r t ( z - i ).* s q r t ( z + i ); u = 2 * r e a l ( F );
s u r f ( r e a l ( z ),i m a g ( z ),u ); x l a b e l ('x a x i s'); y l a b e l ('y a x i s'); z l a b e l ('S o l u t i o n V a l u e') t i t l e ( ['A p p r o x i m a t e S o l u t i o n t o ', ...
'a Mixed Boundary V a lu e P r o b l e m'] ); g r i d on; f i g u r e ( g c f ); % g r a (.4 ); f p r i n t f ('\n P r e s s [ E n t e r ] t o s o l u t i o n e r r o r\n'); p a u s e
% p r i n t - d e p s c a u c h e r l u e x a c t = m b v t e s t ( z,1 ); u d i f = u - u e x a c t; c l f; s u r f ( r e a l ( z ),i m a g ( z ),u d i f ); t i t l e ( ['D i f f e r e n c e Between E x a c t and ', ...
'A p p r o x i m a t e S o l u t i o n s'] ); x l a b e l ('x a x i s'); y l a b e l ('y a x i s'); z l a b e l ('S o l u t i o n E r r o r') g r i d on; f i g u r e ( g c f ); % g r a (.4 )
% p r i n t - d e p s c a u c h e r 2
%=============================================
f u n c t i o n u = m b v t e s t ( z,n o p l o t )
%
% u = m b v t e s t ( z,n o p l o t )
%................................................
%
% T h i s f u n c t i o n d e t e r m i n e s a f u n c t i o n whi ch i s % h a r m o n i c f o r a b s ( z ) < 1 and s a t i s f i e s a t r = 1,
% u = c o s ( t h e t a ), - p i/2 < t h e t a < p i/2 % d u/d r = 0, p i/2 < t h e t a < 3 * p i/2
% The s o l u t i o n o n l y a p p l i e s f o r p o i n t s i n s i d e % o r on t h e u n i t c i r c l e.
%
% z - m a t r i x o f complex v a l u e s where t h e
% s o l u t i o n i s computed.
% n o p l o t - o p t i o n s e t t o one i f no p l o t i s
% r e q u e s t e d, o t h e r w i s e o p t i o n i s n o t
% r e q u i r e d.
%
% u - v a l u e s o f t h e h a r m o n i c f u n c t i o n
% d e f i n e d i n s i d e t h e u n i t c i r c l e
%
% U s e r m f u n c t i o n s c a l l e d: n o n e
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
%
i f n a r g i n = = 0 n o p l o t = 0;
z = l i n s p a c e ( 0,1,1 0 )'* ... e x p ( i * l i n s p a c e ( 0,2 * p i,8 1 ) );
end
[ n,m ] = s i z e ( z ); z = z (:); u = 1/2 * o n e s ( s i z e ( z ) ); k = f i n d ( a b s ( z ) > 0 ); Z = z ( k );
U = ( Z + 1./Z + ( 1 - 1./Z ).* s q r t ( z - i ).* s q r t ( Z + i ) )/2; u ( k ) = r e a l ( U ); u = r e s h a p e ( u,n,m ); i f n a r g i n = = 1 | n o p l o t = = 0 z = r e s h a p e ( z,n,m );
s u r f ( r e a l ( z ),i m a g ( z ),u ); x l a b e l ('x a x i s'); y l a b e l ('y a x i s');
t i t l e ( ['M i x e d Boundary V a lu e P r o b l e m ', ...
'f o r a C i r c u l a r D i s k'] ); g r i d; f i g u r e ( g c f ); % g r a (.4 ), p a u s e % p r i n t - d e p s m b v t e s t end
% T h i s f u n c t i o n n u m e r i c a l l y e v a l u a t e s a Cauchy % i n t e g r a l o f t h e f or m:
% F ( z ) = 1/( 2 * p i * i ) * I n t e g r a l ( f ( t )/( t - z ) * d t )
% where t d e n o t e s p o i n t s on a c u r v e i n t h e % complex p l a n e. The b o u n d a r y c u r v e i s d e f i n e d % by s p l i n e i n t e r p o l a t i o n t h r o u g h d a t a p o i n t s % zb l y i n g on t h e c u r v e. The v a l u e s o f f ( t )
% a r e a l s o s p e c i f i e d by s p l i n e i n t e r p o l a t i o n % t h r o u g h v a l u e s f b c o r r e s p o n d i n g t o t h e % p o i n t s z b. N u m e r i c a l e v a l u a t i o n o f t h e % i n t e g r a l i s p e r f o r m e d u s i n g a c o m p o s i t e % Gauss f o r m u l a o f a r b i t r a r y o r d e r.
%
% F = c a u c h i n t ( f b,z b,z,n q u a d )
%
%
%
%
%
% f b %
- v a l u e s o f d e n s i t y f u n c t i o n f a t p o i n t on t h e c u r v e
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
% zb
p o i n t s where f b i s g i v e n. The number o f v a l u e s o f zb must be a d e q u a t e t o d e f i n e t h e c u r v e a c c u r a t e l y.
a m a t r i x o f v a l u e s a t whi ch t h e Cauchy i n t e g r a l i s t o be e v a l u a t e d. I f any o f t h e z - v a l u e s l i e on p a t h o f i n t e g r a t i o n o r t o o c l o s e t o t h e p a t h o f i n t e g r a t i o n, i n c o r r e c t r e s u l t s w i l l be o b t a i n e d. t h e o r d e r o f Gauss q u a d r a t u r e f o r m u l a u s e d t o p e r f o r m n u m e r i c a l i n t e g r a t i o n
%
%
%
% z
%
%
%
%
%
% nquad
%
%
%
% F
%
%
The v a l u e o f t h e Cauchy i n t e g r a l c o r r e s p o n d i n g t o m a t r i x a r g u m e n t z
% U s er m f u n c t i o n s c a l l e d: g c q u a d s p l i n e d
n = l e n g t h ( f b ); [ n r,n c ] = s i z e ( z ); z = z (:).'; n z = l e n g t h ( z ); t = 1:n;
[ d u m m y,b p,w f ] = g c q u a d ('',1,n,n q u a d,n - 1 ); f q = s p l i n e ( t,f b,b p ); z q = s p l i n e ( t,z b,b p ); z q d = s p l i n e d ( t,z b,b p ); n q = l e n g t h ( f q ); f q = f q (:).* z q d (:);
b d r y l e n = s u m ( a b s ( z q ( 2:n q ) - z q ( 1:n q - 1 ) ) );
c l o s n e s = 1 e 1 0 0; b i g z = m a x ( a b s ( z ) ); f o r j = 1:n q
c l o s n e s = m i n ( [ c l o s n e s,a b s ( z q ( j ) - z ) ] );
end
i f c l o s n e s/b d r y l e n <.0 1 | c l o s n e s/b i g z <.0 1 d i s p (' ')
disp(['WARNING! SOME DATA VALUES ARE ', ...
'EITHER NEAR OR O N'] ); d i s p ( ['T H E BOUNDARY. COMPUTED RESULTS ', ... 'MAY BE INACCURATE']); d i s p (' ')
end
F = w f (:)'* ( f q (:,o n e s ( 1,n z ) )./( z q (:,o n e s ( 1,n z ) )...
- z ( o n e s ( n q,1 ),:) ) );
F = r e s h a p e ( F,n r,n c )/( 2 * p i * i );
%
%
163
164: % 165: % 166: %
f u n c t i o n [ v a l,b p,w f ] = g c q u a d ( f u n c,x l o w,...
x h i g h,n q u a d,m p a r t s,v a r a r g i n )
See Appendix B
167
168:
%
169
1 7 0: % f u n c t i o n v a l = s p l i n e d ( x d,y d,x,i f 2 ) 171: % See Appe ndix B
12.12 Inviscid Fluid Flow around an Elliptic Cylinder
This section analyzes inviscid flow around an elliptic cylinder in an infinite field. Flow around a circular cylinder is treated first. Then the function conformally map­
ping the exterior of a circle onto the exterior of an ellipse is used in conjunction with the invariance of harmonic functions under a conformal transformation. Results de­
scribing the elliptic cylinder flow field for uniform velocity components at infinity are presented.
Let us solve for the flow around a circular cylinder in the region |ζ | > 1, ζ = ξ+ί η with the requirement that the velocity components at infinity have constant values
where (u, v) are the horizontal and vertical components of velocity. These compo­
nents are derivable from a potential function φ such that
where φ is a harmonic function. The velocity normal to the cylinder boundary must be zero. This requires that the function ψ, the harmonic conjugate of φ, must be con­
stant on the boundary. The constant can be taken as zero without loss of generality. In terms of the complex velocity potential
u = U , v = V
^φ ^φ
f (ζ ) = φ + ίψ
we n e e d
/( Ο - /(C) = 0 on ICI = 1 The velocity field is related to the complex velocity potential by
u — iv = f '(ζ)
so the flow condition at infinity is satisfied by
f (ζ )= Ρζ + O(1) where p = U — i V
A Laurent series can be used to represent f (ζ ) in the form
tt
f (ζ ) = ρζ + a0 + 53 αηζ n
n=1
Imposition of the boundary condition on the cylinder surface requiring
/(σ) — /(σ) = 0 where σ = βιθ
l e a d s t o
t t t t
ρσ + αο + 53 α„σ~" — ρ σ —αο — 53 α^ση = 0
η=1 η=1
Taking α0 = 0, a1 = ρ, and an = 0, n > 2 satisfies all conditions of the problem and yields
f (ζ ) = Ρζ + Ρζ-1 as the desired complex potential function giving the velocity field as
u — iv = f '(ζ ) = ρ — ρ ζ -2 , Ιζ I > 1
No w c o n s i d e r f l ow a b o u t a n e l l i p t i c c y l i n d e r l y i n g i n t h e z - p l a n e. I f t h e v e l o c i t y a t i n f i n i t y h a s c o mp o n e n t s (U, V ) then we need a velocity potential F (z ) such that
F'(t t ) = U — i V and
FW -F(I) = 0 for © 2+ ( f ) 2 = l
This is nearly the same problem as was already solved in the ζ -plane except that
dF άζ dF 1 dF
dz dz άζ ω'(ζ) άζ
where ω(ζ ) is the mapping function
, 7 i x _ a + b a — b
ζ = ω(ζ ) = ϋ ( ζ + πιζ , R = — — , m = ——
2 a + b
In terms of ζ we would need dF
—— = uj'(oo)[U — %V\ = R(U — i V) at ζ = oo αζ
Consequently, the velocity potential for the elliptic cylinder problem expressed in terms of ζ is
F = ρζ + ρ ζ - 1 , ρ = R (U — i V ) and the velocity components in the z -plane are given by
— i v = — - — Γρ — ρ ζ - 2] = V - W - V - i V * - 2
ω’ ( ζ ) [P K J 1 - m C - 2 '
To get values for a particular choice of z we can use the inverse mapping function
ζ
z + %/ z1 — 4 mR2 2R
t o e l i mi n a t e ζ or we can compute results in terms of ζ.
To complete our discussion of this flow problem we will graph the lines charac­
terizing the directions of flow. The velocity potential F = φ + ΐψ satisfies
^φ ^ψ
u = tt ~ = ~7Γ~ ,
dx dy
so a curve tangent to the velocity field obeys
dy v
θφ
dy
dx
θψ I dx d^/dy
θφ
dx
or
θφ θφ
— dx + — dy = 0 dx dy
ψ = constant
Consequently, the flow lines are the contours of function ψ, which is called the stream function. The function we want to contour does not exist inside the ellipse, but we can circumvent this problem by computing ψ in the ellipse exterior and then setting ψ to zero inside the ellipse. The function elipcyl analyzes the cylinder flow and produces the accompanying contour plot shown in
Figure 12.9.
u
El li p ti c C y l i n d e r Fl ow Fi el d f o r A n g l e = 30 Degr ees
Figure 12.9: Elliptic Cylinder Flow Field for Angle = 30c
12.12.1 Program Output and Code Function elipcyl
f u n c t i o n [ x,y,F ] = e l i p c y l ( a,n,r x,r y,a n g ) [ x,y,F ] = e l i p c y l ( a,n,r x,r y,a n g )
T h i s f u n c t i o n computes t h e f l o w f i e l d a r o u n d an e l l i p t i c c y l i n d e r. The v e l o c i t y d i r e c t i o n a t i n f i n i t y i s a r b i t r a r y.
a - d e f i n e s t h e r e g i o n - a < x < a, - a < y < a
w i t h i n whi ch t h e f l o w f i e l d i s computed
n - t h i s d e t e r m i n e s t h e g r i d s i z e which
u s e s n by n p o i n t s r x,r y - m a j o r and m i n o r s e m i - d i a m e t e r s a f t h e e l l i p s e l y i n g on t h e x and y a x e s,
x axis
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
% r e s p e c t i v e l y
% ang - t h e a n g l e i n d e g r e e s w h i ch t h e % v e l o c i t y a t i n f i n i t y makes w i t h t h e
% x a x i s
%
% x,y - m a t r i c e s o f p o i n t s where t h e v e l o c i t y % p o t e n t i a l i s computed
% F - m a t r i x o f complex v e l o c i t y p o t e n t i a l % v a l u e s. T h i s f u n c t i o n i s s e t t o z e r o
% i n s i d e t h e e l l i p s e, where t h e
% p o t e n t i a l i s a c t u a l l y n o t d e f i n e d
%
% U s e r m f u n c t i o n s c a l l e d: none
% d e f a u l t d a t a f o r a 2 by 1 e l l i p s e i f n a r g i n = = 0 a=5; n=81; r x = 2; r y = 1; ang=30; end
% Compute a s q u a r e g r i d i n t h e z p l a n e. a r = p i/1 8 0 * a n g; p = ( r x + r y )/2 * e x p ( - i * a r ); c p = c o n j ( p ); d = l i n s p a c e ( - a,a,n ); [ x,y ] = m e s h g r i d ( d,d ); m = s q r t ( r x ~ 2 - r y ~ 2 );
% O b t a i n p o i n t s i n t h e z e t a p l a n e o u t s i d e % t h e e l l i p s e
z = x (:) + i * y (:); k = f i n d ( ( x/r x ).~ 2 + ( y/r y ).~ 2 > = 1 ); Z = z ( k ); z e t a = ( Z + s q r t ( Z - m ).* s q r t ( Z + m ) )/( r x + r y ); F = z e r o s ( n * n,1 );
% E v a l u a t e t h e p o t e n t i a l f o r a c i r c u l a r % c y l i n d e r
F ( k ) = p * z e t a + c p./z e t a; F = r e s h a p e ( F,n,n );
% C o n t o u r t h e s t r e a m f u n c t i o n t o show t h e % d i r e c t i o n o f f l o w
c l f; c o n t o u r f ( x ( 1,:),y (:,1 ),a b s ( i m a g ( F ) ),3 0 ); a x i s ('s q u a r e'); z b = e x p ( i * l i n s p a c e ( 0,2 * p i,1 0 1 ) ); x b = r x * r e a l ( z b ); y b = r y * i m a g ( z b ); x b ( e n d ) = x b ( 1 ); y b ( e n d ) = y b ( 1 ); h o l d on; f i l l ( x b,y b,[ 1 2 7/2 5 5 1 2 1 2/2 5 5 ] ); x l a b e l ('x a x i s'); y l a b e l ('y a x i s'); t i t l e ( ['E l l i p t i c C y l i n d e r Flow F i e l d f o r ', ... 'A n g l e = ',n u m 2 s t r ( a n g ),' D e g r e e s'] );
62: c o l o r m a p h s v; f i g u r e ( g c f ); h o l d o f f; 63: % p r i n t - d e p s e l i p c y l
12.13 Torsional Stresses in a Beam Mapped onto a Unit Disk
Torsional stresses in a cylindrical beam can be computed from an integral formula when the function ζ = ω(ζ) mapping the unit disk, ζ | < 1, onto the beam cross section is known [90]. The complex stress function
1 f ω(σ)ω(σ) άσ /Ο = τ' /— + constant,
J7 σ - ζ
where γ denotes the unit circle, can be evaluated exactly by contour integration in some cases. However, an approach employing series methods is easy to implement and gives satisfactory results if enough series terms are taken. When ω(ζ) is a poly­
nomial, f (ζ) is a polynomial of the same order as ω(ζ). Furthermore, when ω(ζ) is a rational function, residue calculus can be employed to compute f (ζ) exactly, provided the poles of ω(1/ζ) can be found. A much simpler approach is to use the FFT to expand ω(σ)ω(σ) in a complex Fourier series and write
ω(σ)ω(σ) =
tt
Σ
n
n=
Then the complex stress function is
tt
f (ζ) = * 5 3 °ηζη + constant
n=1
where the constant has no influence on the stress state. The shear stresses relative to the curvilinear coordinate system are obtainable from the formula
f '(ζ) - *ω(ζ)ω'(ζ) ζ
με |ζω'(ζ)|
where μ is the shear modulus and ε is the angle of twist per unit length. The capital Z subscript on shear stresses refers to the direction of the beam axis normal to the xy plane rather than the complex variable z = x + iy. The series expansion gives
f '(ζ) = t^nCnC
n-1
■nζ
n=1
TPZ - *TaZ
and this can be used to compute stresses. Differentiated series expansions often converge slowly or may even be divergent. To test the series expansion solution, a
Torsional Shear Stresses on a Square Cross Section
Figure 12.10: Torsional Shear Stresses on a Square Cross Section
rational function mapping |ζ| < 1 onto a square defined by \x\ < 1 and \y\< 1 was employed. Function mapsqr which computes ζ( ζ) and ζ'(ζ) is used by function torstres to evaluate stresses in terms of ζ. A short driver program runtors evaluates stresses on the boundary for x = 1, 0 < y < 1. Stresses divided by the side length of 2 are plotted and results produced from a highly accurate solution [90] are compared with values produced using 800 terms in f (ζ). Results depicted in Figure 12.10 show that the error in maximum shear stress was only 0.44% and the torsional stiff­
ness was accurate within 0.05%. The numerical solution gives a nonzero stress value for y = 1, which disagree with the exact solution. This error is probably due more to the mapping function giving slightly rounded corners than to slow convergence of the series solution. Even though the differentiated series converges slowly, computation time is still small. The reader can verify that using 1500 terms reduces the bound­
ary stress oscillations to negligible magnitude and produces a maximum stress error of 0.03%. Although taking 1500 terms to achieve accurate results seems excessive, less than 400 nonzero terms are actually involved because geometrical symmetry im­
plies a series increasing in powers of four. For simplicity and generality, no attempt was made to account for geometrical symmetry exhibited by a particular mapping function. It appears that a series solution employing a mapping function is a viable computational tool to deal with torsion problems.
Program runtors
12.13.1 Program Output and Code
f u n c t i o n r u n t o r s ( n t r m s )
% Example: r u n t o r s ( n t r m s )
%........................................
%
% Example showing t o r s i o n a l s t r e s s c o m p u t a t i o n % f o r a beam o f s q u a r e c r o s s s e c t i o n u s i n g % c o n f o r m a l mapping and a complex s t r e s s % f u n c t i o n.
%
% n t r m s - number o f s e r i e s t e r m s u s e d t o % r e p r e s e n t a b s ( w ( z e t a ) ) ~ 2
%
% U s er m f u n c t i o n s c a l l e d: t o r s t r e s, mapsqr
% G e n e r a t e z e t a v a l u e s d e f i n i n g h a l f o f a s i d e t h e t a = l i n s p a c e ( 0,p i/4,5 0 1 ); z e t a = e x p ( i * t h e t a ); i f n a r g i n = = 0, n t r m s = 8 0 0; end
% Compute s t r e s s e s u s i n g an a p p r o x i m a t e r a t i o n a l % f u n c t i o n mapping f u n c t i o n f o r t h e s q u a r e [ t r,t a,z,c,C ] = ... t o r s t r e s ('m a p s q r',z e t a,n t r m s,4 * 1 0 2 4 );
% R e s u l t s fr o m t h e e x a c t s o l u t i o n n = 1:2:1 3;
t m e x a c t = 1 - 8/p i ~ 2 * s u m ( 1./( n.~ 2.* c o s h ( n * p i/2 ) ) ); e r r = a b s ( t a ( 1 )/2 - t m e x a c t ) * 1 0 0/t m e x a c t; s t f e x c t = 1 6/3 - 1 0 2 4/p i ~ 5 * s u m ( t a n h ( p i/2 * n )./n.~ 5 ); s t f a p r x = 8/3 - p i * s u m ( ( 1:n t r m s )'.* ...
a b s ( C ( 2:n t r m s + 1 ) ).~ 2 );
s t e r = 1 0 0 * a b s ( s t f a p r x - s t f e x c t )/s t f e x c t;
% P l o t c i r c u m f e r e n t i a l and n o r m a l s t r e s s e s a t
% t h e b o u n d a r y
t h = 1 8 0/p i * t h e t a;
c l f; p l o t ( i m a g ( z ),t r/2,'k:',i m a g ( z ),t a/2,'k -') x l a b e l ('y d i s t a n c e a l o n g t h e s i d e'); y l a b e l ('s h e a r s t r e s s e s a t t h e b o u n d a r y'); t i t l e ( ['T o r s i o n a l S h e a r S t r e s s e s on a ', ... 'S q u a r e C r o s s S e c t i o n'] );
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
74
75
76
77
78
79
80
81
82
83
84
85
t e x t (.0 5,.4 0, ...
['Max S h e a r S t r e s s = ',n u m 2 s t r ( m a x ( t a )/2 ) ] ); t e x t (.0 5,.3 4, ...
['Number o f S e r i e s Terms = ',n u m 2 s t r ( n t r m s ) ] ); t e x t (.0 5,.2 8, ...
['Maximum S t r e s s E r r o r = ',n u m 2 s t r ( e r r ),'%'] ); t e x t (.0 5,.2 2,['S t i f f n e s s F a c t o r E r r o r = ', ...
n u m 2 s t r ( s t e r ),'%'] ); l e g e n d ('R a d i a l s h e a r s t r e s s',...
'T a n g e n t i a l s h e a r s t r e s s'); f i g u r e ( g c f );
% d i s p ('U s e mouse t o l o c a t e l e g e n d b l o c k'); % d i s p ('P r e s s [ E n t e r ] when f i n i s h e d');
% p r i n t - d e p s t o r s i o n
%=============================================
f u n c t i o n [ t r h o,t a l p h a,z,c,C ] = ...
t o r s t r e s ( m a p f u n,z e t a,n t r m s,n f t )
%
% [ t r h o,t a l p h a,z,c,C ] = ...
% t o r s t r e s ( m a p f u n,z e t a,n t r m s,n f t )
%....................................................................................................................
%
% T h i s f u n c t i o n computes t o r s i o n a l s t r e s s e s i n % a beam s u c h t h a t a b s ( z e t a ) < = 1 i s mapped o n t o % t h e beam c r o s s s e c t i o n by a f u n c t i o n named % mapfun.
%
% mapfun - a c h a r a c t e r s t r i n g g i v i n g t h e name
% o f t h e mapping f u n c t i o n
% z e t a - v a l u e s i n t h e z e t a p l a n e
% c o r r e s p o n d i n g t o whi ch t o r s i o n a l
% s t r e s s e s a r e computed
% n t r m s - t h e number o f t e r m s u s e d i n t h e
% s e r i e s e x p a n s i o n o f t h e mapping
% f u n c t i o n
% n f t - t h e number o f f u n c t i o n v a l u e s % employed t o compute F o u r i e r
% c o e f f i c i e n t s o f t h e complex s t r e s s
% f u n c t i o n
%
% t r h o - t o r s i o n a l s t r e s s e s i n d i r e c t i o n s
% n o r m a l t o t h e l i n e s i n t o which
% a b s ( z e t a ) = c o n s t map. T h es e v a l u e s
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
% s h o u l d be z e r o a t t h e b o u n d a r y
% c o r r e s p o n d i n g t o a b s ( z e t a ) = 1.
% t a l p h a - t o r s i o n a l s t r e s s e s i n d i r e c t i o n s % t a n g e n t t o t h e c u r v e s i n t o which
% a b s ( z e t a ) = c o n s t map. The maximum
% v a l u e o f s h e a r s t r e s s a l w a y s o c c u r s
% a t some p o i n t on t h e b o u n d a r y d e f i n e d
% by a b s ( z e t a ) = 1.
% z - v a l u e s o f z where s t r e s s e s a r e
% computed
% c - c o e f f i c i e n t s i n t h e s e r i e s e x p a n s i o n
% o f t h e complex s t r e s s f u n c t i o n
% C - complex F o u r i e r c o e f f i c i e n t s o f
% z.* c o n j ( z ) on t h e b o u n d a r y o f t h e
% beam c r o s s s e c t i o n
%
% U s er m f u n c t i o n s c a l l e d: none
%-----------------------------------------------------------------------------------------
i f n a r g i n < 4, n f t = 4 0 9 6; en d; i f n a r g i n < 3, n t r m s = 8 0 0; end
% Compute b o u n d a r y v a l u e s o f t h e mapping % f u n c t i o n n e e d e d t o c o n s t r u c t t h e complex % s t r e s s f u n c t i o n
z e t a b = e x p ( i * l i n s p a c e ( 0,2 * p i * ( n f t - 1 )/n f t,n f t ) ); z b = f e v a l ( m a p f u n,z e t a b ); z b = z b (:);
% E v a l u a t e z and z'( z e t a ) a t o t h e r % d e s i r e d p o i n t s [ z,z p ] = f e v a l ( m a p f u n,z e t a );
% Compute F o u r i e r c o e f f i c i e n t s f o r t h e complex % s t r e s s f u n c t i o n and i t s d e r i v a t i v e C = f f t ( z b.* c o n j ( z b ) )/n f t; c = i * C ( 2:n t r m s + 1 ).* ( 1:n t r m s )'; f p = p o l y v a l ( f l i p u d ( c ),z e t a );
% E v a l u a t e s t r e s s e s r e l a t i v e t o t h e c u r v i l i n e a r % c o o r d i n a t e s y s t e m
t c p l x = z e t a./a b s ( z e t a.* z p ).* ( f p - i * c o n j ( z ).* z p );
% t r h o i s t h e r a d i a l s h e a r s t r e s s t h a t s h o u l d
% v a n i s h a t t h e b o u n d a r y
t r h o = r e a l ( t c p l x );
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
% t a l p h a i s t h e c i r c u m f e r e n t i a l s t r e s s which % g i v e s t h e maximum s t r e s s o f i n t e r e s t a t t h e % b o u n d a r y t a l p h a = - i m a g ( t c p l x );
%============================================
f u n c t i o n [ z,z p ] = m a p s q r ( z e t a );
%
% [ z,z p ] = m a p s q r ( z e t a )
%................................................
%
% T h i s f u n c t i o n maps t h e i n t e r i o r o f a c i r c l e % o n t o t h e i n t e r i o r o f a s q u a r e u s i n g a r a t i o n a l % f u n c t i o n o f t h e a p p r o x i m a t e f or m:
%
% z ( z e t a ) = z e t a * S u m ( a ( j ) * ...
% z e t a 4 ~ ( j - 1 )/( 1 + S u m ( b ( j ) * z e t a 4 ~ ( j - 1 ) )
%
% where z e t a 4 = z e t a ~ 4 %
% z e t a - m a t r i x o f complex v a l u e s s u c h t h a t % a b s ( z e t a ) < = 1
% z,z p - m a t r i c e s o f v a l u e s o f t h e mapping % f u n c t i o n and i t s f i r s t d e r i v a t i v e
%
% U s er m f u n c t i o n s c a l l e d: none
%-----------------------------------------------------------------------------------------
a = [ 1.0 7 8 3 5, 0.1 3 4 6 0, 0.0 1 8 7 8, b = [ 1.3 7 7 4 3, - 0.1 3 7 5 0, - 0.0 0 3 5 0,
1.3 7 7 5 1, - 0.0 2 6 4 2, - 0.0 9 1 2 9,
- 0.1 5 7 6 3, 0.0 7 4 3 0, 0.1 4 8 5 8,
- 0.0 0 3 5 4 ]';
0.0 7 1 5 7, - 0.1 1 0 8 5, 0.1 2 7 7 8,
0.0 5 3 1 3, 0.1 4 9 3 1, 0.0 2 6 8 3,
- 0.0 0 0 1 2 0 ]';
% E v a l u a t e t h e mapping f u n c t i o n z e t a 4 = z e t a.~ 4; p = z e t a.* p o l y v a l ( f l i p u d ( a ),z e t a 4 ); q = p o l y v a l ( f l i p u d ( [ 1;b ] ),z e t a 4 ); z = p./q;
% E x i t i f t h e d e r i v a t i v e o f z i s n o t n e e d e d i f n a r g o u t = = 1, r e t u r n, end
% e v a l u a t e z'( z e t a )
1 7 6: n a = l e n g t h ( a ); n b = l e n g t h ( b );
1 7 7: p p = p o l y v a l ( f l i p u d ( ( 4 * ( 1:n a ) '- 3 ).* a ),z e t a 4 ) ;
1 7 8: q p = 4 * z e t a.~ 3.* p o l y v a l ( f l i p u d ( ( 1:n b )'.* b ),z e t a 4 ); 179: z p = ( q.* p p - p.* q p )./q.~ 2;
12.14 Stress Analysis by the Kolosov-Muskhelishvili Method
Two-dimensional problems in linear elastostatics of homogeneous bodies can be analyzed with the use of analytic functions. The primary quantities of interest are cartesian stress components τ χχ, Tyy, and rxy and displacement components u and v. These can be expressed as
where μ is the shear modulus and κ depends on Poisson’s ratio ν according to κ = 3 — 4ν for plane strain or κ = (3 — ν )/(! + ν ) for plane stress. The above relations are known as the Kolosov-Muskhelishvili formulas [73] and they have been used to solve many practical problems employing series or integral methods. Bod­
ies such as a circular disk, a plate with a circular hole, and a circular annulus can be handled for quite general boundary conditions. Solutions can also be developed for geometries where a rational function is known that maps the interior of a circle onto the desired geometry. Futhermore, complex variable methods provide the most general techniques available for solving a meaningful class of mixed boundary value problems such as contact problems typified by pressing a rigid punch into a half plane.
Fully understanding all of the analyses presented in [72, 73] requires familiarity with contour integration, conformal mapping, and multivalued functions. However, some of the closed form solutions given in these texts can be used without extensive background in complex variable methods or the physical concepts of elasticity the­
ory. With that perspective let us examine the problem of computing stresses in an infinite plate uniformly stressed at infinity and having a general normal stress N (θ) and tangential shear T (θ) applied to the hole. We will use the general solution of Muskhelishvili1 [72] to evaluate stresses anywhere in the plate with particular inter­
est on stress concentrations occurring around the hole. The stress functions Ψ and Φ
TXX + Tyy = 2[Φ (Ζ) + Φ(Ζ)]
Τχχ + Tyy + 2iTxy = 2[ζΦ' (z) + Ψ(ζ)]
2 μ (u + iv) = κφ(ζ) — ζΦ(ζ) — ψ(ζ)
1 C h a p t e r 2 0.
can be represented as follows
Φ(ζ) = ——— ί ---------- -------1- a + β ζ 1 + δζ 2 , σ = e
1 ί' ( N + i T)άσ , „ , „ „ - ΐ , . -2 __„*e
2 πι ,/γ σ — ζ
wher e 7 denotes counterclockwise contour integration around the boundary of the hole and the other constants are given by
.......... . —TX°x, + Trn, + 2iT
a =
xx 1 ' yy c~ _ 'xx 1 ' yy 1 ' xy
4 ’ “ 2
κ 1 r2 π β = - (N + i T)ei eM
1 + κ 2 π J 0
Pa r a me t e r s a and δ depend only on the components of stress at infinity, while β is determined by the force resultant on the hole caused by the applied loading. The quantity N + i T is the boundary value of radial stress Trr and shear stress Tre in polar coordinates. Hence
N + iT = Trr + iTrg , \ζ\ = 1
The transformation formulas relating Cartesian stresses Txx, Tyy, Txy and polar co­
ordinate stresses Trr, Tgg, Tre are
Trr + Tee = Txx + Tyy , Trr + Tee + 2iTre = ( Txx + Tyy + 2iTxy)e
Let us assume that N + i T is expandable in a Fourier series of the form
tt
N + iT = Σ
οηση , σ = eie
where cn can be obtained by integration as
1 Γ2π
c„ = — / {N + i T) a~n de
2 π J 0
or we can compute the approximate coefficients more readily using the FFT. The stress function Ψ(ζ) is related to Φ(ζ) according to
Ι φ ( ζ )
\ζ\> 1
S u b s t i t u t i n g t h e c o mp l e x F o u r i e r s e r i e s i n t o t h e i n t e g r a l f o r mu l a f o r Φ g i v e s
t t
Φ = — 5 3 cnζη + a + β ζ - 1 + δζ- 2 , \ζ\< 1
0
Φ ^ 5 3 °- η ζ η + a + βζ 1 + δζ 2 , \ζ\ > 1
η = 1
η= — οο
tt
Φ = 5 3 αηζ- η , \ζ\ > 1
η=0
These two relations then determine Ψ as
tt
Φ = δ + βζ 1 + ( α + o n — cq)z " + ^ ' [(??. — l ) o n _ 2 — cn—2] z n
η=3
The last equation has the form
tt
Ψ = Σ ^ -η , \ζ\ > 1
η=0
where the coefficients ϋη are obtainable by comparing coefficients of corresponding powers in the two series. Hence, the series expansions of functions Φ(ζ) and Ψ(ζ) can be generated in terms of the coefficients cη and the stress components at infin­
ity. The stresses can be evaluated by using the stress functions. Displacements can also be obtained by integrating Φ and Ψ, but this straightforward calculation is not discussed here.
The program runplate was written to evaluate the above formulas by expanding N + i T using the FFT. Truncating the series for harmonics above some specified order, say np, gives approximations for Φ(ζ) and Ψ(ζ), which exactly represent the solution corresponding to the boundary loading defined by the truncated Fourier series. Using the same approach employed in Chapter 6 we can define N and T as piecewise linear functions of the polar angle θ.
The pr ogr am ut i l i zes sever al r out i nes descr i bed i n t he t abl e bel ow.
w h i c h h a s t h e f o r m
r u n p l a t e
def i ne Ν, T, stresses at infinity, z-points
where results are requested, and the number
of series terms used.
platecrc
computes series coefficients defining the
stress functions.
strfun
evaluates Φ, Ψ, and Φ'.
cartstrs
evaluates Cartesian stresses for given values
of s and the stress functions.
rec2polr
transforms from Cartesian stresses to polar
coordinate stresses.
polflip
simplified interface to function polyval.
The program solves two sample problems. The first one analyzes a plate having no loading on the hole, and stresses at infinity given by tyyy = 1, Tttx = x = 0. Figure 12.11 shows that the circumferential stress on the hole varies between — 1 and
Stress Concentration Around a Circular Hole in a Plate
Figure 12.11: Stress Concentration around a Circular Hole in a Plate
3, producing a stress concentration factor of three due to the presence of the hole. The second problem applies a sinusoidally varying normal stress on the hole while the stresses at infinity are zero. Taking
T=0; t i = [ 0,0,0 ]; t h = l i n s p a c e ( 0,2 * p i,8 1 ); N=[cos(4*th), 1 8 0/p i * t h ];
3
gives the results depicted in
Figure 12.12.
Readers may find it interesting to inves­
tigate how stresses around the hole change with different combinations of stress at infinity and normal stress distributions on the hole.
Harmonic Loading on a Circular Hole in a Plate
Figure 12.12:
Harmonic Loading on a Circular Hole in a Plate
12.14.1 Program Output and Code Program runplate
i: f u n c t i o n r u n p l a t e ( Wh i c h P r o b l e m )
2: % Exampl e: r u n p l a t e ( Wh i c h P r o b l e m )
3: %...........................................................................
4: %
5: % Exampl e t o comput e s t r e s s e s a r o u n d a 6: % c i r c u l a r h o l e i n a p l a t e u s i n g t h e 7: % K o l o s o v - M u s k h e l i s h v i l i met hod.
8: %
9: % Us e r m f u n c t i o n s r e q u i r e d: i o: % p l a t e c r c, s t r f u n, c a r t s t r s,
i i: % r e c 2 p o l r, p o l f l i p, l i n t r p
12:
i 3: i f n a r g i n = = 0
i 4: t i t l = ['S t r e s s C o n c e n t r a t i o n Around a ', ...
i 5: 'C i r c u l a r Hol e i n a P l a t e'];
i 6: N=0; T=0; t i = [ 0,1,0 ]; kapa =2; np=50;
i 7: Nn='N = 0'; T t ='T = 0';
i 8: r z = l i n s p a c e ( 1,3,2 0 )'; t z = l i n s p a c e ( 0,2 * p i,8 1 );
i 9: z = r z * e x p ( i * t z ); x = r e a l ( z ); y = i m a g ( z );
2 0: v i e w p n t = [ - 4 0,1 0 ];
2 i: e l s e
2 2: t i t l = ['H a r m o n i c Lo a d i n g on a C i r c u l a r', ...
2 3: ' Hol e i n a P l a t e'];
2 4: t h = l i n s p a c e ( 0,2 * p i,8 1 )';
2 5: N = [ c o s ( 4 * t h ),1 8 0/p i * t h ];
2 6: Nn='N = c o s ( 4 * t h e t a )'; T t ='T = 0';
2 7: T=0; t i = [ 0,0,0 ]; kapa =2; np=10;
2 8: r z = l i n s p a c e ( 1,2,1 0 )'; t z = l i n s p a c e ( 0,2 * p i,8 1 );
2 9: z = r z * e x p ( i * t z ); x = r e a l ( z ); y = i m a g ( z );
3 0: v i e w p n t = [ - 2 0,2 0 ];
3 i: end
32:
3 3: f p r i n t f ('\n S T R E S S E S IN A PLATE WITH A ')
3 4: f p r i n t f ('CI RCULAR HOLE')
3 5: f p r i n t f ('\n\n S t r e s s component s a t i n f i n i t y ')
3 6: f p r i n t f ('a r e: '); f p r i n t f ('% g ',t i );
3 7: f p r i n t f ('\n N o r m a l s t r e s s e s on t h e h o l e a r e ')
3 8: f p r i n t f ( ['d e f i n e d by ',N n ] );
3 9: f p r i n t f ('\n T a n g e n t i a l s t r e s s e s on t h e h o l e ')
4 0: f p r i n t f ( ['a r e d e f i n e d by ',T t ] )
4 i
42:
43
44
45:
46
47
48
49
50:
5 i
52:
53
54
55:
56
57
58
59
60:
6 i:
62:
63:
64
65:
66
67:
68
69
70:
7 i
72:
73
74
75:
76
77
78
79
80:
8 i
82:
83
84
85:
f p r i n t f ('\n E l a s t i c c o n s t a n t kappa e q u a l s: ') f p r i n t f ('% s',n u m 2 s t r ( k a p a ) ); f p r i n t f ('\n H i g h e s t harmonic o r d e r used i s: ') f p r i n t f ('% s',n u m 2 s t r ( n p ) );
[ a,b,c ] = p l a t e c r c ( N,T,t i,k a p a,n p );
f p r i n t f ('\n');
f p r i n t f ('\n T h e Kol o s o v - Mu s k h e l i s h v i l i s t r e s s '); f p r i n t f ('f u n c t i o n s h a v e\n t h e s e r i e s f o r m s:'); f p r i n t f ('\n P h i = s u m ( a ( k ) * z ~ ( - k + 1 ), k = 1:n p + 1 )'); f p r i n t f ('\n P s i = s u m ( b ( k ) * z ~ ( - k + 1 ), k = 1:n p + 3 )'); f p r i n t f ('\n');
f p r i n t f ('\n C o e f f i c i e n t s d e f i n i n g s t r e s s '); f p r i n t f ('f u n c t i o n Phi a r e:\n'); d i s p ( a (:) );
f p r i n t f ('C o e f f i c i e n t s d e f i n i n g s t r e s s '); f p r i n t f ('f u n c t i o n P s i a r e:\n'); d i s p ( b (:) );
% E val ua t e t h e s t r e s s f u n c t i o n s [ P h i,P s i,P h i p ] = s t r f u n ( a,b,z );
% Compute t h e C a r t e s i a n s t r e s s e s and t h e % p r i n c i p a l s t r e s s e s
[ t x,t y,t x y,p t 1,p t 2 ] = c a r t s t r s ( z,P h i,P s i,P h i p ); t h e t a = a n g l e ( z./a b s ( z ) ); x = r e a l ( z ); y=imag(z); [ t r,t t,t r t ] = r e c 2 p o l r ( t x,t y,t x y,t h e t a ); p m i n = n u m 2 s t r ( m i n ( [ p t 1 (:);p t 2 (:) ] ) ); p m a x = n u m 2 s t r ( m a x ( [ p t 1 (:);p t 2 (:) ] ) );
d i s p (...
['Minimum P r i n c i p a l S t r e s s = ',n u m 2 s t r ( p m i n ) ] ); d i s p (...
['Maximum P r i n c i p a l S t r e s s = ',n u m 2 s t r ( p m a x ) ] ); f p r i n t f ('\n P r e s s [Enter] f o r a s u r f a c e '); f p r i n t f ('p l o t of t h e\n c i r c u m f e r e n t i a l s t r e s s '); f p r i n t f ('i n t h e p l a t e\n'); i n p u t ('','s'); c l f; c l o s e; c o l o r m a p ('h s v');
s u r f ( x,y,t t ); x l a b e l ('x a x i s'); y l a b e l ('y a x i s');
z l a b e l ('C i r c u m f e r e n t i a l S t r e s s');
t i t l e ( t i t l ); g r i d on; vi ew( vi e wpnt ); f i g u r e ( g c f );
%if nargin==0, p r i n t -deps s t r c o n c 1
%else, p r i n t -deps s t r c o n c 2; end
f p r i n t f ('A l l D o n e\n');
89: f u n c t i o n [ a,b,c ] = p l a t e c r c ( N,T,t i,k a p a,n p )
9 0: %
9 i: % [ a,b,c ] = p l a t e c r c ( N,T,t i,k a p a,n p )
86
8 8
9 4: % T h i s f u n c t i o n comput es c o e f f i c i e n t s i n t h e 95: % s e r i e s e x p a n s i o n s t h a t d e f i n e t h e Ko l o s o v - 96: % M u s k h e l i s h v i l i s t r e s s f u n c t i o n s f o r a p l a t e 97: % h a v i n g a c i r c u l a r h o l e o f u n i t r a d i u s. The 98: % p l a t e i s u n i f o r m l y s t r e s s e d a t i n f i n i t y. On 9 9: % t h e s u r f a c e o f t h e h o l e, n o r ma l and t a n g e n t i a l i 0 0: % s t r e s s d i s t r i b u t i o n s N and T d e f i n e d as i o i: % p i e c e w i s e l i n e a r f u n c t i o n s a r e a p p l i e d.
i 0 2: %
i o 3: % N - a two col umn m a t r i x w i t h e a c h row
i o 4: % c o n t a i n i n g a v a l u e o f n o r ma l s t r e s s
i o 5: % and p o l a r a n g l e i n d e g r e e s u s e d t o
i o 6: % s p e c i f y N a s a p i e c e w i s e l i n e a r
i o 7: % f u n c t i o n of t h e p o l a r a n g l e. S t e p
i o 8: % d i s c o n t i n u i t i e s c a n be i n c l u d e d by
i o 9: % u s i n g s u c c e s s i v e v a l u e s o f N w i t h t h e
i i o: % same p o l a r a n g l e v a l u e s. The d a t a
i i i: % s h o u l d c o v e r t h e r a n g e of t h e t a f r om
i i 2: % 0 t o 360. N r e p r e s e n t s b o u n d a r y v a l u e s
i i 3: % o f t h e p o l a r c o o r d i n a t e r a d i a l s t r e s s.
i i 4: % A s i n g l e c o n s t a n t v a l u e c a n be i n p u t
i i 5: % when N i s c o n s t a n t ( i n c l u d i n g z e r o
i i 6: % i f d e s i r e d ).
i i 7: % T - a two col umn m a t r i x d e f i n i n g v a l u e s of
i i 8: % t h e p o l a r c o o r d i n a t e s h e a r s t r e s s on
i i 9: % t h e h o l e d e f i n e d a s a p i e c e w i s e l i n e a r
i 2 o: % f u n c t i o n. The p o i n t s wher e f u n c t i o n
i 2 i: % v a l u e s of T a r e s p e c i f i e d do n o t n e e d
i 2 2: % t o be t h e same a s a s t h o s e u s e d t o
i 2 3: % s p e c i f y N. I n p u t a s i n g l e c o n s t a n t
i 2 4: % when T i s c o n s t a n t on t h e b o u n d a r y.
i 2 5: % t i - v e c t o r of C a r t e s i a n s t r e s s component s i 2 6: % [ t x,t y,t x y ] a t i n f i n i t y.
i 2 7: % k a p a - a c o n s t a n t d e p e n d i n g on P o i s s o n's r a t i o i 2 8: % nu.
i 2 9: % k a p a =3 - 4 * n u f o r p l a n e s t r a i n
i 3 o: % k a p a = ( 3 - n u )/( 1 + n u ) f o r p l a n e s t r e s s
i 3 2
i 3 3:
134
135
136
137 i 3 8:
139
140 i 4 i: i 4 2: i 4 3: i 4 4: i 4 5:
146
147 i 4 8: i 4 9: i 5 0: i 5 i: i 5 2: i 5 3: i 5 4 i 5 5: i 5 6: i 5 7: i 5 8: i 5 9: i 6 0: i 6 i: i 6 2: i 6 3: i 6 4: i 6 5: i 6 6: i 6 7: i 6 8: i 6 9: i 7 0: i 7 i: i 7 2: i 7 3: i 7 4 i 7 5:
i 3 i:
% When t h e r e s u l t a n t f o r c e on t h e hol e
% i s z e r o, t h e n kapa has no e f f e c t on
% t h e s o l u t i o n.
% np - t h e h i g h e s t power of e x p ( i * t h e t a ) used % i n t h e s e r i e s expansion of N+i*T. This
% s houl d not exceed 255.
%
% a - c o e f f i c i e n t s i n t h e s e r i e s expansion
% d e f i n i n g t h e s t r e s s f u n c t i o n
% Phi=sum( a(k)*z~(-k+1), k=1:np+1)
% b - c o e f f i c i e n t s i n t h e s e r i e s expansion
% d e f i n i n g t h e s t r e s s f u n c t i o n
% Psi=sum( b(k)*z~(- k+1), k=1:np+3)
%
% User m f u n c t i o n s c a l l e d: l i n t r p
%-----------------------------------------------------------------------------------------
% Handle case of c o n s t a n t boundary s t r e s s e s i f l e n g t h ( N (:) ) = = 1; N=[N,0;N,360]; end i f l e n g t h ( T (:) ) = = 1; T=[ T,0;T,360]; end
% Expand t h e boundary s t r e s s e s i n a F o u r i e r % s e r i e s
f = p i/1 8 0; nft =512; n p = m i n ( n p,n f t/2 - 1 ); t h t a = l i n s p a c e ( 0,2 * p i * ( n f t - 1 )/n f t,n f t );
% I n t e r p o l a t e l i n e a r l y f o r v a l u e s a t t h e % F o u r i e r p o i n t s
N f t = l i n t r p ( f * N (:,2 ),N (:,1 ),t h t a ); T f t = l i n t r p ( f * T (:,2 ),T (:,1 ),t h t a ); c = f f t ( N f t (:) + i * T f t (:) )/n f t;
% E val ua t e a u x i l i a r y par a m e t e r s i n t h e % s e r i e s s o l u t i o n s
a l p = ( t i ( 1 ) + t i ( 2 ) )/4; b e t = - k a p a * c ( n f t )/( 1 + k a p a ); s i g = ( - t i ( 1 ) + t i ( 2 ) - 2 * i * t i ( 3 ) )/2;
% Generate a and b c o e f f i c i e n t s u s i n g t h e % F o u r i e r c o e f f i c i e n t s of N+i*T. a = z e r o s ( n p + 1,1 ); b= z e r o s ( n p + 3,1 ); j = ( 1:n p )'; a ( j + 1 ) = c ( n f t + 1 - j ); a ( 1 ) = a l p; a ( 2 ) = b e t + c ( n f t ); a ( 3 ) = s i g + c ( n f t - 1 ); j = ( 3:n p + 2 )'; b ( j + 1) = ( j - 1 ).* a ( j - 1 ) - c o n j ( c ( j - 1 ) ); b ( 1 ) = c o n j ( s i g ); b ( 2 ) = c o n j ( b e t ); b ( 3 ) = a l p + a ( 1 ) - c o n j ( c ( 1 ) );
177: % D i s c a r d any n e g l i g i b l y s m a l l h i g h o r d e r 178: % c o e f f i c i e n t s.
1 7 9: t o l = m a x ( a b s ( [ N (:);T (:);t i (:) ] ) )/1 e 4;
1 8 0: k a = m a x ( f i n d ( a b s ( a ) > t o l ) );
1 8 1: i f i s e m p t y ( k a ), a=0; e l s e, a ( k a + 1:n p + 1 ) = [ ]; end 1 8 2: k b = m a x ( f i n d ( a b s ( b ) > t o l ) );
1 8 3: i f i s e m p t y ( k b ), b=0; e l s e, b ( k b + 1:n p + 3 ) = [ ]; end
1 8 4:
1 8 5: %=============================================
1 8 6:
1 8 7: f u n c t i o n [ P h i,P s i,P h i p ] = s t r f u n ( a,b,z )
1 8 8: %
1 8 9: % [ P h i,P s i,P h i p ] = s t r f u n ( a,b,z )
1 9 0: %
1 9 1: %
1 9 2: % T h i s f u n c t i o n e v a l u a t e s t h e compl ex 193: % s t r e s s f u n c t i o n s P h i ( z ) and P s i ( z )
1 9 4: % a s w e l l a s t h e d e r i v a t i v e f u n c t i o n P h i'( z )
1 9 5: % u s i n g s e r i e s c o e f f i c i e n t s d e t e r m i n e d f r om 196: % f u n c t i o n p l a t e c r c. The c a l c u l a t i o n a l s o 197: % u s e s a f u n c t i o n p o l f l i p d e f i n e d s u c h t h a t 198: % p o l f l i p ( a,z ) = p o l y v a l ( f l i p u d ( a (:) ),z ).
1 9 9: %
2 0 0: % a,b - s e r i e s c o e f f i c i e n t s d e f i n i n g Ph i 201: % and P s i
2 0 2: % z - m a t r i x of compl ex v a l u e s
2 0 3: %
2 0 4: % P h i,P s i - compl ex s t r e s s f u n c t i o n v a l u e s 205: % P h i p - d e r i v a t i v e P h i'( z )
2 0 6: %
2 0 7: % Us e r m f u n c t i o n s c a l l e d: p o l f l i p
2 0 8: %-----------------------------------------------------------------------------------------
2 0 9:
2 1 0: z i = 1./z; n p = l e n g t h ( a ); a = a (:);
2 1 1: P h i = p o l f l i p ( a,z i ); P s i = p o l f l i p ( b,z i );
2 1 2: P h i p = - p o l f l i p ( ( 1:n p - 1 )'.* a ( 2:n p ),z i )./z.~ 2;
2 1 3:
2 1 4: %==============================================
2 1 5:
2 1 6: f u n c t i o n [ t x,t y,t x y,t p 1,t p 2 ] = ...
2 1 7: c a r t s t r s ( z,P h i,P s i,P h i p )
2 1 8: %
2 1 9: % [ t x,t y,t x y,t p 1,t p 2 ] = c a r t s t r s ( z,P h i,P s i,P h i p )
2 2 0: %
176:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242:
243:
244:
245:
246:
247:
248:
249:
250:
251:
252:
253:
254:
255:
256:
257:
258:
259:
260:
261:
262:
263:
264:
265:
%
% This f u n c t i o n us es v a l u e s of t h e complex % s t r e s s f u n c t i o n s t o e v a l u a t e C a r t e s i a n s t r e s s % components r e l a t i v e t o t h e x,y axes.
%
% z - m a t r i x of complex v a l u e s where
% s t r e s s e s a r e r e q u i r e d
% P h i,P s i - m a t r i c e s c o n t a i n i n g complex s t r e s s % f u n c t i o n v a l u e s
% Phip - v a l u e s of P h i'( z )
%
% t x,t y,t x y - v a l u e s of t h e C a r t e s i a n s t r e s s % components f o r t h e x,y axes
% t p 1,t p 2 - v a l u e s of maximum and minimum % p r i n c i p a l s t r e s s e s
%
% User m f u n c t i o n s c a l l e d: none
%-----------------------------------------------------------------------------------------
A= 2*r eal ( P hi ); B=c o n j ( z ).* P h i p +P s i;
C=A-B; R=abs(B);
t x = r e a l ( C ); ty=2*A-tx; txy=-imag(C); tp1=A+R; tp2=A-R;
%==============================================
f u n c t i o n [ t r,t t,t r t ] = r e c 2 p o l r ( t x,t y,t x y,t h e t a )
%
% [ t r,t t,t r t ] = r e c 2 p o l r ( t x,t y,t x y,t h e t a )
%...............................................................................................
%
% This f u n c t i o n t r a n s f o r m s C a r t e s i a n s t r e s s % components t x,t y,t x y t o p o l a r c o o r d i n a t e % s t r e s s e s t r,t t,t r t.
%
% t x,t y,t x y - m a t r i c e s of C a r t e s i a n s t r e s s % components
% t h e t a - a m a t r i x of p o l a r c o o r d i n a t e % v a l u e s. This can a l s o be a
% s i n g l e v a l u e i f a l l s t r e s s
% components a r e r o t a t e d by t h e
% same an g l e.
%
% t r,t t,t r t - m a t r i c e s of p o l a r c o o r d i n a t e % s t r e s s e s
266: %
2 6 7: % Us e r m f u n c t i o n s c a l l e d: none
2 6 8: %-----------------------------------------------------------------------------------------------------------------------------------------------
269:
270: i f l e n g t h ( t h e t a (:) ) = = 1
2 7 1: t h e t a = t h e t a * o n e s ( s i z e ( t x ) ); end
2 7 2: a = ( t x + t y )/2;
2 7 3: b = ( ( t x - t y )/2 - i * t x y ).* e x p ( 2 * i * t h e t a );
2 7 4: c=a+b; t r = r e a l ( c ); t t = 2 * a - t r; t r t = - i m a g ( c );
2 7 5:
2 7 6: %==========================================
2 7 7:
2 7 8: f u n c t i o n y = p o l f l i p ( a,x )
2 7 9: %
2 8 0: % y = p o l f l i p ( a,x )
2 8 2: %
2 8 3: % T h i s f u n c t i o n e v a l u a t e s p o l y v a l ( a,x ) w i t h 284: % t h e o r d e r o f t h e e l e m e n t s r e v e r s e d.
2 8 5: %
2 8 6: %---------------------------------------------------------------------------------
2 8 7:
2 8 8: y = p o l y v a l ( a ( e n d:- 1:1 ),x );
2 8 9:
2 9 0: %==========================================
2 9 1:
2 9 2: % f u n c t i o n y = l i n t r p ( x d,y d,x )
2 9 3: % See Appe ndi x B
12.14.2 Stressed Plate with an Elliptic Hole
This chapter is concluded with an example using conformal mapping in elasticity theory. We discussed earlier the useful property that harmonic functions remain harmonic under a conformal transformation. However, linear elasticity leads to the biharmonic Airy stress function which satisfies
d2 d2
d x2 dy2
U = 0
Unfortunately, a conformal transformation x + iy = ω(ξ + ίη) does not imply
d2 d2 d£2 dt f
U = 0
2
2
except when t he mappi ng f unct i on has t he t r i vi al l i near f or m z = c iC + c0. Conse­
quently, the analogy employed in the ideal flow problem is not applicable in linear
elasticity. This does not preclude use of conformal mapping in elasticity, but we encounter equations of very different structure in the mapped variables. We will examine that problem enough to illustrate the kind of differences involved. Let a mapping function z = ω(ζ) define curvilinear coordinate lines in the z-plane. A po­
lar coordinate grid corresponding to arg(C) = constant and |ζ| = constant maps into curves we term ρ lines and a lines, respectively. Plotting of such lines was demon­
strated previously with function gridview (mapping the exterior of a circle onto the exterior of an ellipse). It can be shown that curvilinear coordinate stresses τ ρρ, ταα,
ρα
ar e r el at ed t o car t esi an st r esses accor di ng t o
τρρ + ταα — τχ x + Ty
yy
τ ρρ + τ αα + 2ίτρα — h( τχ χ + τ yy + 2ίτχ y )
where
h =
ζ*'(ζ)
ζ"'(0
Muskhelishvili [72] has developed a general solution for a plate with an elliptic hole allowing general boundary tractions. Here we use one solution from his text which employs the mapping function
= ω(ζ)=ϋ ζ + -
and the stress functions
φ(ζ)
Φ(ζ) dz
ψ(ζ)
Ψ(ζ) dz
When ζ is selected as the primary reference variable, we have to perform chain rule differentiation and write
Φ(ζ) = -
Φ'(ζ)
(ζ)
Ψ'(0
^(0
z
ω'(ζ)φ"(ζ) -ω"(ζ)φ'(ζ)
[ } ^ ( 0 3
in order to compute stresses in terms of the ζ-variable. Readers unaccustomed to using conformal mapping in this context should remember that there is no stress state in the ζ -plane comparable to the analogous velocity components which can be envisioned in a potential flow problem. We are simply using ζ as a convenient reference variable to analyze physical stress and displacement quantities existing only in the z-plane.
Suppose the infinite plate has an elliptic hole defined by
and the hole is free of applied tractions. The stress state at infinity consists of a tension p inclined at angle Λ with the x-axis. The stress functions relating to that problem are found to be ([72], page 338)
Φ(ζ) = ί ζ + -
Ψ { ζ ) = d'( + - + - p r^ — ζ ζ2 - m
pr
Ιζ I > 1
„2 tX
— , c = b(2a — m)
pra _ pra _ pr(ni + —)
2~ ’ 6 ~ _ 2 m ’ 2
Clearly these functions have no obvious relation to the simpler results shown earlier for a plate with a circular hole. The function el iphole computes curvilinear coordi­
nate stresses in the z-plane expressed in terms of the ζ-variable. When Λ = π/2, the plate tension acts along the y-axis and the maximum circumferential stress occurs at z = rx corresponding to ζ = 1. A surface plot produced by eliphole for the default data case using rx = 2 and ry = 1 is shown in
Figure 12.13.
It is also interesting to graph ταα/Tyy as a function of r x/r y. The program elpmaxst produces the plot in Figure 12.14
showing that the circumferential stress concentration increases linearly according to
= 1 + 2 — p ry
whi ch can al so be ver i f i ed di r ect l y f r om t he st r ess f unct i ons.
Circumferential Stress Around an Elliptical Hole
Figure 12.13: Circumferential Stress around an Elliptical Hole
4
Stress Concentration Around an Elliptical Hole
ratio ( max diameter ) / ( min diameter )
Figure 12.14: Stress Concentration around an Elliptical Hole
Program elpmaxst
12.14.3 Program Output and Code
f u n c t i o n elpmaxst % Example: elpmaxst
%...........................................
%
% MATLAB example t o p l o t t h e s t r e s s % c o n c e n t r a t i o n around an e l l i p t i c ho l e % as a f u n c t i o n of t h e s emi - d i a m e t e r r a t i o.
%
% User m f u n c t i o n s r e q u i r e d: e l i p h o l e
rx=2; ry=1; p=1; ang=90; i f p l o t = 1; z e t a = l i n s p a c e ( 1,2,1 1 )'* ...
e x p ( i * l i n s p a c e ( 0,2 * p i,1 2 1 ) ); e l i p h o l e ( r x,r y,p,a n g,z e t a,1 );
r = l i n s p a c e ( 1.0 0 1,1 0,1 9 ); t a m a x = z e r o s ( s i z e ( r ) ); f o r j =1:19
[ t r,t a m a x ( j ) ] = e l i p h o l e ( r ( j ),1,1,9 0,1 );
end
p l o t ( r,t a m a x,'-',r,t a m a x,'o'); t i t l e ( ['S t r e s s C o n c e n t r a t i o n Around an ', ...
'E l l i p t i c a l H o l e'] ); x l a b e l ( ['r a t i o ( max d i amet er ) / ', ...
'( min di a m e t e r )'] ); y l a b e l ( ['( max c i r c u m f e r e n t i a l s t r e s s ) / ',..
'( p l a t e t e n s i o n a t i n f i n i t y )'] ); g r i d on; f i g u r e ( g c f );
%print -deps elpmaxst
%=============================================
f u n c t i o n [ t r,t a,t r a,z ] = e l i p h o l e...
( r x,r y,p,a n g,z e t a,i f p l o t )
%
% [ t r,t a,t r a,z ] = e l i p h o l e ( r x,r y,p,a n g,...
% z e t a,i f p l o t )
%.......................................................................................................
%
% This f u n c t i o n de t e r mi ne s c u r v i l i n e a r % c o o r d i n a t e s t r e s s e s around an e l l i p t i c hol e
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
74
75
76
77
78
79
80
81
82
83
84
85
% i n a p l a t e u ni f or ml y s t r e s s e d a t i n f i n i t y. %
% r x,r y %
%p %
% ang %
% z e t a %
% i f p l o t %
%
%
% t r %
% t a %
%
% t r a %
% z %
%
% User m f u n c t i o n s c a l l e d: none %
-------------------------------------------------------
i f nar gi n< 6, i f p l o t = 0; end i f nargin==0
rx=2; ry=1; p=1; ang=90; i f p l o t = 1; z e t a = l i n s p a c e ( 1,2,1 1 )'* ...
e x p ( i * l i n s p a c e ( 0,2 * p i,1 2 1 ) );
end
% The complex s t r e s s f u n c t i o n s and mapping % f u n c t i o n have t h e form % p h i ( z e t a ) = b * z e t a + c/z e t a
% p s i ( z e t a ) = d * z e t a + e/z e t a + f * z e t a/( z e t a ~ 2 - m )
% z = w ( z e t a ) = r ( z e t a + m/z e t a )
% P h i ( z e t a ) = p h i'( z e t a )/w'( z e t a )
% P s i ( z e t a ) = p s i'( z e t a )/w'( z e t a )
% d ( P h i )/d z = ( w'( z e t a ) * p h i''( z e t a ) -...
% w''( z e t a ) * p h i'( z e t a ) )/w'( z e t a ) ~ 3
r = ( r x + r y )/2; m = ( r x - r y )/( r x + r y );
- e l l i p s e semi di amet ers on t h e x and y axes
- v a l u e s of u n i a x i a l t e n s i o n a t i n f i n i t y
- angl e of i n c l i n a t i o n i n degr ees of t h e t e n s i l e s t r e s s a t i n f i n i t y
- c u r v i l i n e a r c o o r d i n a t e v a l u e s f o r which s t r e s s e s a r e e v a l u a t e d
- o p t i o n a l par a me t er t h a t i s gi ven a v a l u e i f a s u r f a c e p l o t of t h e c i r c u m f e r e n t i a l s t r e s s i s d e s i r e d
- t e n s i l e s t r e s s normal t o an e l l i p t i c a l c o o r d i n a t e l i n e
- t e n s i l e s t r e s s i n a d i r e c t i o n t a n g e n t i a l t o t h e e l l i p t i c a l c o o r d i n a t e l i n e
- s h e a r s t r e s s complementary t o t h e normal s t r e s s e s
- p o i n t s i n t h e z p l a n e where s t r e s s e s a r e computed
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
z = r * ( z e t a + m./z e t a ); z e t a 2 = z e t a.~ 2; z e t a 3 = z e t a.~ 3; wp=r * ( 1 - m./z e t a 2 ); wpp=2*r*m./zeta3; a=e xp(2*i *pi/180*a ng); b=p*r/4; c=b*(2*a-m); d = - p * r/2 * c o n j ( a ); e=-p*r/2*a/m; f=p*r/2*(m+1/m)*(a-m); p h i p = b - c./z e t a 2; p h i p p = 2 * c./z e t a 3; h=wp.*zeta; h = h./c o n j ( h );
Phi=phip./wp; Phipz=(wp.*phi pp-wpp.*phip)./wp.~3; P s i = ( d - e./z e t a 2 - f * ( z e t a 2 + m )./( z e t a 2 - m ).~ 2 )./w p; A =2 * r e a l ( P h i ); B = ( c o n j ( z ).* P h i p z + P s i ).* h;
C=A-B; t r = r e a l ( C ); t a = 2 * A - t r; t ra=imag( B); i f i f p l o t > 0
% c o l o r m a p ('g r a y'); b r i g h t e n (.9 5 ); s u r f ( r e a l ( z ),i m a g ( z ),t a ); x l a b e l ('x a x i s'); y l a b e l ('y a x i s'); z l a b e l ('c i r c u m f e r e n t i a l s t r e s s'); t i t l e ( ['C i r c u m f e r e n t i a l S t r e s s Around ', ...
'a n E l l i p t i c a l H o l e'] ); g r i d on; f i g u r e ( g c f ); i n p u t ('','s');
%print -deps e l i p h o l e end
Chapiter 13
Nonlinear Optimization Applications
13.1 Basic Concepts
Optimization problems occur for a diverse range of topics. Perhaps the simplest type of optimization problem involves a scalar function of several variables. For ex­
ample, the cost of a product having several ingredients may need to be minimized. This problem can be represented by a function F (x) which depends on the vec­
tor x = [xi; x 2;...; xn] in n-dimensional space. Function F is called the objec­
tive function and cases where the independent variables x x can vary arbitrarily are considered unconstrained. Most problems have constraints requiring x x to remain within given bounds or satisfy other functional equations. Different analysis proce­
dures exist for solving problems depending on whether they are linear or nonlinear, constrained or unconstrained. General solutions are available to handle linear objec­
tive functions with linear equality and inequality constraints. The discipline devoted to such problems is known as linear programming [41] and applications involving thousands of independent variables can be analyzed. 1 Although this class of linear problems is important, it does not offer the versatility of methods used to address nonlinear problems (which are more compute intensive for problems of similar di­
mensionality).2 The material in this chapter addresses nonlinear problems with a few independent variables which are either constrained or restricted to lie within bounds of the form
a < x t < bt.
Thi s t ype of const r ai nt can be sat i sf i ed by t aki ng
x i ai + ( bt Sin (zi )
and letting z* vary arbitrarily. The MATLAB intrinsic functions fminbnd and fmin- search are employed for solving this class of problems. The following five examples are presented to illustrate the nature of nonlinear optimization methods:
1. Computing the inclination angle necessary to cause a projectile to strike a stationary distant object;
1 Hi gh di mensi onal i t y l i near pr obl ems shoul d al ways b e sol ved us i ng t he appr opr i at e speci al i zed soft ware.
2The Mat hWorks mar ket s an “Opt i mi zat i on Tool box” i nt ended t o sat i sfy a number of speci al i zed opt i ­
mi zat i on needs.
2. Finding parameters of a nonlinear equation to closely fit a set of data values;
3. Determining components of end force on a statically loaded cable necessary to make the endpoint assume a desired position;
4. Computing the shape of a curve between two points such that a smooth particle slides from one end to the other in the minimum time;
5. Determining the closest points on two surfaces.
Before addressing specific problems, some of the general concepts of optimization will be discussed.
The minimum of an unconstrained differentiable function
F (xi,x 2, ...,xn)
wi l l occur at a poi nt wher e t he f unct i on has a zer o gr adi ent. Thus t he condi t i on
dF
—— = 0 , 1 < i < n
dxi
l eads t o n nonlinear simultaneous equations. Such systems often have multiple so­
lutions, and a zero gradient indicates either a maximum, or a minimum, or a saddle point. No reliable general methods currently exist to obtain all solutions to a general system of nonlinear equations. However, practical situations do occur where one unique point providing a relative minimum is expected. In such cases F (x) is called unimodal and we seek x 0 which makes
F (xo) < F (xo + Δ) for |Δ| > 0.
Most unconstrained nonlinear programming software starts from an initial point and searches iteratively for a point where the gradient vanishes. Multimodal, or non- unimodal, functions can sometimes be solved by initiating searches from multiple starting points and using the best result obtained among all the searches. Since sit­
uations such as false convergence are fairly common with nonlinear optimization methods, results obtained warrant greater scrutiny than might be necessary for linear problems.
The intrinsic MATLAB functions fminbnd and fminsearch are adequate to ad­
dress many optimization problems. Readers should study the documentation avail­
able for fminbnd, which performs a one-dimensional search within specified limits, and fminsearch, which performs an unconstrained multi-dimensional search starting from a user selected point. Both functions require objective functions of acceptable syntactical form. Various options controlling convergence tolerances and function evaluation counts should be studied to insure that the parameter choices are appro­
priately defined.
Projectile Trajectory f o r Velocity Squared Drag
x axis
Figure 13.1: Projectile Trajectory for v 2 Drag Condition
13.2 Initial Angle for a Projectile
In Chapter 8, equations of motion for motion of a projectile with atmospheric drag were formulated and a function traject producing a solution y(x) passing through (x, y) = (0,0) with arbitrary inclination was developed. The solution is generated for 0 < x < x f assuming the initial velocity is large enough for the projectile to reach x f. Therefore, program execution terminates if dx/dt goes to zero. In order to hit a target at position (xf ,y f ), the starting angle of the trajectory must be selected iteratively because the equations of motion cannot be solved exactly (except for the undamped case). With the aid of an optimization method we calculate \y(x f ) — yf )| and minimize this quantity (described in function missdis which has the firing angle as its argument). Function fminbnd seeks the angle to minimize the “miss” distance. Program runtraj illustrates the solution to the problem described and
Figure 13.1
shows the trajectory required for the projectile to strike the object.
Depending on the starting conditions, zero, one, or two solutions exist to cause the “miss” distance to approach zero. Function fminbnd terminates at either a local minimum or at one of the search limits. The reader will need to examine how the initial data correlate to the final answers. For example, if the projectile misses the target by a significant amount, the initial projectile velocity was not large enough to reach the target.
Program Output and Code Trajectory Analysis Program
f u n c t i o n r u n t r a j Exampl e: r u n t r a j
T h i s p r o g r a m i n t e g r a t e s t h e d i f f e r e n t i a l e q u a t i o n s g o v e r n i n g t w o - d i m e n s i o n a l mo t i o n of a p r o j e c t i l e s u b j e c t e d t o g r a v i t y l o a d i n g and a t m o s p h e r i c d r a g p r o p o r t i o n a l t o t h e v e l o c i t y s q u a r e d. The i n i t i a l i n c l i n a t i o n a n g l e n e e d e d t o h i t a d i s t a n t t a r g e t i s comput ed r e p e a t e d l y and f u n c t i o n f mi n i s empl oyed t o mi n i mi z e t h e s q u a r e of t h e d i s t a n c e by whi ch t h e t a r g e t i s m i s s e d. The o p t i m a l v a l u e of t h e mi s s d i s t a n c e i s z e r o and t h e opt i mum a n g l e w i l l t y p i c a l l y be f o u n d u n l e s s t h e i n i t i a l v e l o c i t y i s t o o s m a l l and t h e h o r i z o n t a l v e l o c i t y becomes z e r o b e f o r e t h e t a r g e t i s p a s s e d. The i n i t i a l v e l o c i t y of t h e p r o j e c t i l e mus t be l a r g e enough t o make t h e p r o b l e m w e l l p o s e d. O t h e r w i s e, t h e p r o g r a m w i l l t e r m i n a t e w i t h an e r r o r me s s a g e.
Us e r m f u n c t i o n s c a l l e d: m i s s d i s, t r a j e c t,
p r o j c t e q
c l e a r a l l;
g l o b a l V i n i t Gr a v t y Cdr ag X f i n l Y f i n l
v i n i t = 6 0 0; g r a v t y = 3 2.2; c d r a g = 0.0 0 2; x f i n l = 1 0 0 0; y f i n l = 1 0 0;
d i s p (' ');
di sp('SEARCH FOR INITIAL INCLINATION ANGLE '); d i s p ('T O MAKE A PROJECTILE STRIKE A DISTANT'); d i s p ('O B J E C T'); d i s p (' ');
d i s p ( ['I n i t i a l v e l o c i t y = ',n u m 2 s t r ( v i n i t ) ] ); d i s p ( ['G r a v i t y c o n s t a n t = ',n u m 2 s t r ( g r a v t y ) ] ); d i s p ( ['D r a g c o e f f i c i e n t = ',n u m 2 s t r ( c d r a g ) ] ); d i s p ( ['C o o r d i n a t e s of t a r g e t = (', ...
1
2
3
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
74
75
76
77
78
79
80
81
82
83
84
85
n u m 2 s t r ( x f i n l ),',',... n u m 2 s t r ( y f i n l ),')'] ); d i s p (' ');
% R e p l i c a t e i n p u t d a t a as g l o b a l v a r i a b l e s V i n i t = v i n i t; Gravt y=gravt y; Cdrag=cdrag; X f i n l = x f i n l; Y f i n l = y f i n l;
% Perform t h e mi n i m i z a t i o n s e a r c h f s t a r t = 1 8 0/p i * a t a n ( y f i n l/x f i n l ); fend=75; d i s p ('P l e a s e wa it f o r compl et i on of t h e') d i s p ('m i n i m i z a t i o n s e a r c h'); b e s t a n g = f m i n b n d ( @ m i s s d i s,f s t a r t,f e n d );
% Di s p l a y f i n a l r e s u l t s [ y,x,t ] = t r a j e c t ...
( b e s t a n g,v i n i t,g r a v t y,c d r a g,x f i n l ); d m i s s = a b s ( y f i n l - y ( l e n g t h ( y ) ) ); d i s p (' ') d i s p ( ['F i n a l miss d i s t a n c e i s ', ...
n u m 2 s t r ( d m i s s ),' when t h e'] ); d i s p ( ['i n i t i a l i n c l i n a t i o n angl e i s ', ... n u m 2 s t r ( b e s t a n g ),...
' d e g r e e s'] );
%==========================================
f u n c t i o n [ d s q,x,y ] = m i s s d i s ( a n g l e )
%
% [ d s q,x,y ] = m i s s d i s ( a n g l e )
%.............................................................
%
% This f u n c t i o n i s used by fminbnd. I t r e t u r n s % an e r r o r measure i n d i c a t i n g how much t h e % t a r g e t i s missed f o r a p a r t i c u l a r i n i t i a l % i n c l i n a t i o n angl e of t h e p r o j e c t i l e.
%
% angl e - t h e i n i t i a l i n c l i n a t i o n angl e of
% t h e p r o j e c t i l e i n degr ees
%
% dsq - t h e s qua r e of t h e d i f f e r e n c e between % Y f i n a l and t h e f i n a l v a l u e of y found
% u s i n g f u n c t i o n t r a j e c t.
% x,y - p o i n t s on t h e t r a j e c t o r y.
%
% S e v e r a l g l o b a l pa r a m e t e r s ( V i n i t, Gravty,
% Cdrag, X f i n l ) a r e pa s s e d t o m i s s d i s by t h e
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
% d r i v e r program r u n t r a j.
%
% User m f u n c t i o n s c a l l e d: t r a j e c t %
-----------------------------------------------------------------------------------------
g l o b a l V i n i t Gravty Cdrag X f i n l Y f i n l [ y,x,t ] = t r a j e c t ...
( a n g l e,V i n i t,G r a v t y,C d r a g,X f i n l,1 );
d s q = ( y ( l e n g t h ( y ) ) - Y f i n l ) ~ 2;
%=============================================
f u n c t i o n [ y,x,t ] = t r a j e c t ...
( a n g l e,v i n i t,g r a v t y,c d r a g,x f i n l,n o p l o t )
%
% [ y,x,t ] = t r a j e c t ...
% ( a n g l e,v i n i t,g r a v t y,c d r a g,x f i n l,n o p l o t )
%....................................................................................................................
%
% This f u n c t i o n i n t e g r a t e s t h e dynamical % e q u a t i o n s f o r a p r o j e c t i l e s u b j e c t e d t o % g r a v i t y l o a d i n g and at mospheri c drag % p r o p o r t i o n a l t o t h e s quar e of t h e v e l o c i t y.
%
% angl e - i n i t i a l i n c l i n a t i o n of t h e % p r o j e c t i l e i n degr ees
% v i n i t - i n i t i a l v e l o c i t y of t h e p r o j e c t i l e % (muzzle v e l o c i t y )
% g r a v t y - t h e g r a v i t a t i o n a l c o n s t a n t % cdrag - drag c o e f f i c i e n t s p e c i f y i n g t h e % drag f o r c e p e r u n i t mass which
% e q u a l s c d r a g * v e l o c i t y ~ 2.
% x f i n l - t h e p r o j e c t i l e i s f i r e d toward t h e % r i g h t from x=0. x f i n l i s t h e
% l a r g e s t x v a l u e f o r which t h e
% s o l u t i o n i s computed. The i n i t i a l
% v e l o c i t y must be l a r g e enough t h a t
% atmospheri c damping does not reduce
% t h e h o r i z o n t a l v e l o c i t y t o ze r o
% b e f o r e x f i n l i s r e a che d. Otherwise
% an e r r o r t e r m i n a t i o n w i l l occur.
% n o p l o t - p l o t t i n g of t h e t r a j e c t o r y i s % o m i t t e d when t h i s par amet er i s
% gi ven an i n p u t v al u e
%
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
% y,x,t - t h e y, x and time v e c t o r s produced % by i n t e g r a t i n g t h e e q u a t i o n s of
% motion
%
% Global v a r i a b l e s:
%
% g r a v, - two c o n s t a n t s r e p l i c a t i n g g r a v t y and % dragc cdr ag, f o r use i n f u n c t i o n p r o j c t e q % v t o l - equal t o v i n i t/1 e 6, used i n p r o j c t e q
% t o check whether t h e h o r i z o n t a l
% v e l o c i t y has been reduced t o z e ro
%
% User m f u n c t i o n s c a l l e d: p r o j c t e q %-----------------------------------------------------------------------------------------
g l o b a l grav dragc v t o l
% D e f a u l t d a t a case g e n e r a t e d when i n p u t i s n u l l i f n a r g i n ==0
angle=45; v i n i t = 6 0 0; g r a vt y= 32.2; cdrag=0.002; xf i nl =1000; end;
% Assign g l o b a l v a r i a b l e s and e v a l u a t e % i n i t i a l v e l o c i t y
gr a v=gr avt y; dragc=cdrag; ang=pi/180*angl e; v t o l = v i n i t/1 e 6;
z 0 = [ v i n i t * c o s ( a n g ); v i n i t * s i n ( a n g ); 0; 0];
% I n t e g r a t e t h e e q u a t i o n s of motion d e f i n e d % i n f u n c t i o n p r o j c t e q d e o p t n = o d e s e t ('R e l T o l',1 e - 6 ); [ x,z ] = o d e 4 5 ('p r o j c t e q',[ 0,x f i n l ],z 0,d e o p t n );
y = z (:,3 ); t = z (:,4 ); n = l e n g t h ( x ); x f = x ( n ); y f = y ( n );
% P l o t t h e t r a j e c t o r y curve i f n a r g i n < 6
p l o t ( x,y,'k -',x f,y f,'k o'); x l a b e l ('x a x i s'); y l a b e l ('y a x i s'); t i t l e ( ['P r o j e c t i l e T r a j e c t o r y f o r ', ...
'V e l o c i t y Squared D r a g'] ); a x i s ('e q u a l'); g r i d on; f i g u r e ( g c f );
%print -deps t r a j p l o t
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
end
%=
f u n c t i o n z p = p r o j c t e q ( x,z )
%
% z p = p r o j c t e q ( x,z )
%% ~~~~~~~~~~~~~~~~
% This f u n c t i o n d e f i n e s t h e e q u a t i o n of motion % f o r a p r o j e c t i l e loaded by g r a v i t y and % atmospheri c dr a g p r o p o r t i o n a l t o t h e squar e % of t h e v e l o c i t y.
%
% x - t h e h o r i z o n t a l s p a t i a l v a r i a b l e
% z - a v e c t o r c o n t a i n i n g [vx; vy; y; t ];
%
% zp %
%
% Global v a r i a b l e s:
%
t h e d e r i v a t i v e dz/dx which e q u a l s [ v x'( x ); v y'( x ); y'( x ); t'( x ) ];
% grav - % dragc - %
% v t o l - %
%
% User m f u n c t i o n s c a l l e d: %------------------------------------------------
t h e g r a v i t y c o n s t a n t
t h e dr a g c o e f f i c i e n t d i v i d e d by
g r a v i t y
a g l o b a l v a r i a b l e used t o check whether vx i s ze ro
none
g l o b a l grav dragc v t o l
vx=z( 1); vy=z( 2); v=sqrt(vx~2+vy~2);
% Check t o see whether dr a g reduced t h e % h o r i z o n t a l v e l o c i t y t o z e r o b e f o r e t h e % x f i n l was r e ac he d. i f abs(vx) < v t o l d i s p (' ');
disp('ERROR i n f u n c t i o n p r o j c t e q. The '); d i s p (' i n i t i a l v e l o c i t y of t h e p r o j e c t i l e'); d i s p (' was not l a r g e enough f o r x f i n a l t o'); d i s p (' be r e a c h e d.'); disp('EXECUTION IS TERMINATED.');
221: '); 2 2 2: d i s p (' '),e r r o r (' ');
2 2 3: end
2 2 4: z p = [ - d r a g c * v; - ( g r a v + d r a g c * v * v y )/v x; ...
2 2 5: v y/v x; 1/v x ];
13.3 Fitting Nonlinear Equations to Data
Often an equation of known form is needed to approximately fit some given data values. An equation y(t) to fit m data values (tl,yl ) might be sought from an equa­
tion expressible as
y f (a 1, a2, · · ·, an, t)
where n parameters a1,a2, . . . ,an are needed to minimize the least squares error
n
e ( a 1 ■ a2, . . . ■ an) ''''ζ* ^ [y3 f ( a 1 ■ a2 ■} ... an ■ t 3)] .
3=1
The smallest possible error would be zero when the equation passes exactly through all the data values. Function e can be minimized with an optimizer such as fmin­
search, or conditions seeking a zero gradient of e which require
de rxr ( d f\
— = 2 ^ [/( α 1ια2ι..,α ηι ί 3) - y 3\
3=1 \ /
can be wr i t t en. Not e t hat t he pr obl em of mi ni mi zi ng a f unct i on and t he pr obl em of sol vi ng a set of nonl i near si mul t aneous equat i ons ar e cl osel y r el at ed. Sol vi ng l ar ge syst ems of nonl i near equat i ons i s di ffi cul t. Ther ef or e, dat a f i t t i ng by us e of f unct i on mi ni mi zat i on pr ocedur es i s t ypi cal l y mor e ef fect i ve.
The f or mul at i on assumi ng y depends on a single independent variable could just as easily have involved several independent variables x 1,x 2,...,x N, which would yield an equation of the form
y = f (a 1,a2,...,an,X1,X2,...,XN).
For i nst ance, we mi ght choos e t he si mpl est usef ul equat i on dependi ng l i near l y on t he i ndependent var i abl es
N
y = xk ak
k=0
wh e r e x 0 = 1. The least squares error can be expressed as
N 2
n
e(a0· a 1· . ..■ an') ^ ^
3=1
y j - Σ X jk ak
k=0
where X 3k means the value of the kth independent variable at the j th data point. The condition that e have a zero gradient gives
N
N
k=0
Y JX3iX3k
1-3=1
ak = 5 3 X3iy3 ■ 1 — I — N.
3=1
This linear system can be solved using traditional methods. Since the multiple in­
dices in the equation are slightly cryptic, expressing the relationship in matrix nota­
tion is helpful. We get
Y & X A
where
y1
a0
y2
a1
Y =
■ X = [ 1,X1,X2,...,Xn] ■ A =
yn
aN
with X t being the column matrix [x l 1,x l2,..., xin ] and the first column of X con­
tains all ones. The requirement to minimize e is simply
(XT X )A = X T Y
and MATLAB produces the desired solution using
n
n
A=X\Y;
Although taking y as a linear function of parameters a 0,a1,...,a N produces solv­
able linear equations, the general situation yields nonlinear equations, and a min­
imization search procedure has greater appeal. We conclude this section with an example employing a minimization search.
Consider an experiment where data values (t l,yl ) are expected to conform to the transient response of a linear harmonic oscillator governed by the differential equa­
tion
m0 y + c0 y + k0 y = 0.
This equation has a solution representable as
y = a 1 e-la2lt cos( |a3|t + a4)
wher e la2 1 makes the response decay exponentially and la3 1 assures that the damped natural frequency is positive. Minimizing the error function
n 2
e( a1, a,2, a,3, 0,4 ) = 53 ^ 3 - a1 e- 1 a2 t] cos(|a3It3 + 0,4 )
requires a four-dimensional search.
Data Approxi mati ng y = 1.5*exp( -.1*t) *cos( 2.5 *t+pi/4 )
time
Figure 13.2: Data Approximating y = 1.5 exp—0.1i) cos(2.5t + π/4)
The program vibfit tests data deviating slightly from an equation employing spe­
cific values of ai,a2,a3,a4. Then function fminsearch is used to verify whether the coefficients can be recovered from the data points. Figure 13.2 shows the data values and the equation resulting from the nonlinear least square fit. The results produced are quite acceptable.
Program Output and Code Program vibfit
i: f u n c t i o n v i b f i t 2: %
3: % Exampl e: v i b f i t
5: %
6: % T h i s p r o g r a m i l l u s t r a t e s u s e of t h e N e l d e r 7: % and Mead m u l t i - d i m e n s i o n a l f u n c t i o n 8: % m i n i m i z a t i o n met hod t o d e t e r m i n e an e q u a t i o n 9: % f o r y ( t ) whi ch d e p e n d s n o n l i n e a r l y on s e v e r a l i o: % p a r a m e t e r s c h o s e n t o c l o s e l y f i t known d a t a
11:
12
13
14:
15:
16
17
18
19
2o:
21:
22
23:
24:
25:
26
27:
28
29
3o:
31:
32
33
34:
35:
36
37
38
39
4o:
41:
42
43
44
45
46
47
48
49
5o:
51:
52
53
54:
55:
% v a l u e s. The program minimizes t h e sum of t h e % s q u a r e s of e r r o r d e v i a t i o n s between t h e d a t a % v a l u e s and r e s u l t s produced by t h e chosen % e q u a t i o n. The example p e r t a i n s t o t h e time % r e s ponse curve c h a r a c t e r i z i n g f r e e v i b r a t i o n s % of a damped l i n e a r harmonic o s c i l l a t o r.
%
% User m f u n c t i o n s c a l l e d: v i b f u n %
% Make t h e d a t a v e c t o r s g l o b a l t o all ow % ac c e s s from f u n c t i o n v i b f u n g l o b a l t i md a t ydat
echo o f f; d i s p (' ');
d i s p (' CHOOSING PARAMETERS');
d i s p (' IN THE THE NONLINEAR EQUATION'); d i s p (' Y = A*EXP(B*T)*COS(C*T+D)'); di s p ('T O OBTAIN THE BEST FIT TO GIVEN DATA'); f p r i n t f ('\n P r e s s [Enter] t o l i s t f u n c t i o n\n'); f p r i n t f ('v i b f u n which i s t o be m i n i m i z e d\n'); pause;
% Generate a s e t of d a t a t o be f i t t e d by a % chosen e q u a t i o n. a=1.5; b = -.1; c=2.5; d =p i/5; t i m d a t = 0:.2:2 0;
y d a t = a * e x p ( b * t i m d a t ).* c o s ( c * t i m d a t + d );
% Add some random n o i s e t o t h e d a t a y d a t = y d a t +.1 * ( -.5 + r a n d ( s i z e ( y d a t ) ) );
% Funct i on v i b f u n d e f i n e s t h e q u a n t i t y t o be % minimized by a s e a r c h u s i n g f u n c t i o n fmins. d i s p (' ');
d i s p ('T h e f u n c t i o n t o be minimized i s:'); t y p e vi bfun.m; d i s p (' ');
d i s p ('T h e i n p u t d a t a w i l l be p l o t t e d n e x t.'); d i s p ('P r e s s [Enter] t o c o n t i n u e'); pause; p l o t ( t i m d a t,y d a t,'k.'); t i t l e ('I n p u t D a t a'); x l a b e l ('t i m e'); y l a b e l ('y a x i s'); g r i d o f f; f i g u r e ( g c f ); i n p u t ('','s');
% I n i t i a t e t h e f o u r - d i m e n s i o n a l s e a r c h
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
x=fmi nsearch(@vi bfun,[1 1 1 1 ] );
% Check how we l l t h e computed p a r amet er s % f i t t h e d a t a.
aa =x(1); b b = - a b s ( x ( 2 ) ); c c = a b s ( x ( 3 ) ); dd=x(4); a s =num2s t r ( a a); bs=num2str(bb); cs =num2s t r ( c c); ds=num2str(dd); t t r p = 0:.0 5:2 0;
y t r p = a a * e x p ( b b * t t r p ).* c o s ( c c * t t r p + d d ); d i s p (' ');
d i s p ('P r e s s [Enter] t o see how w e l l'); d i s p ('t h e e q u a t i o n f i t s t h e d a t a'); pause; p l o t ( t t r p,y t r p,'k -',t i m d a t,y d a t,'k.'); s t r 1 = ['A p p r o x. e q u a t i o n i s y = ', ...
'a * e x p ( b * t ) * c o s ( c * t + d )']; s t r 2 = ['a = ',a s,' b = ',b s,' c = ', ...
c s,' d = ',d s ]; t e x t ( 6,- 1.1,s t r 1 ); t e x t ( 6,- 1.2 5,s t r 2 ); x l a b e l ('t i m e'); y l a b e l ('y a x i s'); t i t l e ( ['D a t a Approximating ', ...
'y = 1.5 * e x p ( -.1 * t ) * c o s ( 2.5 * t + p i/4 )'] ); g r i d o f f; f i g u r e ( g c f ); p r i n t -deps appr xdat
%=============================================
f u n c t i o n z=vi bf un(x)
%
% z=vi bf un(x)
%%~~~~~~~~~~~
% This f u n c t i o n e v a l a u t e s t h e l e a s t s quar e % e r r o r f o r a s e t of v i b r a t i o n d a t a. The d a t a % v e c t o r s t i md a t and ydat a r e p a s s e d as g l o b a l % v a r i a b l e s. The f u n c t i o n t o be f i t t e d i s:
%
% y=a *e xp(b*t )*cos( c*t +d)
%
% x - a v e c t o r d e f i n i n g a,b,c and d %
% z - t h e s quar e of t h e norm f o r t h e v e c t o r
% of e r r o r d e v i a t i o n s between t h e d a t a and
% r e s u l t s t h e e q u a t i o n g i v e s f o r c u r r e n t
% par amet er v a l u e s
%
1 0 1: % Us e r m f u n c t i o n s c a l l e d: none
1 0 2: %-------------------------------------------------------------------------------
1 0 3:
1 0 4: g l o b a l t i m d a t y d a t
1 0 5: a = x ( 1 ); b = - a b s ( x ( 2 ) ); c = a b s ( x ( 3 ) ); d = x ( 4 ); 1 0 6: z = a * e x p ( b * t i m d a t ).* c o s ( c * t i m d a t + d ) ;
1 0 7: z = n o r m ( z - y d a t ) ~ 2;
13.4 Nonlinear Deflections of a Cable
We will now present an optimization procedure to determine the static equilibrium position of a perfectly flexible inextensible cable having given end positions and a known distributed load per unit length. If R(s) is the position of any point on the cable as a function of arc length 0 < s < L, then the internal tension at position s is
T(s) = Fe + ί q(s) ds
s
with q(s) being the applied force per unit length and F e being the support force at s = L. The end force to produce a desired end deflection has to be determined in the analysis. However, the end deflection resulting from any particular choice of end force can be computed by observing that the tangent to the deflection curve will point along the direction of the cable tension. This means
dR T(s)
~cL· ~ |T(s)|
and
Γ T(s)ds _ f s ( F e + t f q d s ) ds
{S)- J 0 ~ p ( s )\~ J o \Fe + J ^ qds\
wher e R( 0 ) = 0 i s t aken as t he posi t i on at t he st ar t i ng end. The def l ect i on at s = L will have some specified position R e so that requiring R( L) = R e gives a vector equation depending parametrically on F e. Thus, we need to solve three nonlinear simultaneous equations in the Cartesian components of force F e. A reasonable an­
alytical approach is to employ an optimization search to minimize \R(L) — R e\ in terms of the components of F e.
The procedure described for a cable with continuous loading extends easily to a cable having several rigid links connected at frictionless joints where arbitrary concentrated forces are applied. The function cabldefl evaluates the position of each joint when the joint forces and outer end force are given. With the end force on the last link treated as a parameter, function endfl computes an error measure \F(L) — R e \2 to be minimized using function fminsearch. The optimization search seeks the components of F e needed to reduce the error measure to zero. Specifying a sensible problem obviously requires that \R e \ must not exceed the total length of all members
Deflection Shape f o r a Loaded Cable
Figure 13.3: Deflected Shape for a Loaded Cable
in the chain. Initiating the search with a randomly generated starting force leads to a final force produced by fminsearch, which is then employed in another call to cabldefl to determine and plot the final deflection position as shown in Figure 13.3. Using a random initial guess for the end force was done to show that choosing bad starting data, insufficiently stringent convergence tolerances, or too few allowable function iterations can sometimes produce erroneous results. This emphasizes the need to always examine the results from nonlinear search procedures to assure that satisfactory answers are obtained.
Program Output and Code Program cablsolv
i: f u n c t i o n [ r,t,p e n d s ] = c a b l s o l v ( L e n,P,R e n d )
2: %
3: % [ r,t,p e n d s ] = c a b l s o l v ( L e n,P,R e n d )
4: % ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5: %
6: % T h i s f u n c t i o n comput es t h e e q u i l i b r i u m 7: % p o s i t i o n f o r a c a b l e composed o f r i g i d 8: % w e i g h t l e s s l i n k s w i t h l o a d s a p p l i e d a t t h e 9: % f r i c t i o n l e s s j o i n t s. The e n d s o f t h e c a b l e i o: % a r e as s umed t o h a v e a known p o s i t i o n.
11: %
12
13
14
15
16
17
18
19
2o:
21:
22:
23
24:
25
26
27
28
29
3o:
31:
32:
33
34:
35
36
37
38
39
4o:
41:
42
43
44
45
46
47
48
49
5o:
51:
52:
53:
54:
55
56
% Len - a v e c t o r c o n t a i n i n g t h e l e n g t h s
% Len( 1), ..., Len(n)
% P - m a t r i x of f o r c e components a p p l i e d
% a t t h e i n t e r i o r j o i n t s. P (:,i )
% c o n t a i n s t h e C a r t e s i a n components of
% t h e f o r c e a t j o i n t i.
% Rend - t h e c o o r d i n a t e v e c t o r g i v i n g t h e
% p o s i t i o n of t h e o u t e r end of t h e l a s t
% l i n k, assuming t h e o u t e r end of t h e
% f i r s t l i n k i s a t [ 0,0,0 ].
%
% r - a m a t r i x wi t h rows g i v i n g t h e
% computed e q u i l i b r i u m p o s i t i o n s of a l l
% ends
% t - a v e c t o r of t e n s i o n v a l u e s i n t h e
% l i n k s
% pends - a m a t r i x havi ng two rows which % c o n t a i n t h e f o r c e components a c t i n g
% a t bot h ends of t h e ch a i n t o m a i n t a i n
% e q u i l i b r i u m
%
% User m f u n c t i o n s c a l l e d: e n d f l, c a b l d e f l
i f n a r g i n < 3
% Example f o r a t e n l i n k c a b l e wi t h v e r t i c a l % and l a t e r a l l oads L en= 1.5*ones ( 10,1); Rend=[10,0,0]; P = o n e s ( 9,1 ) * [ 0,- 2,- 1 ]; end
g l o b a l l e n p rend
len=Len; rend=Rend; p=P; t ol =sum( Len)/1e8;
% S t a r t t h e s e a r c h wi t h a random f o r c e a p p l i e d % a t t h e f a r end
% Perform s e v e r a l s e a r c h e s t o minimize t h e % l e n g t h of t h e v e c t o r from t h e o u t e r end of % t h e l a s t l i n k t o t h e d e s i r e d p o s i t i o n Rend % where t h e l i n k i s t o be connected t o a % s u p p o r t. The f i n a l end f o r c e s houl d reduce % t h e d e f l e c t i o n e r r o r t o ze ro i f t h e s e a r c h % i s s u c c e s s f u l.
o p t s = o p t i m s e t ('t o l x',t o l,'t o l f u n',t o l,
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
'm a x f u n e v a l s',2 0 0 0 );
endval=realmax;
% I t e r a t e s e v e r a l t i me s t o avoi d f a l s e % convergence f o r k=1:5
p 0 = 1 0 * m a x ( a b s ( p (:) ) ) * r a n d ( s i z e ( p,2 ),1 ); [ p e n d k,e n d v a l k,e x i t f ] =... f m i n s e a r c h ( @ e n d f l,p 0,o p t s ); i f endvalk < endval
pend=pendk(:); endval=endvalk; end
end
% Use t h e computed end f o r c e t o o b t a i n t h e % f i n a l d e f l e c t i o n. Also r e t u r n t h e % s u p p o r t f o r c e s.
[ r,t,p s t a r t ] = c a b l d e f l ( l e n,[ p;p e n d'] ); x = r (:,1 ); y = r (:,2 ); z = r (:,3 ); p e n d s = [ p s t a r t (:)';p e n d (:)'];
% P l o t t h e d e f l e c t i o n curve of t h e c a b l e p l o t 3 ( x,y,z,'k -',x,y,z,'k o'); x l a b e l ('x a x i s'); y l a b e l ('y a x i s'); z l a b e l ('z a x i s'); t i t l e ('D e f l e c t i o n Shape f o r a Loaded C a b l e'); a x i s ('e q u a l'); g r i d on; f i g u r e ( g c f ); p r i n t -deps d e f c a b l e
%=============================================
f u n c t i o n en d e r r = e n d f l ( p e n d )
%
% e n d e r r =e n d f l ( p e n d )
%~~~~~~~~~~~~~~~~~~
%
% This f u n c t i o n computes how much t h e % p o s i t i o n of t h e o u t e r end of t h e l a s t l i n k % d e v i a t e s from t h e d e s i r e d p o s i t i o n when an % a r b i t r a r y f o r c e pend a c t s a t t h e c a b l e end.
%
% pend - v e c t o r of f o r c e components a p p l i e d % a t t h e o u t e r end of t h e l a s t l i n k
%
% e n d e r r - t h e d e f l e c t i o n e r r o r d e f i n e d by t h e % s quar e of t h e norm of t h e v e c t o r
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
% from t h e computed end p o s i t i o n and
% t h e d e s i r e d end p o s i t i o n. This e r r o r
% s houl d be ze r o f o r t h e f i n a l
% e q u i l i b r i u m p o s i t i o n
%
% User m f u n c t i o n s c a l l e d: c a b l d e f l %
-------------------------------------------------------------------------------------
% Pass t h e l e n g t h s, t h e i n t e r i o r f o r c e s and t h e % d e s i r e d p o s i t i o n of t h e o u t e r end of t h e l a s t % l i n k as g l o b a l v a r i a b l e s. g l o b a l l e n p rend
% use f u n c t i o n c a b l d e f l t o compute t h e % d e s i r e d e r r o r r = c a b l d e f l ( l e n,[ p;p e n d (:)'] ); r l a s t = r ( s i z e ( r,1 ),:); d = r l a s t (:) - r e n d (:); e n d e r r = d'* d;
%=============================================
f u n c t i o n [ r,t,p b e g i n ] = c a b l d e f l ( l e n,p )
%
% [ r,t,p b e g i n ] = c a b l d e f l ( l e n,p )
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~
%
% This f u n c t i o n computes t h e s t a t i c e q u i l i b r i u m % p o s i t i o n f o r a c a b l e of r i g i d w e i g h t l e s s % l i n k s havi ng c o n c e n t r a t e d l o a d s a p p l i e d a t % t h e j o i n t s and t h e o u t s i d e of t h e l a s t l i n k.
% The o u t s i d e of t h e f i r s t l i n k i s p o s i t i o n e d % a t t h e o r i g i n.
%
% l e n - a v e c t o r of l i n k l e n g t h s
% l e n ( 1 ), ..., l e n ( n )
% p - a m a t r i x wi t h rows g i v i n g t h e
% f o r c e components a c t i n g a t t h e
% i n t e r i o r j o i n t s and a t t h e o u t e r
% end of t h e l a s t l i n k
%
% r - m a t r i x havi ng rows which gi v e t h e
% f i n a l p o s i t i o n s of each node
% t - v e c t o r of member t e n s i o n s
% pbegi n - f o r c e a c t i n g a t t h e o u t e r end of
% t h e f i r s t l i n k t o ac hie ve
147: % e q u i l i b r i u m
1 4 8: %
1 4 9: % Us e r m f u n c t i o n s c a l l e d: none
1 5 0: %------------------------------------------------------------------------------------------------------------------------------------------------------------
151:
1 5 2: n = l e n g t h ( l e n ); l e n = l e n (:); n d = s i z e ( p,2 );
1 5 3:
1 5 4: % Compute t h e f o r c e s i n t h e l i n k s 155: T = f l i p u d ( c u m s u m ( f l i p u d ( p ) ) );
1 5 6: t = s q r t ( s u m ( ( T.~ 2 )')');
1 5 7:
1 5 8: % O b t a i n t h e d e f l e c t i o n s o f t h e o u t e r ends 159: % and t h e i n t e r i o r j o i n t s
1 6 0: r = c u m s u m ( T./t (:,o n e s ( 1,n d ) ) .* l e n (: ,o n e s ( 1,n d ) ) ); 1 6 1: r = [ z e r o s ( 1,n d );r ]; p b e g i n = - t ( 1 ) * r ( 2,:)/l e n ( 1 );
13.5 Quickest Time Descent Curve (the Brachistochrone)
The subject of variational calculus addresses methods to find a function producing the minimum value for an integral depending parametrically on the function. Typi­
cally, we have a relationship of the form
/■ X 2
I ( y ) = G( x,y,y'( x ) ) dx
J Xi
wh e r e v a l u e s o f y at x = xi and x = x 2 are known, and y(x) for xi < x < x 2 is sought to minimize I. A classical example in this subject is determining a curve starting at (0,0) and ending at (a, b) so that a smooth particle will slide from one end to the other in the shortest possible time. Let X and Y be measured positive to the right and downward. Then the descent time for frictionless movement along the curve will be
i r 11 + Y'(x)2
‘ = 7 rsl \K w ^'i X - y <o> = o, n.) = !·.
This probl em is solved in various advanced calculus books.3 The curve is a cycloid expressed in parametric form as
X = k [θ - 8ίπ(θ)] , Y = k[1 - οοβ(θ)]
3Wei nst ock [105] provi des an excel l ent di scussi on of t he br achi st ochr one pr obl em usi ng cal cul us of var i ­
at i on met hods.
where 0 < θ < θf. Values of θ f and k are found to make x (θ f ) = a and Y (θ f ) = b. The exact descent time is
which is significantly smaller than the descent time for a straight line, which is
Two functions, brfaltim and bracifun, are used to compute points on the brachis­
tochrone curve and evaluate the descent time.
The main purpose of this section is to illustrate how optimization search can be used to minimize an integral depending parametrically on a function. The method used chooses a set of base points through which an interpolation curve is constructed to specify the function. Using numerical integration gives a value for the integral. Holding the x values for the interpolation points constant and allowing the y values to vary expresses the integral as a function of the y values at a finite number of points. Then a multi-dimensional search function such as fminsearch can optimize the choice of Y values. Before carrying out this process for the brachistochrone problem it is convenient to change variables so that x = X/a and
For any selected set of interpolation points, functions spline and splined can eval­
uate y(x) and y'(x) needed in the integrand, and function gcquad can be used to perform Gaussian integration. An optimization search employing fminsearch pro­
duces the curve heights yielding an approximation to the brachistochrone as shown in
Figure 13.4.
2 ( a 2 + 52 )
gb
Y(X) = b[x + y(x)] , 0 < x < 1,
wi t h
y(0 ) = y(1) = 0.
Then the descent integral becomes
y/b
Brachistochrone Curve f o r a/b = 3
x/a
Figure 13.4: Brachistochrone Curve for § = 3
Program Output and Code
Program brachist
1: f u n c t i o n b r a c h i s t 2: % Exampl e: b r a c h i s t
3: %...........................................................................
4: % T h i s p r o g r a m d e t e r m i n e s t h e s h a p e of a 5: % s moot h c u r v e down whi ch a p a r t i c l e c a n s l i d e 6: % i n minimum p o s s i b l e t i m e. The a n a l y s i s 7: % empl oys a p i e c e w i s e c u b i c s p l i n e t o d e f i n e 8: % t h e c u r v e by i n t e r p o l a t i o n u s i n g a f i x e d s e t 9: % of b a s e p o i n t p o s i t i o n s. The c u r v e s h a p e 10: % becomes a f u n c t i o n of t h e h e i g h t s c h o s e n a t 11: % t h e b a s e p o i n t s. The s e h e i g h t s a r e d e t e r m i n e d 12: % by c o mp u t i n g t h e d e s c e n t t i m e a s a f u n c t i o n 13: % of t h e h e i g h t s and m i n i m i z i n g t h e d e s c e n t 14: % t i m e by u s e o f an o p t i m i z a t i o n p r o g r a m. The 15: % N e l d e r and Mead u n c o n s t r a i n e d s e a r c h 16: % p r o c e d u r e i s u s e d t o comput e t h e minimum.
17: %
1 8: % Us e r m f u n c t i o n s c a l l e d:
19: % c h b p t s, b r f a l t i m, f l t i m, g c q u a d,
2 0: % b r a c i f u n, s p l i n e d
21:
2 2: g l o b a l cbp cwf c o f s n xc yc a b b _ o v e r _ a ...
2 3: g r a v n p a r t s nquad n f c l s
24:
2 5: f p r i n t f (...
2 6: '\nBRACHISTOCHRONE DETERMINATION BY NONLINEAR'); 2 7: f p r i n t f ('\n OPTIMIZATION SEARCH \n');
2 8: f p r i n t f ( ['\n P l e a s e w a i t. The ',...
2 9: 'c a l c u l a t i o n t a k e s a w h i l e.\n'] );
30:
3 1: % I n i t i a l i z e
3 2: a=30; b=10; g r a v = 3 2.2; n p a r t s = 1; nquad=50;
3 3: t o l = 1 e - 4; n=6; b _ o v e r _ a = b/a;
34:
3 5: [ d u m m y,c b p,c w f ] = g c q u a d ('',0,1,n q u a d,n p a r t s );
3 6: x c = c h b p t s ( 0,1,n ); x c = x c (:);
3 7: y 0 = 5 * s i n ( p i * x c ); x c = [ 0;x c;1 ];
38:
3 9: % C a l c u l a t e r e s u l t s f r o m t h e e x a c t s o l u t i o n 40: [ t e x a c t,x e x a c t,y e x a c t ] = b r f a l t i m ( a,b,g r a v,1 0 0 );
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
74:
75
76
77
78:
79:
80:
81:
82
83
84
85
% Perform m i n i m i z a t i o n s e a r c h f o r % approximate s o l u t i o n o p t s = o p t i m s e t ('t o l x',t o l,'t o l f u n',t o l ); [ y f m i n,f m i n,f l a g,o u t p ] =...
f m i n s e a r c h ( @ f l t i m,y 0,o p t s );
% E val ua t e f i n a l p o s i t i o n and approximate % d e s c e n t time
Xfmin=xc; Yfmi n=Xfmin+[0;yfmin(:);0];
% t f m i n = a/s q r t ( 2 * g r a v * b ) * f l t i m ( y f m i n (:) ); t f m i n = a/s q r t ( 2 * g r a v * b ) * f m i n; n f c l s =1+ out p.f unc Count;
% Summary of c a l c u l a t i o n s f p r i n t f ('\n B r a c h i s t o c h r o n e Summary');
f p r i n t f ('\n ---------------------------------------------');
f p r i n t f ('\n N u m b e r of f u n c t i o n c a l l s: ');
f p r i n t f ('% g',n f c l s ); f p r i n t f ('\n D e s c e n t t i me: ');
f p r i n t f ('% g',t f m i n ), f p r i n t f ('\n')
% P l o t r e s u l t s comparing t h e approximate % and e x a c t s o l u t i o n s x p l o t = l i n s p a c e ( 0,1,1 0 0 ); y p l o t = s p l i n e ( X f m i n,Y f m i n,x p l o t ); p l o t ( x p l o t,- y p l o t,'-',X f m i n,- Y f m i n,'o', ...
x e x a c t/a,- y e x a c t/b,'—'); x l a b e l ('x/a'); y l a b e l ('y/b'); % g r i d t i t l e ( ['B r a c h i s t o c h r o n e Curve f o r ', ...
'a/b = ',n u m 2 s t r ( a/b ) ] ); t e x t (.5,-.1, 'Descent time ( s e c s )')
t e x t (.5,-.1 7 5,['A p p r o x i m a t e: ',n u m 2 s t r ( t f m i n ) ] ) t e x t (.5,-.2 5, ['E x a c t: ',n u m 2 s t r ( t e x a c t ) ] );
t e x t (.5,-.3 2 5, ...
s p r i n t f ('E r r o r t o l e r a n c e: % g',t o l ) );
l e gend('Appr oxi mat e C u r v e', ...
'Computed P o i n t s','E x a c t C u r v e',3 ); f i g u r e ( g c f ); p r i n t -deps b r a c h i s t
%=============================================
f u n c t i o n [ t f a l l,x b r a c,y b r a c ] = b r f a l t i m ...
( a,b,g r a v,n p t s )
86
87
88
89
90:
91:
92:
93
94:
95
96
97
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
[ t f a l l,x b r a c,y b r a c ] = b r f a l t i m ( a,b,g r a v,n p t s )
This f u n c t i o n det e r mi ne s t h e d e s c e n t time and a s e t of p o i n t s on t h e b r a c h i s t o c h r o n e curve p a s s i n g t hr ough (0,0) and ( a,b ).
The curve i s a c y c l o i d e x p r e s s i b l e i n p a r a m e t r i c form as
x = k * ( t h - s i n ( t h ) ), y = k * ( 1 - c o s ( t h ) ) f o r 0<=th<=thf
where t h f i s found by s o l v i n g t h e e q u a t i o n
b/a = ( 1 - c o s ( t h f ) )/( t h f - s i n ( t h f ) ).
Once t h f i s known t h e n k i s found from
k = a/( t h - s i n ( t h ) ).
The e x a c t v a l u e of t h e d e s c e n t time i s gi ven
by
t f a l l = s q r t ( k/g ) * t h f
a,b - f i n a l v a l u e s of ( x,y) on t h e curve grav - t h e g r a v i t y c o n s t a n t n p t s - t h e number of p o i n t s computed on t h e curve
t f a l l - t h e ti me r e q u i r e d f o r a smooth
p a r t i c l e t o s l i d e al ong t h e curve from ( 0,0) t o ( a,b ) xbrac - x p o i n t s on t h e curve wi t h x i n c r e a s i n g t o t h e r i g h t ybrac - y p o i n t s on t h e curve wi t h y i n c r e a s i n g downward
User m f u n c t i o n s c a l l e d: none
b r f n = i n l i n e ('c o s ( t h ) - 1 + c o f * ( t h - s i n ( t h ) )','t h','c o f');
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
ba=b/a; [ t h,f v a l,f l a g ] = f z e r o (...
b r f n,[.0 1,1 0 ],o p t i m s e t ('f z e r o'),b a );
k = a/( t h - s i n ( t h ) ); t f a l l = s q r t ( k/g r a v ) * t h; i f nargin==4
t h v e c = ( 0:n p t s - 1 )'* ( t h/( n p t s - 1 ) );
x b r a c = k * ( t h v e c - s i n ( t h v e c ) );
y b r a c = k * ( 1 - c o s ( t h v e c ) );
end
%=============================================
f u n c t i o n x=chbpts(xmin,xmax,n)
%
% x=chbpts(xmin,xmax,n)
%~~~~~~~~~~~~~~~~~~~~~
% Determine n p o i n t s wi t h Chebyshev s p a c i n g % between xmin and xmax.
%
% User m f u n c t i o n s c a l l e d: none
%-----------------------------------------------------------------------------------------
x=(xmin+xmax)/2+((xmin-xmax)/2)* ... c o s ( p i/n * ( ( 0:n - 1 )'+.5 ) );
%=============================================
f u n c t i o n t = f l t i m ( y )
%
% t = f l t i m ( y )
%%~~~~~~~~~~
% This f u n c t i o n e v a l u a t e s t h e t ime d e s c e n t % i n t e g r a l f o r a s p l i n e curve havi ng h e i g h t s % s t o r e d i n y.
%
% y - v e c t o r d e f i n i n g t h e curve h e i g h t s a t % i n t e r i o r p o i n t s c o r r e s p o n d i n g t o base % p o s i t i o n s i n xc %
% t - t h e n u m e r i c a l l y i n t e g r a t e d time d e s c e n t % i n t e g r a l e v a l u a t e d by use of base p o i n t s % cbp and weight f a c t o r s cwf p a s s e d as % g l o b a l v a r i a b l e s %
176: % Us e r m f u n c t i o n s c a l l e d: s p l i n e d
1 7 7: %------------------------------------------------------------------------------------------------------------------------------------------------------------
178:
1 7 9: g l o b a l xc c o f s n p a r t s bp wf n f c l s cbp cwf ...
1 8 0: b _ o v e r _ a
1 8 1:
1 8 2: n f c l s = n f c l s + 1; x=cbp;
1 8 3:
1 8 4: % G e n e r a t e c o e f f i c i e n t s u s e d i n s p l i n e 185: % i n t e r p o l a t i o n 1 8 6: y c = [ 0;y (:);0 ];
1 8 7: y = s p l i n e ( x c,y c,x ); y p = s p l i n e d ( x c,y c,x );
1 8 8:
1 8 9: % E v a l u a t e t h e i n t e g r a n d
1 9 0: f = ( 1 + ( b _ o v e r _ a * ( 1 + y p ) ).~ 2 )./( x + y ); f = s q r t ( f );
1 9 1:
1 9 2: % E v a l u a t e t h e i n t e g r a l 193: t = c w f (:)'* f (:);
1 9 4:
1 9 5: %==============================================
1 9 6:
1 9 7: % f u n c t i o n [ v a l,b p,w f ] = g c q u a d ( f u n c,x l o w,...
1 9 8: % x h i g h,n q u a d,m p a r t s,v a r a r g i n )
1 9 9: % See Appe ndi x B
2 0 0:
2 0 1: %==============================================
2 0 2:
2 0 3: % f u n c t i o n v a l = s p l i n e d ( x d,y d,x,i f 2 )
2 0 4: % See Appe ndi x B
13.6 Determining the Closest Points on Two Surfaces
Determining the closest points on two surfaces arises in applications such as robotic collision avoidance and container packing. Many types of surfaces can be parameter­
ized using two curvilinear coordinates; so, the problem reduces to a four dimensional search to minimize the length of a line from a point on one surface to a point on the other surface. We call this the proximity problem and will consider typical instances involving two circular cylinders arbitrarily positioned in space as illustrated by the test examples of
Figure 13.5
. This application illustrates that, despite the appar­
ent simplicity of this problem, convergence difficulties can occur with minimization search procedures, and several runs may be needed to get correct results.
An elementary way to analyze the proximity of two surfaces is to describe each surface by a grid of points and find the smallest element in a matrix describing the distance from point i of the first surface to a point j of the second surface. Large array
z axis
CASE 1
CASE 2
CASE 3 CASE 4
Figure 13.5: Geometry for Four Test Cases
dimensions can occur since a typical 100 by 100 surface grid involves 10,000 points and 30,000 coordinate values. The adjacency matrix for two surfaces, each using 10,000 points, has one hundred million points and would consume 2400 megabytes of memory when stored unpartitioned. However, memory limitations can be over­
come by processing a few points at a time. In the program given below, a function surf2surf is presented to perform exhaustive search. It works well for the cylinder to cylinder problem and also handles some special cases. Since points and space curves are degenerate examples of surfaces, surf2surf can solve problems like obtaining the point on a curve closest to an arbitrary point in space.
For surfaces described by equations of the form r(s 1,s 2) and R( s3 ,s 4 ), the prox­
imity problem can be treated by minimizing norm(r — R ) 2 as a function of [s i , s2, s3 , s4]. In this context, let us discuss briefly the concepts used in function fmin­
search based on the flexible polyhedron search procedure developed by Nelder and Mead [ ]. The search employs a polyhedron having n + 1 corners in n space, which are initially aggregated about a starting point x 0. A sequence of moves repeatedly replaces corners at which the objective function has maximum values, with new cor­
ners corresponding to smaller values. Ultimately, the polyhedron is reduced in size and contracts to a point where the objective function is perceived to have a rela­
tive minimum. The algorithm embodied in fminsearch is useful but it sometimes gives false convergence. This experience led the authors to implement, for compari­
son purposes, a somewhat shorter version of the Nelder and Mead algorithm given in function nelmed shown in the following program cylclose. This program is designed to solve four test problems using functions fminsearch, nelmed, or surf2surf. Both implementations of the flexible polyhedron search are vulnerable to false conver­
gence; so, it is necessary to initiate the search several times using random starting points. By making enough trials so that the same best result is obtained several times, reasonable confidence in the answers can be achieved. Furthermore, the pro­
gram shows images of the cylinders and connecting minimum distance lines. These images can be rotated interactively to observe the validity of results. In the test cases considered, about eight trials was sufficient to produce the same best results at least twice. Some results showing computer output for case 4 are typical.
c y l c l o s e ( l );
CASE 4 USING FUNCTION NELMED
T r i a l
Minimum
F u n c t i o n
Number
D i s t a n c e
E v a l u a t i o n
l
1.915
163
2
1.916
161
3
1.710
207
4
2.293
156
5
1.710
154
6
2.165
139
7
2.165
122
8
1.710
182
The a n a l y s i s used FUNCTION NELMED S h o r t e s t Di st ance = 1.710
Function Eval ua ti ons = 1284
Compute Time = 4.450 secs
c y l c l o s e ( 1 );
CASE 4 USING FUNCTION FMINSEARCH
T r i a l
Minimum
Function
Number
Dist ance
Eval uati ons
1
1.710
223
2
2.293
472
3
2.293
693
4
2.293
295
5
2.165
286
6
2.165
585
7
1.710
265
8
1.915
231
The a n a l y s i s used
FUNCTION FMINSEARCH
S h o r t e s t
Dist ance
= 1.710
Function
Eval ua ti ons = 3 0 50
Compute Time c y l c l o s e ( 3 );
= 10.930 secs
CASE 4 USING EXHAUSTIVE SEARCH
S h o r t e s t
Dist ance
= 1.729
Function
Eval ua ti ons = 546
Compute
Time
= 0.440 secs
Note that incorrect answers were obtained repeatedly by fminsearch and nelmed, whereas exhaustive search gave the fastest and most reliable solution. Readers in­
terested in exploring the convergence problems occurring with the Nelder and Mead search will find it instructive to run program cylclose to observe the variations in re­
sults produced from randomly chosen starting points. This example problem shows clearly that, unless the best result among a number of trials is taken, an incorrect answer may occur.
13.6.1 Discussion of the Computer Code
Program cylclose uses minimization search to determine the closest points on two arbitrarily positioned circular cylinders. Three solution methods are provided using functions fminsearch, nelmed, or surf2surf. Four test cases are included, and other
geometries can be analyzed by modifying data lines in function cylclose. The various modules in the program are listed in the following table.
Routine
Line
Operation
cylclose
1-155
several functions are called to plot the geom­
etry and perform the minimization search
cylpoint
159-178
gives the position of a point on a cylinder sur­
face
dcyl2cyl
182-197
computes the distance between points on two cylinders
cylfigs
201 -244
plots the geometries for four data cases
plot2cyls
248-276
plots the geometry for two cylinders
cylpts
280-300
generates a grid of points on a cylinder sur­
face
crnrpts
304-321
generates a dense set of points in an increas­
ing set of data set
ortbas
325-332
creates orthonormal base vectors needed to define cylinder geometry
nelmed
336-475
function which performs the Nelder-Mead search
surf2surf
479-513
uses discrete search to compute closest points on two surfaces defined by coordinate grids. Large grids can be handled by calling func­
tion srf2srf
srf2srf
517-534
uses discrete search to compute closest points on two surfaces defined by coordinate grids
rads
538-550
gives base radii for example problems
Program cylclose
f u n c t i o n [ d b e s t,r,R ] = c y l c l o s e ( s r c h t y p e,...
n t r i a l s,s i d l e n,t o l x,t o l f ) % [ d b e s t,r,R ] = c y l c l o s e ( s r c h t y p e,n t r i a l s,...
% s i d l e n,t o l x,t o l f )
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
%
% This program l o c a t e s t h e p o i n t s c l o s e s t % t o g e t h e r on t h e s u r f a c e s of two c i r c u l a r % c y l i n d e r s a r b i t r a r i l y p o s i t i o n e d i n s pace.
% A f o u r - d i m e n s i o n a l u n c o n s t r a i n e d s e a r c h % i s performed u s i n g f u n c t i o n s NELMED,
% FMINSEARCH, or SURF2SURF. The q u a n t i t y
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
minimized i s t h e s quar e of t h e d i s t a n c e from an a r b i t r a r y p o i n t on one c y l i n d e r t o an a r b i t r a r y p o i n t on t h e o t h e r c y l i n d e r. The s e a r c h p a r amet er s s p e c i f y a x i a l and c i r c u m f e r e n t i a l c o o r d i n a t e s of p o i n t s on t h e c y l i n d e r s u r f a c e s.
s r c h t y p e - s e l e c t s t h e s o l u t i o n method. Use 1,2, or 3 f o r NELMED, FMINSEARCH, or SURF2SURF n t r i a l s - Number of t i me s t h e s o l u t i o n i s
r e p e a t e d t o avoi d f a l s e convergence s i d l e n - i n i t i a l polyhedron s i d e l e n g t h
t o l x - Convergence t o l e r a n c e on s o l u t i o n
v e c t o r
t o l f - Convergence t o l e r a n c e on f u n c t i o n
v al u e
User m f u n c t i o n s c a l l e d:
c y l p o i n t, d c y l 2 c y l, c y l f i g s, p l o t 2 c y l s c y l p t s, c o r n r p t s, o r t b a s i s, nelmed, surfmany, s u r f 2 s u r f, s r f 2 s r f, r a d s
i f nar gi n< 5, t o l f = 1 e - 4; end
i f nar gi n< 4, t o l x = 1 e - 2; end
i f nar gi n< 3, s i d l e n =.5; end
i f nar gi n< 2, n t r i a l s = 8; end
i f nar gi n< 1, s rc htype =1; end
i f srchtype==1
fname='FUNCTION NELMED'; e l s e i f srchtype==2
fname='FUNCTION FMINSEARCH'; e l s e
fname='EXHAUSTIVE SEARCH'; end
d i s p (' '),
d i s p (' CYLINDER PROXIMITY ANALYSIS') disp('USING A FOUR-DIMENSIONAL SEARCH')
c y l f i g s, drawnow, d i s p (' '), d u m y = i n p u t (... 'P r e s s r e t u r n t o b eg i n t h e s e a r c h','s'); c l o s e; ncases=4;
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
f o r j c a s e = 1:n c a s e s
d i s p (' '), disp(['CASE ',...
n u m 2 s t r ( j c a s e ),' USING ',f n a m e ] )
% Define s e v e r a l d a t a c ases s w i t c h j c a s e case 1
rad=1; len=3; r 0 = [ 4,0,0 ]; v = [ 0,0,1 ];
Rad=1; Len=3; R 0 = [ 0,4,0 ]; V = [ 0,0,1 ]; case 2
rad=1; len=3; r 0 = [ 4,0,0 ]; v = [ 3,0,4 ];
Rad=1; Len=3; R 0 = [ 0,4,0 ]; V = [ 0,3,4 ]; case 3
rad=1; len=5; r 0 = [ 4,0,0 ]; v = [ - 4,0,3 ];
Rad=1; Len=5; R 0 = [ 0,4,0 ]; V = [ 0,0,1 ]; case 4
rad=1; l e n = 4 * s q r t ( 2 ); r 0 = [ 4,0,0 ];
v = [ - 1,1,0 ];
Rad=1; Len=3; R 0 = [ 0,0,- 2 ]; V = [ 0,0,- 1 ]; end
% C r e a t e d a t a p a r ame t er s used r e p e a t e d l y % d u r i n g t h e s e a r c h p r o c e s s
% F i r s t c y l i n d e r d a t = c u m s u m ( [ 0;r a d;l e n;r a d ] ); d a t = d a t/m a x ( d a t ); z d a t = [ d a t,[ 0;0;l e n;l e n ] ]; r d a t = [ d a t,[ 0;r a d;r a d;0 ] ]; m = o r t b a s i s ( v );
% Second c y l i n d e r dat=cumsum([0;Rad;Len;Rad]); d a t = d a t/m a x ( d a t ); Z d a t = [ d a t,[ 0;0;L e n;L e n ] ]; R d a t = [ d a t,[ 0;R a d;R a d;0 ] ]; M=ortbasis(V);
% Make s e v e r a l s e a r c h e s s t a r t i n g from % randomly chosen p o i n t s and keep % t h e b e s t answer o b t a i n e d n t o t a l = 0; n t y p e = z e r o s ( 1,5 ); d i s p (' ') t i c; dbest =real max; o p t s = o p t i m s e t; i f srchtype<3
d i s p ('T r i a l Minimum F u n c t i o n')
disp('Number Di s t a n c e E v a l u a t i o n s')
f o r k = 1:n t r i a l s
w i n i t = 2 * p i * r a n d ( 4,1 );
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
i f srchtype==1 % Search u s i n g nelmed
[ w,f m i n,n v a l s,n t y p ] = n e l m e d ( @ d c y l 2 c y l,... w i n i t,s i d l e n,t o l x,t o l f,2 0 0 0,0,.. . r 0,m,r d a t,z d a t,R 0,M,R d a t,Z d a t ); e l s e i f srchtype==2 % Search u s i n g f mi ns e ar ch [ w,f m i n,x f l a g,o u t p ] = f m i n s e a r c h ( @ d c y l 2 c y l,... w i n i t,o p t s,r 0,m,r d a t,z d a t,R 0,M,R d a t,Z d a t ); nv al s =o u t p.f u n cC o u n t; n t y p = z e r o s ( 1,5 ); end
d k = s q r t ( d c y l 2 c y l ( w,r 0,m,r d a t,z d a t,...
R0,M,Rda t,Zdat )); f p r i n t f ('% 4 i %8.3f % 7 i\n',k,d k,n v a l s ) i f dk<dbest, dbest=dk; W=w; end n t o t a l = n t o t a l + n v a l s; ntype=ntype+ntyp; end
w=W; r = c y l p o i n t ( w ( 1 ),w ( 2 ),r 0,m,r d a t,z d a t );
R= c y l p o i n t ( w ( 3 ),w ( 4 ),R 0,M,R d a t,Z d a t );
t = t o c;
f p r i n t f ( ['\n T h e a n a l y s i s used ',f n a m e,'\n'] )
%if srchtype==1
% f p r i n t f ( ['\n R e f l e c t Expand C o n t r a c t ',...
% 'S h r i n k \n%4i %7i %9i % 7 i\n'],n t y p e ( 2 ),...
% n t y p e ( 3 ),n t y p e ( 4 ),n t y p e (5))
%end
e l s e
d p l o t = 0.3; t i c;
[ x,y,z,X,Y,Z ] = p l o t 2 c y l s ( r a d,l e n,r 0,v,... R a d,L e n,R 0,V,d p l o t,' '); c l o s e; [ d b e s t,r,R ] = s u r f 2 s u r f ( x,y,z,X,Y,Z ); n t o t a l = l e n g t h ( x ) * l e n g t h ( X ); t = t o c; end
f p r i n t f (...
['S h o r t e s t Di s t a n c e = % 8.3 f\n',...
'F u n c t i o n E v a l u a t i o n s = % 8 i\n',...
'Compute Time = %8.3f s e c s\n'],...
d b e s t,n t o t a l,t )
n=1; R r = r e p m a t ( R,1,n + 1 ) + ( r - R ) * ( 0:n )/n; ho l d o f f; c l f,
t i t l = ['C A S E ',n u m 2 s t r ( j c a s e ),' USING ',f n a m e ]; d p l o t = 0.3; p l o t 2 c y l s (...
r a d,l e n,r 0,v,R a d,L e n,R 0,V,d p l o t,t i t l ); colormap([1 1 0 ] ), hol d on, p l o t 3 ( R r ( 1,:),R r ( 2,:),R r ( 3,:),'l i n e w i d t h',2 ) t i t l e ( [ t i t l,' : DISTANCE = ',...
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
n u m 2 s t r ( d b e s t ),', CPU TIME = ',... n u m 2 s t r ( t ),' SECS']) r o t a t e 3 d on, shg, d i s p (' ') d i s p ('R o t a t e t h e f i g u r e or p r e s s') d i s p ('r e t u r n t o c o n t i n u e') dumy=input(' ','s'); c l o s e
end
%===========================================
f u n c t i o n r = c y l p o i n t ( w 1,w 2,r 0,m,r d a t,z d a t )
% r = c y l p o i n t ( w 1,w 2,v,r 0,m,r d a t,z d a t )
%.....................................................................................
% This f u n c t i o n computes t h e p o s i t i o n of a % p o i n t on t h e s u r f a c e of a c i r c u l a r c y l i n d e r % a r b i t r a r i l y p o s i t i o n e d i n s pac e. The argument % l i s t p a r amet er s have t h e f o l l o w i n g form,
% where r a d means c y l i n d e r r a d i u s, and l e n % means c y l i n d e r l e n g t h.
% b=2*rad+len;
% z d a t = [ [ 0,0 ]; [ r a d/b, 0];
% [ ( r a d + l e n )/b, l e n ];[ 1, l e n ] ];
% r d a t = z d a t; r d a t ( 2,2 ) = r a d;
% r d a t ( 3,2 ) = r a d; r d a t ( 4,2 ) = 0;
u=2*pi*sin(w1)~2; v=sin(w2)~2; z = i n t e r p 1 ( z d a t (:,1 ),z d a t (:,2 ),v ); r h o = i n t e r p 1 ( r d a t (:,1 ),r d a t (:,2 ),v ); x=r ho*c os ( u); y = r h o * s i n ( u ); r = r 0 (:) + m * [ x;y;z ];
%===========================================
f u n c t i o n d s q r = d c y l 2 c y l (...
w,r 0,m,r d a t,z d a t,R 0,M,R d a t,Z d a t )
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
% d s q r = d c y l 2 c y l ( w,r 0,m,r d a t,z d a t,R 0,M,R d a t,Z d a t )
% This f u n c t i o n computes t h e s quar e of t h e
% d i s t a n c e between g e n e r i c p o i n t s on t h e
% s u r f a c e s of two c i r c u l a r c y l i n d e r s i n t h r e e
% di mensions.
%
% U s e r m f u n c t i o n s c a l l e d: c y l p o i n t
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
g l o b a l f c o u n t fc ount=fcount +1;
r = c y l p o i n t ( w ( 1 ),w ( 2 ),r 0,m,r d a t,z d a t ); R = c y l p o i n t ( w ( 3 ),w ( 4 ),R 0,M,R d a t,Z d a t ); dsqr=norm(r-R)~2;
%===========================================
f u n c t i o n c y l f i g s % c y l f i g s
%~~~~~~~
% This f u n c t i o n p l o t s t h e geome t r i e s % p e r t a i n i n g t o f o u r d a t a c a s es used % t o t e s t c l o s e s t p r o x i m i t y problems % i n v o l v i n g two c i r c u l a r c y l i n d e r s %
% User m f u n c t i o n s c a l l e d: p l o t 2 c y l s
w=rads; p=1:2; q=3:4; s=5:6; t = 7:8;
rad=1; len=3; r 0 = [ 4,0,0 ]; v = [ 0,0,1 ];
Rad=1; Len=3; R 0 = [ 0,4,0 ]; V = [ 0,0,1 ]; d=.4; s u b p l o t ( 2,2,1 )
[ x,y,z,X,Y,Z ] = p l o t 2 c y l s ( r a d,l e n,r 0,v,R a d,L e n,...
R0,V,d,'CASE 1'); hol d on p l o t 3 ( w ( p,1 ),w ( p,2 ),w ( p,3 ),'l i n e w i d t h',2') h o l d o f f
rad=1; len=3; r 0 = [ 4,0,0 ]; v = [ 3,0,4 ];
Rad=1; Len=3; R 0 = [ 0,4,0 ]; V = [ 0,3,4 ]; d=.4; s u b p l o t ( 2,2,2 );
[ x,y,z,X,Y,Z ] = p l o t 2 c y l s ( r a d,l e n,r 0,v,R a d,L e n,...
R0,V,d,'CASE 2'); hol d on p l o t 3 ( w ( q,1 ),w ( q,2 ),w ( q,3 ),'l i n e w i d t h',2') h o l d o f f
rad=1; len=5; r 0 = [ 4,0,0 ]; v = [ - 4,0,3 ];
Rad=1; Len=5; R 0 = [ 0,4,0 ]; V = [ 0,0,1 ]; d=.4; s u b p l o t ( 2,2,3 )
[ x,y,z,X,Y,Z ] = p l o t 2 c y l s ( r a d,l e n,r 0,v,R a d,L e n,...
R0,V,d,'CASE 3'); hol d on p l o t 3 ( w ( s,1 ),w ( s,2 ),w ( s,3 ),'l i n e w i d t h',2') h o l d o f f
rad=1; l e n = 4 * s q r t ( 2 ); r 0 = [ 4,0,0 ]; v = [ - 1,1,0 ];
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
Rad=1; Len=3; R 0 = [ 0,0,- 2 ]; V = [ 0,0,- 1 ]; d=.4; s u b p l o t ( 2,2,4 );
[ x,y,z,X,Y,Z ] = p l o t 2 c y l s ( r a d,l e n,r 0,v,R a d,L e n,...
R0,V,d,'CASE 4'); hol d on p l o t 3 ( w ( t,1 ),w ( t,2 ),w ( t,3 ),'l i n e w i d t h',2') h o l d o f f, s u b p l o t % p r i n t -deps c y l c l o s e
%===========================================
f u n c t i o n [ x,y,z,X,Y,Z ] = p l o t 2 c y l s (. ..
r a d,l e n,r 0,v c,R a d,L e n,R 0,V c,d,t i t l ) % [ x,y,z,X,Y,Z ] = p l o t 2 c y l s ( r a d,l e n,r 0,v c,R a d,...
% L e n,R 0,V c,d,t i t l )
%....................................................................................................................
% This f u n c t i o n g e n e r a t e s p o i n t g r i d s on t h e % s u r f a c e s of two c i r c u l a r c y l i n d e r s and p l o t s % bot h c y l i n d e r s t o g e t h e r %
% User m f u n c t i o n s c a l l e d: c o r n r p t s surfmany % c y l p t s
i f nargin==0
titl='TWO CYLINDERS';
rad=1; len=3; r 0 = [ 4,0,0 ]; v c = [ 3,0,4 ];
Rad=1; Len=3; R 0 = [ 0,4,0 ]; V c = [ 0,3,4 ]; d=.2;
end
i f i s e m p t y ( t i t l ), t i t l =' '; end u=2*rad+len; v=2*pi*rad; n u = c e i l ( u/d ); n v = c e i l ( v/d ); u = c o r n r p t s ( [ 0,r a d,r a d + l e n,u ],n u )/u; v = l i n s p a c e ( 0,1,n v ); [ x,y,z ] = c y l p t s ( u,v,r a d,l e n,r 0,v c );
U=2*Rad+Len; V=2*pi*Rad;
Nu=c ei l ( U/d); Nv=cei l (V/d); U=cornrpt s([ 0,Rad,Rad+Len,U],Nu)/U; V = l i n s p a c e ( 0,1,N v ); [X,Y,Z]=cylpts(U,V,Rad,Len,R0,Vc); s u r f m a n y ( x,y,z,X,Y,Z ), t i t l e ( t i t l ) colormap([1 1 0 ] ), shg
%===========================================
f u n c t i o n [ x,y,z ] = c y l p t s (...
a x i a l,c i r c u m,r a d,l e n,r 0,v e c t a x ) % [ x,y,z ] = c y l p t s ( a x i a l,c i r c u m,r a d,l e n,r 0,v e c t a x )
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
%....................................................................................................................
% This f u n c t i o n computes a g r i d of p o i n t s on t h e % s u r f a c e of a c i r c u l a r c y l i n d e r %
% User m f u n c t i o n s c a l l e d: o r t b a s i s
U=2*rad+len; u = U * a x i a l (:); n = l e n g t h ( u ); v = 2 * p i * c i r c u m (:)'; m=l engt h(v); u d = [ 0,r a d,r a d + l e n,U ]; r = i n t e r p 1 ( u d,[ 0,r a d,r a d,0 ],u ); z = i n t e r p 1 ( u d,[ 0,0,l e n,l e n ],u ); x = r * c o s ( v ); y = r * s i n ( v ); z =r epmat ( z,1,m);
% w = b a s i s ( v e c t a x ) * [ x (:),y (:),z (:) ]'; w = o r t b a s i s ( v e c t a x ) * [ x (:),y (:),z (:) ]';
x = r 0 ( 1 ) + r e s h a p e ( w ( 1,:),n,m ); y = r 0 ( 2 ) + r e s h a p e ( w ( 2,:),n,m ); z = r 0 ( 3 ) + r e s h a p e ( w ( 3,:),n,m );
%===========================================
f u n c t i o n v= c o r n r p t s ( u,N )
% v=c o r n r p t s ( u,N )
% This f u n c t i o n g e n e r a t e s appr oxi ma t e l y N % p o i n t s between min(u) and max(u) i n c l u d i n g % a l l p o i n t s i n u p l u s a d d i t i o n a l p o i n t s evenly % spaced i n each s u c c e s s i v e i n t e r v a l.
% u - v e c t o r of p o i n t s
% N - approximate number of o u t p u t p o i n t s
% between m i n ( u (:) ) and m a x ( u (:) )
% v - v e c t o r of p o i n t s i n i n c r e a s i n g o r d e r
u = s o r t ( u (:) )'; n p = l e n g t h ( u ); d = u ( n p ) - u ( 1 ); v=u(1); f o r j =1:n p - 1
d ( = u ( ( u 1 ) - u ( ( ); n i = m a x ( 1,f i x ( N * d j/d ) ); v = [ v,[ u ( j ) + d j/n j * ( l:n j ) ] ]; end
%===========================================
f u n c t i o n m a t = o r t b a s i s ( v )
% m a t = o r t b a s i s ( v )
%...................................
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
% This f u n c t i o n g e n e r a t e s a r o t a t i o n m a t r i x % havi ng v (:)/n o r m ( v ) as t h e t h i r d column
v = v (:)/n o r m ( v ); m a t = [ n u l l ( v') ] v ]; i f de t ( m a t ) < 0, m a t (:] 1 ) = - m a t (:] 1 ); end
%==========================================
f u n c t i o n [ x m i n ] f m i n ] m,n t y p e ] = n e l m e d (...
F ] x 0 ] d x ] e p s x ] e p s f ] M ] i f p r,v a r a r g i n ) % [ xmi n]fmi n]m,ntype ]=nel med(...
% F ] x 0 ] d x ] e p s x ] e p s f ] M ] i f p r,v a r a r g i n )
This f u n c t i o n performs m u l t i d i m e n s i o n a l u n c o n s t r a i n e d f u n c t i o n m i n i m i z a t i o n u s i n g t h e d i r e c t s e a r c h proc edur e developed by J. A. Nelder and R. Mead. The method i s d e s c r i b e d i n v a r i o u s books such as:
'N o n l i n e a r O p t i m i z a t i o n', by M. Av r i e l
F - o b j e c t i v e f u n c t i o n of t h e form
F ( x ] p 1 ] p 2,...) where x i s v e c t o r i n n space and p 1,p 2,... a r e any a u x i l i a r y pa r a m e t e r s needed t o d e f i n e F
x0 - s t a r t i n g v e c t o r t o i n i t i a t e
t h e s e a r c h
dx - i n i t i a l polyhedron s i d e l e n g t h
epsx - convergence t o l e r a n c e on x
eps f - convergence t o l e r a n c e on
f u n c t i o n v a l u e s M - f u n c t i o n e v a l u a t i o n l i m i t t o
t e r m i n a t e s e a r c h i f p r - when t h i s par a me t e r e q u a l s one,
d i f f e r e n t s t a g e s i n t h e s e a r c h a r e p r i n t e d
v a r a r g i n - v a r i a b l e l e n g t h l i s t of p a r a met e r s which can be p a s s e d t o f u n c t i o n F xmin - c o o r d i n a t e s of t h e s m a l l e s t
f u n c t i o n v al u e fmin - s m a l l e s t f u n c t i o n v a l u e found
m - t o t a l number of f u n c t i o n
e v a l u a t i o n s made nt ype - a v e c t o r c o n t a i n i n g
[ n i n i t ] n r e f l ] n e x p n,n c o n t r ] n s h r n k ]
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
% which t e l l s t h e number of r e f l e c t -
% i o n s, exp a n s i o n s, c o n t r a c t i o n s,a n d
% s h r i n k a g e s performed
%
% User m f u n c t i o n s c a l l e d: o b j e c t i v e f u n c t i o n % named i n t h e argument l i s t
i f i s e m p t y ( i f p r ), i f p r = 0; end i f isempty(M), M=500; end; i f i s e m p t y ( e p s f ), epsf =1e-5; end i f i s e m p t y ( e p s x ), epsx=1e-5; end
% I n i t i a l i z e t h e simplex a r r a y x 0 = x 0 (:); n = l e n g t h ( x 0 ); N=n+1; f = z e r o s ( 1 ] N ); x = r e p m a t ( x 0 ] 1 ] N ) + [ z e r o s ( n ] 1 ) ] d x * e y e ( n ] n ) ]; f o r k=1:N
f ( k ) = f e v a l ( F ] X (:] k ) ] V a r a r g i n {:} );
end
n i ni t = N; n r e f l = 0; nexpn=0; ncont r=0; nshrnk=0; m=N;
Erx=realmax; Erf=realmax; a l pha= 1.0; % R e f l e c t i o n c o e f f i c i e n t b et a= 0.5; % C o n t r a c t i o n c o e f f i c i e n t gamma=2.0; % Expansion c o e f f i c i e n t
% Top of t h e m i n i m i z a t i o n loop
whi l e Erx>epsx | Erf >epsf
[ f,k ] = s o r t ( f ); x = x (:,k );
% E x i t i f maximum a l l o w a b l e number of
% f u n c t i o n v a l u e s i s exceeded
i f m>M, x mi n=x(:] 1); f m i n = f ( 1 ); r e t u r n; end
% Generate t h e r e f l e c t e d p o i n t and % f u n c t i o n v al u e
c = s u m ( x (:] 1:n ) ] 2 )/n; x r = c + a l p h a * ( c - x (:,N ) ); f r = f e v a l ( F ] X r ] V a r a r g i n {:} ); m=m+1; n r e f l = n r e f l + 1;
i f i f p r = = 1, f p r i n t f (' :RFL \n'); end
i f f r < f ( 1 )
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
% Expand and t a k e b e s t from expansion
% or r e f l e c t i o n
xe=c+gamma*(xr-c);
f e = f e v a l ( F ] X e ] V a r a r g i n {:} );
m=m+1; nexpn=nexpn+1;
i f i f p r == 1, f p r i n t f (' :EXP \n'); end
i f f r < f e
% The r e f l e c t e d p o i n t was b e s t f ( N ) = f r; x (:,N ) = x r; e l s e
% The expanded p o i n t was b e s t f ( N ) = f e; x (:,N ) = x e; end
e l s e i f f r < = f ( n ) % In t h e middle zone f ( N ) = f r; x (:,N ) = x r;
e l s e
% R e f l e c t e d p o i n t exceeds t h e second % h i g h e s t v a l u e so e i t h e r use c o n t r a c t i o n % or s h r i n k a g e i f fr <f ( N)
xx=xr; f f = f r; e l s e
x x = x (:,N ); f f = f ( N ); end
xc=c +bet a*( xx- c); f c = f e v a l ( F ] X C ] V a r a r g i n {:} ); m=m+1; ncont r=ncont r+1;
i f fc <=ff
% Accept t h e c o n t r a c t e d va l u e x (:,N ) = x c; f ( N) = f c;
i f i f p r = = 1, f p r i n t f (' :CNT \n'); end e l s e
% Shri nk t h e simplex toward % t h e b e s t p o i n t x = ( x + r e p m a t ( x (:] 1 ) ] 1 ] N ) )/2; f o r j=2:N
f ( j ) = f e v a l ( F ] X (:] j ) ] V a r a r g i n {:} );
end
m=m+n; nshrnk=nshrnk+n;
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
i f i f p r = = 1, f p r i n t f (' :SHR \n'); end end end
% E v a l u a t e p a r amet er s t o check convergence favg=sum(f)/N; E r f = s q r t ( s u m ( ( f - f a v g ).~ 2 )/n ); xcent=sum( x,2)/N; x d i f = x - r e p m a t ( x c e n t,1,N ); E r x = m a x ( s q r t ( s u m ( x d i f.~ 2 ) ) );
end % Bottom of t h e o p t i m i z a t i o n loop
x m i n = x (:,1 ); f mi n =f ( 1 );
n t y p e = [ n i n i t,n r e f l,n e x p n,n c o n t r,n s h r n k ];
%=================================================
f u n c t i o n [ d,r,R ] = s u r f 2 s u r f ( x,y,z,X,Y,Z,n )
% [ d,r,R ] = s u r f 2 s u r f ( x,y,z,X,Y,Z,n )
%...............................................................................
% This f u n c t i o n de t e r mi ne s t h e c l o s e s t p o i n t s on two % s u r f a c e s and t h e d i s t a n c e between t h e s e p o i n t s. I t % i s s i m i l a r t o f u n c t i o n s r f 2 s r f except t h a t l a r g e % a r r a y s can be p r o c e s s e d.
%
% x,y,z - a r r a y s of p o i n t s on t h e f i r s t s u r f a c e % X,Y,Z - a r r a y s of p o i n t s on t h e second s u r f a c e % d - t h e minimum d i s t a n c e between t h e s u r f a c e s
% r,R - v e c t o r s c o n t a i n i n g t h e c o o r d i n a t e s of t h e % n e a r e s t p o i n t s on t h e f i r s t and t h e
% second s u r f a c e
% n - l e n g t h of s u b v e c t o r s used t o p r o c e s s t h e
% d a t a a r r a y s. Sending v e c t o r s of l e n g t h
% n t o s r f 2 s r f and t a k i n g t h e b e s t of t h e
% s u b r e s u l t s al l ows p r o c e s s i n g of l a r g e
% a r r a y s of d a t a p o i n t s
%
% User m f u n c t i o n s used: s r f 2 s r f i f nar gi n< 7, n=500; end
N = p r o d ( s i z e ( x ) ); M=prod(size(X)); d=realmax; kN=max( 1,f loor (N/n)); kM=max(1,floor(M/n)); f o r i=1:kN
i 1 = 1 + ( i - 1 ) * n; i2=min(i1+n,N); i 1 2 = i 1:i 2; x i = x ( i 1 2 ); y i = y ( i 1 2 ); z i = z ( i 1 2 ); f o r j=1:kM
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
j 1 = 1 + ( j - 1 ) * n; j2=min(j1+n,M); j 1 2 = j 1:j 2; [ d i j,r i j,R i j ] = s r f 2 s r f (...
x i,y i,z i,X ( j 1 2 ),Y ( j 1 2 ),Z ( j 1 2 ) ); i f d i j < d, d = d i j; r = r i j; R=Rij; end end end
%================================================
f u n c t i o n [ d,r,R ] = s r f 2 s r f ( x,y,z,X,Y,Z )
% [ d,r,R ] = s r f 2 s r f ( x,y,z,X,Y,Z )
%.....................................................................
% This f u n c t i o n de t e r mi ne s t h e c l o s e s t p o i n t s on two % s u r f a c e s and t h e d i s t a n c e between t h e s e p o i n t s.
% x,y,z - a r r a y s of p o i n t s on t h e f i r s t s u r f a c e % X,Y,Z - a r r a y s of p o i n t s on t h e second s u r f a c e % d - t h e minimum d i s t a n c e between t h e s u r f a c e s
% r,R - v e c t o r s c o n t a i n i n g t h e c o o r d i n a t e s of t h e % n e a r e s t p o i n t s on t h e f i r s t and t h e
% second s u r f a c e
x = x (:); y = y (:); z = z (:); n = l e n g t h ( x ); v = o n e s ( n,1 ); X=X(:)’; Y=Y(:)’; Z = Z (:) ’; N=length(X); h=ones(1,N); d 2 = ( x (:,h ) - X ( v,:) ).~ 2; d 2 = d 2 + ( y (:,h ) - Y ( v,:) ).~ 2; d 2 = d 2 + ( z (:,h ) - Z ( v,:) ).~ 2;
[ u,i ] = m i n ( d 2 ); [ d,j ] = m i n ( u ); i = i ( j ); d = s q r t ( d );
r = [ x ( i );y ( i );z ( i ) ]; R = [ X ( j );Y ( j );Z ( j ) ];
%=================================================
f u n c t i o n R=rads % R=rads
% R adi i f o r t h e problem s o l u t i o n s
R=[.
0.7045
3.2903
0.8263
3.2932
0.7074
0.8295
0.7783
3.4977
0.3767
3.4994
0.7800
0.3755
0.0026
3.0000
2.9934
0.0028
1.0000
3.0001
0.7034
0.7107
-2.0000
1.5139
1.5320
-0.7382]
%
554: % s u r f m a n y ( x 1,y 1,z 1,x 2,y 2,z 2,x 3,y 3,z 3,... 5 5 5: % x n,y n,z n )
5 5 6: % See Appe ndi x B
553:
Appendix A
List of MATLAB Routines with Descriptions
Table A.1: Description of MATLAB Programs and Selected Functions
Routine
Chapter
Description
finance
1
Financial analysis program illustrating programming methods.
inputv
1
Function to read several data items on one line.
polyplot
2
Program comparing polynomial and spline Interpolation.
squarrun
2
Program illustrating conformal map­
ping of a square.
squarmap
2
Function for Schwarz-Christoffel map­
ping of a circular disk inside a square.
cubrange
2
Function to compute data range limits for 2D or 3D data.
pendulum
2
Program showing animated large oscil­
lations of a pendulum.
ammpen
2
Function showing pendulum anima­
tion.
smdplot
2
Program to animate forced motion of a spring-mass-damper system.
smdsolve
2
Function to solve a constant coefficient linear second order differential equa­
tion with a harmonic forcing function.
strngrun
2
Program animating wave motion in a string with given initial deflection.
strngwav
2
Function to compute deflections of a vibrating string.
animate
2
Function to show animation of a vibrat­
ing string.
continued on next page
Routine
Chapter
Description
splinerr
2
Program showing differential geome­
try properties of a space curve.
curvprpsp
2
Function using spline interpolation to compute differential properties of a space curve.
splined
2
Function to compute first or second derivatives of a cubic spline.
srfex
2
Program illustrating combined plotting of several surfaces.
frus
2
Function to compute points on a frus­
tum.
surfmany
2
Function to plot several functions to­
gether without distortion.
rgdbodmo
2
Program illustrating 3D rigid body ro­
tation and translation.
rotatran
2
Function to perform coordinate rota­
tion.
membran
3
Program illustrating static deflection of a membrane.
mbvprun
3
Program to solve a mixed boundary value problem for a circular disk.
makratsq
3
Program showing conformal mapping of a square using rational functions.
ratcof
3
Function to compute coefficients for
rational function interpolation.
raterp
3
Function to evaluate a rational func­
tion using coefficients from function raterp.
strdyneq
3
Program to solve the structural dy­
namics equation using eigenvalue - eigenvector methods.
fhrmck
3
Function to solve a linear second or­
der matrix differential equation having a harmonic forcing function.
recmemfr
3
Program illustrating use of functions null and eig to compute rectangular membrane frequencies.
continued on next page
Routine
Chapter
Description
multimer
3
Program comparing execution of in­
trinsic MATLAB matrix multiplication and slow Fortran style using loops.
lintrp
4
Function for piecewise linear interpo­
lation allowing finite jump discontinu­
ities.
curvprop
4
Program to compute the length and area bounded by a curve defined by spline interpolation.
spcof
4
Function to compute spline interpo­
lation coefficients used by function spterp.
spterp
4
Function to interpolate, differentiate, and integrate a cubic spline having general end conditions.
powermat
4
Function used by functions spcof and spterp.
splineq
4
Function to interpolate, integrate, and differentiate using the intrinsic func­
tion spline.
splincof
4
Function that computes coefficients used by splineg to handle general end conditions.
matlbdat
4
Program that draws the word MAT­
LAB using a spline.
finitdif
4
Program to compute finite difference formulas.
findifco
4
Function to compute finite difference formulas for derivatives of arbitrary or­
der.
simpson
5
Function using Simpson’s rule to inte­
grate an exact function or one defined by spline interpolation.
gcquad
5
Function to perform composite Gauss integration of arbitrary order, and re­
turn the base points and weight factors.
quadtest
5
Program comparing the performance of gcquad and quadl for several test functions.
continued on next page
Routine
Chapter
Description
areaprog
5
Program to compute area, centroidal coordinates and inertial properties of general areas bounded by spline curves.
aprop
5
Function to compute geometrical prop­
erties of general areas.
volrevol
5
Program to compute geometrical prop­
erties of partial volumes of revolution bounded by spline curves.
volrev
5
Function to compute geometrical prop­
erties of partial volumes of revolution.
rotasurf
5
Function to plot a partial surface of rev­
olution.
ropesymu
5
Program using numerical and symbolic computation to evaluate geometrical properties of a rope shaped solid.
ropedraw
5
Function to draw a twisted rope shaped surface.
twistprop
5
Function using symbolic computation to obtain geometrical properties.
srfv
5
Function to compute geometrical prop­
erties of a solid specified by general surface coordinates.
polhdrun
5
Program to produce geometrical prop­
erties and a surface plot of an arbitrary
polyhedron.
polhedron
5
Function for geometrical properties of a polyhedron.
polyxy
5
Function for geometrical properties of a polygon.
sqrtquadtest
5
Program using quadl and gcquad to evaluate integrals having square root type singularities at the integration end points.
quadqsqrt
5
Function applying gcquad to integrals having square root type singularities.
quadlsqrt
5
Function applying quadl to integrals having square root type singularities.
continued on next page
Routine
Chapter
Description
triplint
5
Program applying Gauss quadrature to evaluate a triple integral with variable integration limits.
plotjrun
6
Program to compute and plot integer order Bessel functions using the FFT.
runimpv
6
Program using the FFT to analyze earthquake data.
fouapprox
6
Function for Fourier series approxima­
tion of a general function.
fouseris
6
Program to plot truncated Fourier se­
ries expansions of general functions.
fousum
6
Function to sum a Fourier series and in­
clude coefficient smoothing.
cablinea
7
Program showing modal superposition analysis of a swinging cable.
udfrevib
7
Function computing undamped re­
sponse of a second order matrix differ­
ential equation with general initial con­
ditions.
strdynrk
7
Function using ode45 to solve a second order matrix differential equation.
deislner
7
Program comparing implicit second and fourth order integrators which use fixed stepsize.
mckde2i
7
Function to solve a matrix ODE using a second order fixed stepsize integrator.
mckde4i
7
Function to solve a matrix ODE using
a fourth order fixed stepsize integrator.
rkdestab
8
Program to plot stability zones for Runge-Kutta integrators.
prun
8
Program illustrating ode45 response calculation of an inverted pendulum.
toprun
8
Program for dynamic response of a spinning top.
traject
8
Program for a projectile trajectory.
cablenl
8
Program illustrating animated nonlin­
ear dynamic response for a multi-link cable of rigid links.
continued on next page
Routine
Chapter
Description
plotmotn
8
Function to animate the dynamic re­
sponse of a cable.
sprchan
8
Program for animated nonlinear dy­
namics of an elastic cable shaken at both ends.
laplarec
9
Program using Fourier series to solve the Laplace equation in a rectangle having general boundary conditions.
recsens
9
Function to compute a harmonic func­
tion and gradient components in a rect­
angular region.
stringft
9
Program for Fourier series solution and animated response for a string with given initial displacement.
forcmove
9
Program for response of a string sub­
jected to a moving concentrated load.
membwave
9
Program animating the response of a rectangular or circular membrane sub­
jected to an oscillating concentrated force.
memrecwv
9
Function for dynamic response of a 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.
membanim
9
Function to show animated membrane response.
bemimpac
9
Program showing wave propagation in 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.
slabheat
9
Program for heat conduction in a slab having sinusoidally varying end tem­
perature.
continued on next page
Routine
Chapter
Description
heatcyln
9
Program analyzing transient heat con­
duction in a circular cylinder.
tempstdy
9
Function for the steady-state tempera­
ture in a circular cylinder with general boundary conditions.
foubesco
9
Function to compute coefficients in a Fourier-Bessel series.
besjtabl
9
Function giving a table of integer order Bessel function roots.
rector
9
Program to compute torsional stresses in a beam of rectangular cross section.
eigverr
10
Program comparing eigenvalues of a second order differential equation computed using finite difference meth­
ods and using collocation with spline interpolation.
prnstres
10
Function to compute principal stresses and principal directions for a symmet­
ric second order stress tensor.
trusvibs
10
Program to compute and show anima­
tion of the natural vibration modes of a general pin connected truss.
drawtruss
10
Function to draw the deflection modes of a truss.
eigsym
10
Function solving the constrained eigenvalue problem associated with an elastic structure fixed as selected points.
elmstf
10
Function to form mass and stiffness matrices of a pin connected truss.
colbuc
10
Program to compute buckling loads of a variable depth column with general end conditions.
cbfreq
10
Program comparing cantilever beam natural frequencies computed by ex­
act, finite difference, and finite element methods.
continued on next page
Routine
Chapter
Description
cbfrqnwm
10
Function to compute exact cantilever beam frequencies.
cbfrqfdm
10
Function to compute cantilever beam frequencies using finite difference methods.
cbfrqfem
10
Function to compute cantilever beam frequencies using the finite element method.
elipfreq
10
Program for natural frequencies and animation of the mode shapes of an el­
liptic membrane.
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 +
B X = X( XC + DX).
p l o t m o d e
1 0
F u n c t i o n t o p l o t t h e m o d e s h a p e s o f t h e m e m b r a n e.
v d b
11
P r o g r a m t o c o m p u t e s h e a r, m o m e n t, s l o p e, a n d d e f l e c t i o n i n a v a r i a b l e d e p t h m u l t i - s u p p o r t b e a m w i t h g e n e r a l e x t e r n a l l o a d i n g c o n d i t i o n s.
e x t l o a d
11
F u n c t i o n t o c o m p u t e l o a d a n d d e f o r ­
m a t i o n q u a n t i t i e s f o r d i s t r i b u t e d a n d c o n c e n t r a t e d l o a d i n g o n a b e a m.
s n g f
11
S i n g u l a r i t y f u n c t i o n u s e d t o d e s c r i b e b e a m l o a d s.
t r a p s u m
11
T r a p e z o i d a l r u l e f u n c t i o n u s e d t o i n t e ­
g r a t e b e a m f u n c t i o n s.
s q r t s u r f
1 2
F u n c t i o n u s e d t o i l l u s t r a t e b r a n c h c u t d i s c o n t i n u i t i e s f o r a n a n a l y t i c f u n c t i o n.
e l i p i n v r
1 2
F u n c t i o n t o i n v e r t t h e f u n c t i o n m a p ­
p i n g t h e e x t e r i o r o f a c i r c l e o n t o t h e e x ­
t e r i o r o f a n e l l i p s e.
e l i p d p l t
1 2
P r o g r a m s h o w i n g g r i d l i n e s f o r c o n f o r ­
m a l m a p p i n g o f a c i r c u l a r d i s k o n t o a n e l l i p t i c d i s k.
c ont i nue d on n e x t page
Routine
Chapter
Description
elipdisk
12
Function mapping an elliptic disk onto a circular disk.
gridview
12
Function to plot a curvilinear coordi­
nate grid.
linfrac
12
Function to perform linear fractional transformations.
crc2crc
12
Function analyzing mapping of circles and straight lines under a linear frac­
tional transformation.
ecentric
12
Function to determine a concentric an­
nulus which maps onto a given eccen­
tric annulus.
swcsqlO
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 ex­
terior of a square.
swcsqmap
12
Function using truncated series expan­
sions in relation to circle to square maps.
lapcrcl
12
Program solving the Laplace equation in