ebook img

Numerical Methods, Algorithms and Tools in C# PDF

592 Pages·2010·2.61 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Numerical Methods, Algorithms and Tools in C#

Numerical Methods, Algorithms Tools and in C# © 2010 by Taylor and Francis Group, LLC Numerical Methods, Algorithms Tools and in C# Waldemar Dos Passos Boca Raton London New York CRC Press is an imprint of the Taylor & Francis Group, an informa business © 2010 by Taylor and Francis Group, LLC All the source codes for the material contained in this book can be downloaded directly from the publisher’s website: http://www.crcpress.com/product/isbn/9780849374791 followed by selecting the option for “Down- loads & Updates.” CRC Press Taylor & Francis Group 6000 Broken Sound Parkway NW, Suite 300 Boca Raton, FL 33487-2742 © 2010 by Taylor and Francis Group, LLC CRC Press is an imprint of Taylor & Francis Group, an Informa business No claim to original U.S. Government works Printed in the United States of America on acid-free paper 10 9 8 7 6 5 4 3 2 1 International Standard Book Number: 978-0-8493-7479-1 (Hardback) This book contains information obtained from authentic and highly regarded sources. Reasonable efforts have been made to publish reliable data and information, but the author and publisher cannot assume responsibility for the validity of all materials or the consequences of their use. The authors and publishers have attempted to trace the copyright holders of all material reproduced in this publication and apologize to copyright holders if permission to publish in this form has not been obtained. If any copyright material has not been acknowledged please write and let us know so we may rectify in any future reprint. Except as permitted under U.S. Copyright Law, no part of this book may be reprinted, reproduced, transmit- ted, or utilized in any form by any electronic, mechanical, or other means, now known or hereafter invented, including photocopying, microfilming, and recording, or in any information storage or retrieval system, without written permission from the publishers. For permission to photocopy or use material electronically from this work, please access www.copyright. com (http://www.copyright.com/) or contact the Copyright Clearance Center, Inc. (CCC), 222 Rosewood Drive, Danvers, MA 01923, 978-750-8400. CCC is a not-for-profit organization that provides licenses and registration for a variety of users. For organizations that have been granted a photocopy license by the CCC, a separate system of payment has been arranged. Trademark Notice: Product or corporate names may be trademarks or registered trademarks, and are used only for identification and explanation without intent to infringe. Library of Congress Cataloging‑in‑Publication Data Dos Passos, Waldemar. Numerical methods, algorithms, and tools in C# / Waldemar Dos Passos. p. cm. Includes bibliographical references and index. ISBN 978-0-8493-7479-1 (hardcover : alk. paper) 1. Numerical analysis--Data processing. 2. Algorithms. 3. C# (Computer program language) I. Title. QA297.D684 2010 518.0285’5133--dc22 2009031461 Visit the Taylor & Francis Web site at http://www.taylorandfrancis.com and the CRC Press Web site at http://www.crcpress.com © 2010 by Taylor and Francis Group, LLC Preface Today,morethanatanyothertimeinthehistoryofmankind,computersareincreas- inglyandsuccessfullybeingexploitedtogainabetterunderstandingofourphysical worldandasaresult,alsodeepenourappreciationandreverenceforGod’sCreation. Consequently,ascomputersevolve,somustthemeanstocontrolthemthroughad- vancementsnotjustinhardwarebutalsoinsoftware. Inordertosatisfythisdemandforbettersoftware,Microsoftreleasedanentirely new programminglanguagecalled C# that incorporatesthe best features of all the otherexistingpopularprogramminglanguagessuchasJava,C/C++,andVisualBa- sic. Inspiteofconsiderableresistancebysomepeoplewhopersistonclingingonto thepastandcontinuetoprogramcomputersthehardway,C#hasnowfirmlyestab- lished itself worldwideas arguablythe preferredlanguageforsoftware application development. Althoughmanyexcellentbooksonthetopicofgeneralprogramming in C# have been written, there is still a considerablelack of publishedmaterial on thetopicofnumericalmethodsinC#. Accordingly,NumericalMethods,AlgorithmsandToolsinC# isabookcontain- ingalargecollectionofveryusefulready-to-usemathematicalroutines,algorithms andothercomputationaltoolsaimedatprogrammers,mathematicians,statisticians, scientists, engineers and anyone else interested in developing mathematically ori- entedcomputerapplicationsin the relativelynew andeasy-to-learnobject-oriented C# programminglanguage from Microsoft. With a heavy emphasis on using well established numerical methods, object-oriented techniques and the latest state-of- the-artMicrosoft.NETprogrammingenvironment,thisbookprovidesreaderswith workingC#codeincludingpracticalexamplesthatcanbeeasilycustomizedandim- plementedto solvecomplexengineeringandscientific problemstypicallyfoundin real-worldapplications. ForthebenefitofthosereaderswhoarenotyetfamiliarwithC#,Chapter1pro- videsabriefoutlineofthe.NETFramework,theC#programminglanguageandthe basicconceptsofObjectOrientedProgramming(OOP).Specialattentionisgivento topicsthatillustratehowtobestutilizetheseandothertoolstodevelopaccurateand robustnumericalmethodsinC#. Chapter2isentirelyfocusedonthe.NETFrameworkMathClassLibrarywhich already comes built into Microsoft’s Visual Studio software development system. Additional material is introduced where appropriate in order to supplement, com- pleteorotherwiseenhancethefeaturesalreadyavailablewiththislibrary. Chapter3introducesdatastructuresalongwiththeirassociatedfunctionsthatare particularlyusefulforprogrammingandworkingwithvectorsandmatrices. These iii © 2010 by Taylor and Francis Group, LLC iv NumericalMethods,AlgorithmsandToolsinC# routinesareoftenusedinmoreadvancedapplicationsinlaterchapters. Chapter 4 is entirely dedicated to the topic of complex numbers. Since timing issuescansometimesposeasubstantialproblemwhendoingnumericalcalculations, complexnumberfunctionsare presentedusingboth elegantstate-of-the-artobject- oriented methodswhich, althoughslick, can at times carry some overheadand the old fashioned but proven methods which at times have been found to actually run fasteronsomecomputers. Inaddition,importantoverflowandunderflowissuesare alsodiscussedandalternativesolutionstoavoidthoseproblemsareproposed. Chapter 5 is devoted solely to sorting and searching algorithms. Computersare often required to perform various types of data sorting for which many different algorithms exist. Consequently, choosing the most efficient sorting algorithm is a very important decision that developers frequently have to make. In this chapter, readersareprovidedwithbothawideselectionofsortingandsearchingalgorithms fromwhichtochoosealongwithabriefexplanationofhoweachalgorithmworks. Chapter6 iscenteredonthe topicof bitmanipulationwhichis typicallyusedin avarietyofprogrammingapplicationsranginganywherefromcomputerinterfacing toimageprocessing. Chapter 7 is focusedon interpolationmethods. Equationsthat cannotbe solved analytically often need to be solved using some kind of interpolation scheme, and thischapterhasplentyofpracticalexamplestoillustratehowonemighthandlethis kindofproblem. Chapter 8 centers on the numerical manipulation of linear algebraic equations. Thisisactuallyahugetopicbyitself andquiteworthyofitsownbook. Neverthe- less, asubstantialamountofusefulinformationcanbereadilyobtainedfromjusta handfulofthesepowerfultools. Chapter9isfocusedonnumericalmethodsforcalculatingapproximatesolutions to nonlinearequationswhich often appearnaturally in variousbranchesof science andengineering. Chapter10isdevotedexclusivelytothetopicofrandomnumbers. AlthoughC# comeswithitsowninternalrandomnumbergeneratorfunction,itisnotregardedto be sufficientlyrobustforuse inadvancedsecuredapplicationsorin computersim- ulationsthatrequirethousandsandsometimesevenmillionsofrandomnumbersin order to producereliable and accurate results. Alternate ways to obtainboth com- puter generated pseudo-randomnumbers and real random numbers obtained from naturallyoccurringphysicalphenomenaarealsodiscussed. Inaddition,routinesare also provided for generating random numbers that follow a particular probability distributionfunction. Chapter11describesvariousmethodsforapproximatingnumericaldifferentiation offunctions.Thisisaverytrickyandcontroversialtopicwhoseapproximationscan givefairlygoodtoatrociouslybadresults. Nevertheless,numericalmethodsdoexist forcalculatingthesetypesoffunctions.Thetrickisreallyinlearningtorecognizethe differencebetweengoodandbadresultsandinchoosingthebestavailablemethod foruseinaparticularsituation. Chapter12centersondevelopingnumericalmethodsforapproximatingintegrals ofspecificfunctionsaswellasfromcollectionsofrawdatapoints.Othermoreexotic © 2010 by Taylor and Francis Group, LLC Preface v waysofcalculatingintegrals,suchasbyusingMonteCarlomethods,arealsobriefly discussed. Chapter13containsaconsiderablenumberofroutinesforuseinperformingsta- tisticalanalysisofdata. Chapter14isdevotedtodevelopingnumericalmethodsforapproximatingspecial functionswhicharetypicallyfoundinvariousbranchesofmathematics,physicsand engineering. Chapter 15 is focused on least squares and numericalcurve fitting methodsthat are frequently used in analyzing experimental data. A brief discussion of the χ2 goodness-of-fittestisalsoincluded. Chapter16centersondevelopingroutinestofindnumericalsolutionstoordinary differential equations. Although this is really a huge topic, there are some basic numericalmethodswhich can be used successfully to solve a lot of these types of equationsinmanyreal-worldapplications. Chapter 17 introduces some numerical methods for solving partial differential equations. Although this is also a huge topic by itself and quite deserving of its own book, there are some standardtypesof partialdifferentialequationsthat arise naturallyinmanyareasofscienceandengineering,andwhosesolutionscanbeap- proximatedbywellestablishednumericalmethods. Chapter 18 focuses on optimization methods which are primarily aimed at the minimizationor maximizationof functionsand thus have manypracticalscientific andengineeringapplications.Sincethisisstillaveryactiveareaofongoingresearch, the examples presented here are more narrowly focused on just a few established topicswiththeexplicitpurposeofillustratinghowsuchmethodsmaybeindividually customizedandthenappliedtowardssolvingmoreadvancedproblems. Lastly,Iwouldliketopointoutthatmostofthenumericalmethodsdescribedin thisbookhaveactuallybeenaroundinoneformoranotherforyears,andsometimes even for centuries, and it is only their computer implementation in C# that makes this bookuniquelydifferentfromsome other bookon the topic of numericalanal- ysis. Accordingly,Ihavemadeeveryefforttotrackdownandgivepropercreditto originalsources wheneverpossible as the size of this book’sreference section can easily attest. Inaddition,I havealso madeeveryeffortto providemyreaderswith accurate,reliableinformationtohelpthemintheireffortstosuccessfullycomplete theirprogrammingprojects.Unfortunately,unwantedmistakesincludingtypograph- icalerrorsmayinadvertentlycreepupsomewhereinthisbook. Asaresult,Iwould greatlyappreciateifmyreaderswouldbesokindastobringtomyattentionifsuch errorsareeverfoundsothatImaypromptlyhavetheproblemcorrectedforanyfu- tureeditionsofthisbook. Also,aswithjustabouteverythingwedoinlife,thereis alwaysroomforimprovement. Accordingly,Iwouldalsoverymuchwelcomeany constructivecriticismthatmyreadersmayhaveregardingthisbooksothatIcanper- hapsmakeappropriatechanges.Finally,thereisanoldsayingthatstates,“anauthor neverfinishesabook,butmerelyabandonsit.” Ihavecertainlycometoappreciate thatobservationafterworkingonthisprojectforsolongandmakingcountlessrevi- sions. Nevertheless,thishascertainlybeenaveryenjoyableprojectwherejustabout everyword was carefullychosen and everytopic was meticulouslyresearchedand © 2010 by Taylor and Francis Group, LLC vi NumericalMethods,AlgorithmsandToolsinC# documented. Therefore,ifitisindeedtruethatIhavewillinglychosentoabandon writingthisbook,itisonlywiththemodesthopethatitmaybeusefultomyreaders inspiteofanypossibleshortcomings. WaldemarDosPassos,Ph.D. Concord,California e-mail:[email protected] website: www.waldemardospassos.com Acknowledgements It givesme greatpleasure to thank the manypeople who made this bookpossible. First,Iwouldverymuchliketothankmypublisher,NoraKonopka,fornotonlyac- ceptingthisbookforpublicationbutalsoforherexceptionalpatienceasIunderwent aseriesofunforeseentumultuouseventsinmylifeduringthecourseofwritingthis book which unfortunatelyled to some regrettabledelaysin its originalpublication targetdate. Iwouldalsoliketoparticularlythankbothmyprojectdirector,Theresa Delforn,andmyeditor,AmyRodriguez,fortheirexcellentexpertguidanceinvari- ousaspectsofthisproject. IwouldalsoliketothankDawnSniderforherexcellent artistic skills in designingthe coverfor this book. Many thanksto Ashley Gasque forguidingmethroughthenecessarybureaucraticpaperworkandtoShashiKumar for some expert LATEX tips he gave me. I would also like to thank all those other wonderfulpeopleatTaylor&Franciswhohaveworkedtirelesslybehindthescenes to make this project a success but whose exact names I may likely never come to know. IamalsoverygratefulforthesupportIreceivedfromtheH.E.MartinFoundation undergrant13011938.Withouttheirmostkindandextraordinarygenerousfinancial assistance,thewritingofthisbookwouldnothavebeenpossible. I am especially grateful to my third grade teacher, Miss Daly, for all her help, patience,kindness,andenthusiasmwhichultimatelysparkedmyinterestinmathe- maticsandeventually,physics. Lookingbackoveralltheseyearsthathaveelapsed since Iwasa studentinherclass, I cannowsay unequivocallythatMissDaly was byfartheverybestandmostcaringteacher,professor,orinstructorIeverhad. Lastly, I would also like to express my deepest and most heartfeltthanks to my parents,HeleniceandWaldemarDosPassos(Sr.) © 2010 by Taylor and Francis Group, LLC Thisbookisdedicatedwithallmyloveandcaretomyparents, HeleniceandWaldemarDosPassos(Sr.) foralltheirhardwork,genuinelove,andselflesssacrifices madeonmybehalfthroughoutmyentirelife. “Inthislifewecannotdogreatthings;onlysmallthingswithgreatlove.” MotherTeresa AdMajorem Dei Gloriam © 2010 by Taylor and Francis Group, LLC TThhiiss ppaaggee iinntteennttiioonnaallllyy lleefftt bbllaannkk

Description:
Comprehensive Coverage of the New, Easy-to-Learn C# Although C, C++, Java, and Fortran are well-established programming languages, the relatively new C# is much easier to use for solving complex scientific and engineering problems. Numerical Methods, Algorithms and Tools in C# presents a broad colle
See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.