Cover image for Using R for numerical analysis in science and engineering
Title:
Using R for numerical analysis in science and engineering
Series:
Chapman & Hall/CRC the R series
Publication Information:
Boca Raton : CRC Press, Taylor & Francis Group, 2014
Physical Description:
xxii, 335 pages : illustrations ; 25 cm.
ISBN:
9781439884485
Abstract:
"This book shows how the free and open-source R environment can be used as a powerful and comprehensive platform for the kinds of numerical analysis that are traditionally employed by MATLAB®. With R code fully integrated, the book offers brief descriptions of basic approaches and emphasizes detailed worked examples. It covers functions in the base installation of R as well as those in contributed packages, which greatly enhance the numerical analysis capabilities of R"--provided by publisher

Available:*

Library
Item Barcode
Call Number
Material Type
Item Category 1
Status
Searching...
32080000000177 Q183.9 B56 2014 Open Access Book Book
Searching...
Searching...
30000010344115 Q183.9 B56 2014 Open Access Book Book
Searching...

On Order

Summary

Summary

Instead of presenting the standard theoretical treatments that underlie the various numerical methods used by scientists and engineers, Using R for Numerical Analysis in Science and Engineering shows how to use R and its add-on packages to obtain numerical solutions to the complex mathematical problems commonly faced by scientists and engineers. This practical guide to the capabilities of R demonstrates Monte Carlo, stochastic, deterministic, and other numerical methods through an abundance of worked examples and code, covering the solution of systems of linear algebraic equations and nonlinear equations as well as ordinary differential equations and partial differential equations. It not only shows how to use R's powerful graphic tools to construct the types of plots most useful in scientific and engineering work, but also:

Explains how to statistically analyze and fit data to linear and nonlinear models Explores numerical differentiation, integration, and optimization Describes how to find eigenvalues and eigenfunctions Discusses interpolation and curve fitting Considers the analysis of time series

Using R for Numerical Analysis in Science and Engineering provides a solid introduction to the most useful numerical methods for scientific and engineering data analysis using R.


Author Notes

Victor A. Bloomfield is currently emeritus professor at University of Minnesota, Minneapolis, USA. His research has encompassed more than four decades and a variety of topics, including enzyme kinetics, dynamic laser light scattering, bacteriophage assembly, DNA condensation, scanning tunneling microscopy, and single molecule stretching experiments on DNA. His theoretical work on biopolymer hydrodynamics and polyelectrolyte behavior has resulted in over 200 peer-reviewed journal publications. Using R for Numerical Analysis in Science and Engineering is an extension and broadening of his 2009 book, Computer Simulation and Data Analysis in Molecular Biology and Biophysics: An Introduction Using R , for general usage in science and engineering.


Table of Contents

List of Figuresp. xiii
Prefacep. ix
1 Introductionp. 1
1.1 Obtaining and installing Rp. 1
1.2 Learning Rp. 1
1.3 Learning numerical methodsp. 1
1.4 Finding helpp. 2
1.5 Augmenting R with packagesp. 3
1.6 Learning more about Rp. 5
1.6.1 Booksp. 5
1.6.2 Online resourcesp. 5
2 Calculatingp. 7
2.1 Basic operators and functionsp. 7
2.2 Complex numbersp. 8
2.3 Numerical display, round-off error, and roundingp. 9
2.4 Assigning variablesp. 11
2.4.1 Listing and removing variablesp. 12
2.5 Relational operatorsp. 12
2.6 Vectorsp. 13
2.6.1 Vector elements and indexesp. 13
2.6.2 Operations with vectorsp. 14
2.6.3 Generating sequencesp. 15
2.6.3.1 Regular sequencesp. 15
2.6.3.2 Repeating valuesp. 16
2.6.3.3 Sequences of random numbersp. 16
2.6.4 Logical vectorsp. 17
2.6.5 Speed of forming large vectorsp. 18
2.6.6 Vector dot product and crossproductp. 19
2.7 Matricesp. 21
2.7.1 Forming matricesp. 21
2.7.2 Operations on matricesp. 24
2.7.2.1 Arithmetic operations on matricesp. 24
2.7.2.2 Matrix multiplicationp. 25
2.7.2.3 Transpose and determinantp. 26
2.7.2.4 Matrix crossproductp. 26
2.7.2.5 Matrix exponentialp. 27
2.7.2.6 Matrix inverse and solvep. 27
2.7.2.7 Eigenvalues and eigenvectorsp. 29
2.7.2.8 Singular value decompositionp. 31
2.7.3 The Matrix packagep. 33
2.7.4 Additional matrix functions and packagesp. 34
2.8 Time and date calculationsp. 34
3 Graphingp. 37
3.1 Scatter plotsp. 37
3.2 Function plotsp. 39
3.3 Other common plotsp. 40
3.3.1 Bar chartsp. 40
3.3.2 Histogramsp. 42
3.3.3 Box-and-whisker plotsp. 43
3.4 Customizing plotsp. 44
3.4.1 Points and linesp. 44
3.4.2 Axes, ticks, and par ()p. 44
3.4.3 Overlaying plots with graphic elementsp. 46
3.5 Error barsp. 48
3.6 Superimposing vectors in a plotp. 49
3.7 Modifying axesp. 50
3.7.1 Logarithmic axesp. 51
3.7.2 Supplementary axesp. 51
3.7.3 Incomplete axis boxesp. 52
3.7.4 Broken axesp. 52
3.8 Adding text and math expressionsp. 54
3.8.1 Making math annotations with expression()p. 55
3.9 Placing several plots in a figurep. 56
3.10 Two- and three-dimensional plotsp. 58
3.11 The plotrix packagep. 60
3.11.1 radial.plot and polar.plotp. 60
3.11.2 Triangle plotp. 61
3.11.3 Error bars in plotrixp. 62
3.12 Animationp. 63
3.13 Additional plotting packagesp. 64
4 Programming and functionsp. 65
4.1 Conditional execution: if and ifelsep. 65
4.2 Loopsp. 66
4.2.1 for loopp. 66
4.2.2 Looping with while and repeatp. 68
4.3 User-defined functionsp. 69
4.4 Debuggingp. 72
4.5 Built-in mathematical functionsp. 73
4.5.1 Bessel functionsp. 73
4.5.2 Beta and gamma functionsp. 74
4.5.3 Binomial coefficientsp. 75
4.6 Special functions of mathematical physicsp. 75
4.6.1 The gsl packagep. 75
4.6.2 Special functions in other packagesp. 75
4.7 Polynomial functions in packagesp. 78
4.7.1 PolynomF packagep. 79
4.7.2 orthopolynom packagep. 83
4.8 Case studiesp. 86
4.8.1 Two-dimensional random walkp. 86
4.8.2 higenvalues of a polymer chainp. 87
5 Solving systems of algebraic equationsp. 91
5.1 Finding the zeros of a polynomialp. 91
5.2 Finding the zeros of a functionp. 92
5.2.1 Bisection methodp. 92
5.2.2 Newton's methodp. 93
5.2.3 uniroot and uniroot.allp. 94
5.3 Systems of linear equations: matrix solvep. 96
5.4 Matrix inversep. 97
5.5 Singular matrixp. 97
5.6 Overdetermined systems and generalized inversep. 98
5.7 Sparse matricesp. 99
5.7.1 Tridiagonal matrixp. 99
5.7.2 Banded matrixp. 101
5.7.3 Block matrixp. 102
5.8 Matrix decompositionp. 104
5.8.1 QR decompositionp. 105
5.8.2 Singular value decompositionp. 106
5.8.3 Eigendecompositionp. 107
5.8.4 LU decompositionp. 107
5.8.5 Cholesky decompositionp. 108
5.8.6 Schur decompositionp. 109
5.8.7 backsolve and forwardsolvep. 109
5.9 Systems of nonlinear equationsp. 109
5.9.1 multiroot in the rootSolve packagep. 109
5.9.2 nleqslvp. 111
5.9.3 BBsolve() in the BB packagep. 112
5.10 Case studiesp. 117
5.10.1 Spectroscopic analysis of a mixturep. 117
5.10.2 van der Waals equationp. 120
5.10.3 Chemical equilibriump. 122
6 Numerical differentiation and integrationp. 125
6.1 Numerical differentiationp. 125
6.1.1 Numerical differentiation using base Rp. 125
6.1.1.1 Using the fundamental definitionp. 125
6.1.1.2 diff()p. 126
6.1.2 Numerical differentiation using the numDeriv packagep. 127
6.1.2.1 grad()p. 128
6.1.2.2 jacobian()p. 128
6.1.2.3 hessianp. 129
6.1.3 Numerical differentiation using the pracma packagep. 129
6.1.3.1 fderiv()p. 129
6.1.3.2 numderiv() and numdiff ()p. 130
6.1.3.3 grad() and gradient ()p. 131
6.1.3.4 jacobian()p. 131
6.1.3.5 hessianp. 132
6.1.3.6 laplacian()p. 133
6.2 Numerical integrationp. 133
6.2.1 integrate: Basic integration in Rp. 134
6.2.2 Integrating discretized functionsp. 136
6.2.3 Gaussian quadraturep. 137
6.2.4 More integration routines in pracmap. 140
6.2.5 Functions with singularitiesp. 142
6.2.6 Infinite integration domainsp. 144
6.2.7 Integrals in higher dimensionsp. 146
6.2.8 Monte Carlo and sparse grid integrationp. 148
6.2.9 Complex line integralsp. 150
6.3 Symbolic manipulations in Rp. 152
6.3.1 D()p. 152
6.3.2 deriv()p. 152
6.3.3 Polynomial functionsp. 154
6.3.4 Interfaces to symbolic packagesp. 155
6.4 Case studiesp. 155
6.4.1 Circumference of an ellipsep. 155
6.4.2 Integration of a Lorentzian derivative spectrump. 156
6.4.3 Volume of an ellipsoidp. 157
7 Optimizationp. 159
7.1 One-dimensional optimizationp. 159
7.2 Multi-dimensional optimization with optim()p. 162
7.2.1 optim() with "Nelder-Mead" defaultp. 163
7.2.2 optim() with "BFGS" methodp. 165
7.2.3 optim() with "CG" methodp. 167
7.2.4 optim() with "L-BFGS-B" method to find a local minimump. 167
7.3 Other optimization packagesp. 169
7.3.1 nlm()p. 169
7.3.2 ucminf packagep. 171
7.3.3 BB packagep. 171
7.3.4 optimx() wrapperp. 172
7.3.5 Derivative-free optimization algorithmsp. 172
7.4 Optimization with constraintsp. 173
7.4.1 constrOptim to optimize functions with linear constraintsp. 173
7.4.2 External packages alabama and Rsolnpp. 175
7.5 Global optimization with many local minimap. 177
7.5.1 Simulated annealingp. 178
7.5.2 Genetic algorithmsp. 181
7.5.2.1 DEoptimp. 181
7.5.2.2 rgenoudp. 183
7.5.2.3 GAp. 183
7.6 Linear and quadratic programmingp. 183
7.6.1 Linear programmingp. 183
7.6.2 Quadratic programmingp. 186
7.7 Mixed-integer linear programmingp. 189
7.7.1 Mixed-integer problemsp. 189
7.7.2 Integer programming problemsp. 190
7.7.2.1 Knapsack problemsp. 191
7.7.2.2 Transportation problemsp. 191
7.7.2.3 Assignment problemsp. 192
7.7.2.4 Subsetsum problemsp. 193
7.8 Case studyp. 194
7.8.1 Monte Carlo simulation of the 2D Ising modelp. 194
8 Ordinary differential equationsp. 199
8.1 Euler methodp. 200
8.1.1 Projectile motionp. 201
8.1.2 Orbital motionp. 203
8.2 Improved Euler methodp. 205
8.3 deSolve packagep. 208
8.3.1 Isoda() andlsode()p. 210
8.3.2 "adams" and related methodsp. 211
8.3.3 Stiff systemsp. 213
8.4 Matrix exponential solution for sets of linear ODEsp. 214
8.5 Events and rootsp. 215
8.6 Difference equationsp. 220
8.7 Delay differential equationsp. 221
8.8 Differential algebraic equationsp. 224
8.9 rootSolve for steady state solutions of systems of ODEsp. 227
8.10 bvpSolve package for boundary value ODE problemsp. 230
8.10.1 bvpshoot()p. 230
8.10.2 bvptwp()p. 231
8.10.3 bvpcol()p. 232
8.11 Stochastic differential equations: GillespieSSA packagep. 233
8.12 Case studiesp. 240
8.12.1 Launch of the space shuttlep. 240
8.12.2 Electrostatic potential of DNA solutionsp. 241
8.12.3 Bifurcation analysis of Lotka-Volterra modelp. 244
9 Partial differential equationsp. 249
9.1 Diffusion equationp. 249
9.2 Wave equationp. 251
9.2.1 FTCS methodp. 252
9.2.2 Lax methodp. 253
9.3 Laplace's equationp. 254
9.4 Solving PDEs with the ReacTran packagep. 256
9.4.1 setup.grid.1Dp. 257
9.4.2 setup.prop.1Dp. 258
9.4.3 tran.1Dp. 258
9.4.4 Calling ode.1D or steady.1Dp. 259
9.5 Examples with the ReacTran packagep. 259
9.5.1 1-D diffusion-advection equationp. 259
9.5.2 1-D wave equationp. 260
9.5.3 Laplace equationp. 262
9.5.4 Poisson equation for a dipolep. 263
9.6 Case studiesp. 264
9.6.1 Diffusion in a viscosity gradientp. 264
9.6.2 Evolution of a Gaussian wave packetp. 267
9.6.3 Burgers equationp. 269
10 Analyzing datap. 273
10.1 Getting data into Rp. 273
10.2 Data framesp. 274
10.3 Summary statistics for a single datasetp. 275
10.4 Statistical comparison of two samplesp. 277
10.5 Chi-squared test for goodness of fitp. 279
10.6 Correlationp. 280
10.7 Principal component analysisp. 281
10.8 Cluster analysisp. 283
10.8.1 Using hclust for agglomerative hierarchical clusteringp. 283
10.8.2 Using diana for divisive hierarchical clusteringp. 284
10.8.3 Using kmeans for partitioning clusteringp. 285
10.8.4 Using pam for partitioning around medoidsp. 286
10.9 Case studiesp. 286
10.9.1 Chi square analysis of radioactive decayp. 286
10.9.2 Principal component analysis of quasarsp. 289
11 Fitting models to datap. 293
11.1 Fitting data with linear modelsp. 293
11.1.1 Polynomial fitting with lmp. 294
11.2 Fitting data with nonlinear modelsp. 296
11.3 Inverse modeling of ODEs with the FME packagep. 304
11.4 Improving the convergence of series: Padé and Shanksp. 309
11.5 Interpolationp. 311
11.5.1 Linear interpolationp. 312
11.5.2 Polynomial interpolationp. 313
11.5.3 Spline interpolationp. 313
11.5.3.1 Integration and differentiation with splinesp. 314
11.5.4 Rational interpolationp. 315
11.6 Time series, spectrum analysis, and signal processingp. 316
11.6.1 Fast Fourier transform: fft() functionp. 316
11.6.2 Inverse Fourier transformp. 317
11.6.3 Power spectrum: spectrumO functionp. 318
11.6.4 findpeaks() functionp. 321
11.6.5 Signal packagep. 322
11.6.5.1 Butterworth filterp. 322
11.6.5.2 Savitzky-Golay filterp. 324
11.6.5.3 fit filterp. 324
11.7 Case studiesp. 325
11.7.1 Fitting a rational function to datap. 325
11.7.2 Rise of atmospheric carbon dioxidep. 327
Bibliographyp. 329
Indexp. 331