William C. Haneberg Computational Geosciences with Mathematica William C. Haneberg Computational Geosciences with Mathematica With 297 Figures and a CD-ROM 123 Dr. William C. Haneberg Haneberg Geoscience 10208 39th Avenue SW Seattle WA 98146 USA E-mail:[email protected] Additional material to this book can be doenloaded from http://extra.springer.com. Library of Congress Control Number: 2004106660 ISBN 978-3-642-62157-4 ISBN 978-3-642-18554-0 (eBook) DOI 10.1007/978-3-642-18554-0 This work is subject to copyright.AII rights are reserved,whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reu se of illustrations, recitations, broadcasting, reproduction on microfilm or in any other way, an d storage in data banks. Duplication of this publication or parts thereof is permitted only under the provisions of the German Copyright Law of September 9, 1965, in its current version, and permission for use must always be obtained from Springer.Violations are liable to prosecution under the German Copyright Law. sp ri ngeronl i ne.com © Springer-Verlag Berlin Heidelberg 2004 Originally published by Springer-Verlag Berlin Heidelberg New York in 2004 Softcover reprint of the hardcover 1st edition 2004 The use of general descriptive na mes, registered names, tradema rks, etc. in this publication does not imply, even in the absence of a specific statement, that such names are exempt from the relevant protective laws and regulations and therefore free for general use. Cover design: E. Kirchner Production: A. Oelschlăger Typesetting: F. Herweg, Germany Printed on acid-free paper 32/3141/AO - 543210 Preface Mathematica(cid:2)R is a comprehensive mathematics package that can be used to per- form numerical calculations, manipulate symbolic expressions, develop compli- cated computer programs, and create sophisticated scientific graphics. My objec- tiveinwritingComputationalGeoscienceswithMathematicawastoshowhowthe programcanbeappliedtosolveawiderangeofproblemsofinteresttogeologists, geomorphologists,hydrologists,geophysicists,and othergeoscientists. Assuch, it is partly a textbook on quantitative geoscience and partly a manual showing how Mathematicacan beused to solvesomeproblemsof interestto geoscientists. Itis written at a level appropriate for graduate students embarking on quantitative re- searchprojects,professorswhoareinterestedinlearningaboutnewapproachesto quantitativeproblemsolving,andpracticinggeoscientistswithaninterestinMathe- matica.Whilesomeofthematerialismoreadvancedthanthattaughtintypicalun- dergraduategeologyprogramsintheUnitedStates,muchofitwillbeaccessibleto motivatedjuniorandseniorstudents. Ithaslongpuzzledmethat,whileadvancedcomputationaltoolssuchasMathe- maticahavebeenavailablefor15yearsormore,manygeoscientists(geologistsin particular) seem to be stuck in a spreadsheet rut. While spreadsheets manipulate rowsandcolumnsof numbersadequately,they arenotwellsuited formuchmore thansimplearithmetic.Still,theirpopularitypersistsand,inmyopinion,continues to make life more difficult for students or professionals trying to solve quantita- tivegeoscientificproblems.IbeganusingMathematicain1989andithasbecome an indispensablecomputationalandgraphicstoolin my researchandprofessional practice.GerardMiddletonseemstoshareasimilarviewofspreadsheetstohisbook DataAnalysisin the EarthSciencesUsingMatlab,andI am gladtosee thatIam not alone in that regard. Inexpensivestudent versions make Mathematica particu- larlywellsuitedforstudentsincomputermethodsorquantitativegeologyclasses. The subject matter and examples in Computational Geoscience with Mathe- matica were drawn largely from my experience as an applied researcher in engi- neeringgeologyandhydrogeology,universityinstructor,andconsultinggeologist. Ihavetriedtoincludeabroadrangeoftopics,buttherearemanygeoscientificand mathematicaltopics that are not covered.Fractals, wavelets, and geostatistics, for example,arealltopicsthatcanbe fruitfullyaddressed Mathematica,buttheseare topicsthateitherfallwelloutsidemyrangeofexperienceorthespaceavailablein VI Preface thisbook.Ihopethat,ratherthansparkingcomplaints,theiromissionwillmotivate specialistsinthosefieldstofillthevoid. MathematicaispublishedbyWolframResearch,Inc.,andiscurrently(summer 2003)inversion5.0.Formoreinformation,contactthecompanyat: WolframResearch,Inc. 100TradeCenterDrive Champaign,IL61820-7237USA (217)398-0700 [email protected] www.wolfram.com Mathematica is a registered trademark of Wolfram Research, Inc. Matlab is a registeredtrademarkofTheMathWorks,Inc. Thisbookwouldnothavebeenwrittenwithoutthesupportandencouragement of my wife Lisa. Others who deserve a measure of credit (but none of the blame foranymistakes)includeArvidJohnsonandPaulPotterwho,respectively,taught mehowtoformulategeologicalproblemsintermsofmechanicsandstatistics.John HawleyandthelateFrankKottlowskihiredmeandprovidedafertileenvironment forprofessionalgrowthattheNewMexicoBureauofMinesandMineralResources, adivisionofNewMexicoTech.ThelateAllanGutjahr,alsoatNewMexicoTech, wasafountainofstatisticalwisdomduringourcarpoolingyears.MikeWhitworth, Marshall Reiter, Dave Love, Laurel Goodwin,Peter Mozley, and many other col- leagues introduced me to a fascinating array of technical topics during my time inNewMexico.Finally,WolframResearchgenerouslyprovidedcopiesof Mathe- maticaandallowedmetouseapre-releaseversionofMathematica5.0duringthe writingofthisbook. WilliamC.Haneberg PortOrchard,Washington August2003 About theAuthor William C. Haneberg is an engineering geologist, hydrogeologist, and accredited Mathematica consultant living and working in the Seattle area. Before moving to the Pacific Northwest to establish a consulting practice in 1999, he served as Se- nior Engineering Geologist and Assistant Director of the New Mexico Bureau of Mines and Mineral Resources in Socorro and Albuquerque,New Mexico. He has alsotaughtundergraduateandgraduateclassesingeology,hydrology,geophysics, andgeologicalengineeringatNewMexicoTechandPortlandStateUniversity.Dr. Haneberg is an author or co-author of more than 25 papers and co-editor of two Preface VII multi-authormonographs(ClayandShaleSlopeInstability,publishedbytheGeo- logicalSocietyofAmerica,andFaultsandFluidFlowintheShallowSubsurface, publishedbytheAmericanGeophysicalUnion).HeearnedaPh.D.ingeologyfrom the University of Cincinnati, where his dissertation research concerned precipita- tion induced pore pressure increases in potentially unstable slopes. For additional information,pleasevisitwww.haneberg.com. Contents 1 IntroductiontoMathematica .................................... 1 1.1 WhatisMathematica? ...................................... 1 1.2 GettingHelp............................................... 2 1.3 InstallingandRunningMathematica........................... 2 1.4 HowtheBookisOrganized.................................. 3 1.5 ABriefTourofMathematica ................................ 4 1.5.1 SymbolicandNumericalOperations .................... 4 1.5.2 VectorandMatrixOperations.......................... 8 1.5.3 2-Dand3-DGraphing................................ 10 1.5.4 User-DefinedFunctions............................... 20 1.5.5 DataImportandExport............................... 21 1.5.6 MathematicaPackages ............................... 22 1.6 ReferencesandRecommendedReading........................ 23 2 SpecialPlotsforGeoscienceData ................................ 25 2.1 MathematicaPackagesYouWillNeed......................... 25 2.2 Overview ................................................. 25 2.3 StemPlots ................................................ 25 2.3.1 ImportingtheData ................................... 26 2.3.2 CreatingtheStemPlot................................ 26 2.4 RosePlots ................................................ 29 2.4.1 ImportingtheData ................................... 29 2.4.2 CreatingtheRosePlot................................ 30 2.5 TernaryPlots .............................................. 35 2.6 StereographicProjections.................................... 37 2.6.1 StereographicProjectionsofPlanes..................... 38 2.6.2 StereographicProjectionsofLines...................... 39 2.7 EqualAreaProjections...................................... 41 2.7.1 EqualAreaProjectionsofLines........................ 41 2.7.2 ContouringEqualAreaProjections ..................... 43 2.8 BoxandWhiskerPlots ...................................... 47 2.9 WellLogs................................................. 49 2.10 ReferencesandRecommendedReading........................ 55 X Contents 3 ManipulatingandSolvingEquations ............................. 57 3.1 MathematicaPackagesYouWillNeed......................... 57 3.2 BasicSymbolicManipulation ................................ 57 3.3 MatrixandVectorOperations ................................ 62 3.4 LinearEquationSolving..................................... 64 3.4.1 Solve,Roots,andReduce ............................. 64 3.4.2 NSolveandFindRoots................................ 66 3.4.3 GeoscienceExamples ................................ 68 3.5 OrdinaryDifferentialEquations .............................. 78 3.5.1 ManualManipulationandIntegration ................... 78 3.5.2 SolutionsUsingDSolveandNDSolve................... 80 3.5.3 GeoscienceExamples ................................ 81 3.6 PartialDifferentialEquations.................................103 3.6.1 HillslopeDiffusion...................................103 3.6.2 PeriodicHeatFlow...................................109 3.6.3 TopographicLoadingofEarth’sCrust...................113 3.6.4 TwoDimensionalSteadyGroundwaterFlow .............119 3.7 ReferencesandRecommendedReading........................129 4 RandomVariablesandUnivariateProbabilityDistributions ........131 4.1 MathematicaPackagesYouWillNeed.........................131 4.2 TheConceptofRandomVariables ............................131 4.3 SomeContinuousDistributions...............................133 4.3.1 NormalDistribution..................................133 4.3.2 Log-NormalDistribution..............................135 4.3.3 UniformDistribution .................................136 4.3.4 ExtremeValueDistribution............................137 4.3.5 BetaDistribution ....................................137 4.3.6 ParetoDistribution ...................................139 4.4 SomeDiscreteDistributions..................................140 4.4.1 PoissonDistribution..................................140 4.4.2 BinomialDistribution ................................142 4.5 RelatingDistributionstoData:MethodofMoments..............142 4.5.1 HowGoodAreThoseEstimates?.......................145 4.6 ParametricHypothesisTesting:tandFtests ....................147 4.6.1 ThetStatistic .......................................148 4.6.2 CriticaltValues .....................................149 4.6.3 ComparingTwoMeansorVariances ....................152 4.7 NonparametricHypothesisTesting:K-STests ..................154 4.8 GeneratingRandomNumbersfromProbabilityDistributions ......157 4.9 CareandFeedingoftheRandomNumberGenerator .............162 4.10 IllustratingtheCentralLimitTheorem.........................163 4.11 ThePitfallsofUndersampling................................166 4.12 ReferencesandRecommendedReading........................171 Contents XI 5 ProbabilisticSimulation ........................................173 5.1 MathematicaPackagesYouWillNeed.........................173 5.2 FloodFrequencyModeling ..................................173 5.2.1 PlottingtheData.....................................174 5.2.2 Log-NormalandExtremeValueDistributionFitting.......175 5.2.3 EmpiricalCumulativeDistribution......................177 5.2.4 ComparisonofResults................................178 5.2.5 ExceedanceProbabilityandRecurrenceIntervals .........179 5.3 Didn’tWeJustHavea100YearFlood? .......................181 5.4 MonteCarloSimulationofaWettingFront.....................183 5.5 MonteCarloAnalysisofInfiniteSlopeStability.................186 5.5.1 StaticFactorofSafety ................................186 5.5.2 EffectsofChangingIndependentVariableDistributions....189 5.5.3 ConditionalProbability:EarthquakesandSlopeStability...192 5.6 ApparentClastSizeDistributions:TheOutcropEffect ...........196 5.6.1 RandomlyRotatedEllipsoids ..........................202 5.7 ReferencesandRecommendedReading........................211 6 InterpolationandRegression ....................................213 6.1 MathematicaPackagesYouWillNeed.........................213 6.2 InterpolationorRegression:WhichisAppropriate?..............213 6.3 Interpolation...............................................214 6.3.1 FindingaSingleInterpolatingPolynomial ...............214 6.3.2 PiecewisePolynomialInterpolation.....................218 6.4 LinearRegression ..........................................221 6.4.1 DerivationofLinearLeastSquaresEquations ............222 6.4.2 Residuals...........................................226 6.4.3 Goodness-of-FitandtheCorrelationCoefficient ..........228 6.4.4 SignificanceofRegressionResults:ANOVA .............229 6.4.5 UsingFitandRegress ................................231 6.4.6 CanISolvefortheIndependentVariable? ...............233 6.4.7 ReducedMajorAxisRegression:TwoVariableswithError .240 6.5 NonlinearRegression .......................................244 6.5.1 NonlinearLeastSquares ..............................245 6.5.2 LogisticRegression ..................................247 6.6 ReferencesandRecommendedReading........................255 7 VisualizingandAnalyzingSurfaces ..............................257 7.1 MathematicaPackagesYouWillNeed.........................257 7.2 GriddedData ..............................................257 7.2.1 DigitalElevationModels..............................258 7.2.2 ImportingSDTSDEMFiles ...........................259 7.2.3 ContourPlots .......................................260 7.2.4 DensityPlots........................................263 7.2.5 ThreeDimensionalSurfacePlots .......................265 XII Contents 7.2.6 QuantitativeTerrainAnalysis ..........................268 7.2.7 CompositeGeomorphicMaps..........................281 7.3 IrregularlySpacedData .....................................284 7.3.1 ReciprocalDistanceGridding..........................290 7.3.2 ThinPlateSplineGridding ............................292 7.3.3 ANoteAboutKriging................................294 7.3.4 AddingWellLocationstoSurfacePlots .................294 7.3.5 ComparingResults...................................296 7.4 TrendSurfaceMapping .....................................298 7.5 ReferencesandRecommendedReading........................305 8 DigitalSignalandImageProcessing..............................307 8.1 MathematicaPackagesYouWillNeed.........................307 8.2 TheNatureofPeriodicWaveforms............................307 8.3 DiscreteFourierTranforms ..................................310 8.4 AutocovarianceandAutocorrelation...........................318 8.5 FiltersandConvolution......................................321 8.5.1 FirstDifferences.....................................322 8.5.2 MovingAveragesandSmoothing.......................325 8.5.3 High-PassFiltering...................................327 8.6 ImageProcessing...........................................328 8.6.1 ImportingDigitalImages..............................328 8.6.2 BasicMathematicalOperations ........................333 8.6.3 Thresholding........................................337 8.6.4 SmoothingorBlurring................................338 8.6.5 UnsharpMasking....................................340 8.6.6 EdgeDetection ......................................342 8.6.7 UsingListInterpolation ...............................345 8.7 RecommendedReading .....................................347 AppendixA MathematicaFunctionsintheComputationalGeoscience Package.......................................................349 A.1 Introduction ...............................................349 A.2 PlottingandCalculations ....................................349 A.3 ColorFunctions............................................351 AppendixB WorkingwithColor.....................................353 B.4 MathematicaPackagesYouWillNeed.........................353 B.5 SpecifyingColorsinMathematica ............................353 B.5.1 Hue,Saturation,andBrightness ........................353 B.5.2 Red,Green,andBlue(RGB) ..........................355 B.5.3 Cyan,Magenta,Yellow,andBlack(CMYK) .............358 B.5.4 OtherColorSystems .................................358 B.6 UsingColorinPlotsandGraphics ............................359 B.6.1 PlotandListPlot.....................................359