Contents

Part I - Introduction

Chapter 1. Overview 1

1.1 Product Components 1

1.2 Software Requirements 2

1.3 NMath Assemblies 2

Microsoft Solver Foundation 3

1.4 NMath License Key 3

Evaluation License 3

Product License 3

1.5 NMath Configuration 4

Logging 5

License Key 5

Native Location 6

MKL Threading Control 6

MKL Conditional Numerical Reproducibility (CNR) 6

1.6 Building and Deploying NMath Applications 7

License Key 7

C++ Runtime 8

1.7 Web Applications 8

Referencing NMath 8

Kernel Assemblies and Native DLLs 9

NMath Configuration 9

1.8 Very Large Objects 10

Very Large Objects with ASP.NET 11

1.9 Documentation 12

This Manual 12

1.10 Technical Support 13

Part II - NMath Core

Chapter 2. NMath Core 17

Chapter 3. Complex Number Types 19

3.1 Creating Complex Numbers 19

Creating Complex Numbers from Numeric Values 19

Creating Complex Numbers from Strings 20

Implicit Conversion 21

3.2 Value Operations on Complex Numbers 21

3.3 Logical Operations on Complex Numbers 22

3.4 Arithmetic Operations on Complex Numbers 22

3.5 Functions of Complex Numbers 23

Conjugate, Norm, and Argument 23

Trigonometric Functions 24

Transcendental Functions 25

Absolute Value and Square Root 25

Chapter 4. Viewing Data 27

4.1 DataBlock Classes 27

Class Names 27

Data Block Properties 28

Accessing the Underlying Data 28

4.2 Slices and Ranges 29

Creating Slices and Ranges 29

Creating Abstract Subsets 30

Modifying Ranges and Slices 31

Chapter 5. Vector Classes 33

5.1 Class Names 33

5.2 Creating Vectors 33

Creating Vectors from Numeric Values 34

Creating Vectors from Strings 35

Implicit Conversion 38

Copying Vectors 38

New Vector Views 39

5.3 Value Operations on Vectors 40

Accessing and Modifying Vector Values 41

Clearing and Resizing a Vector 41

Appending to a Vector 42

5.4 Logical Operations on Vectors 43

5.5 Arithmetic Operations on Vectors 43

5.6 Functions of Vectors 45

Rounding Functions 45

Sums, Differences, and Products 46

Min/Max Functions 47

Statistical Functions 47

Trigonometric Functions 48

Transcendental Functions 48

Absolute Value and Square Root 49

Sorting Functions 49

Complex Vector Functions 50

5.7 Generic Functions 50

5.8 Vector Enumeration 51

Chapter 6. Matrix Classes 53

6.1 Class Names 53

6.2 Creating Matrices 53

Creating Matrices from Numeric Values 54

Creating Matrices from Strings 56

Implicit Conversion 59

Copying Matrices 59

Matrix Views 60

6.3 Value Operations on Matrices 60

Accessing and Modifying Matrix Values 61

Clearing and Resizing a Matrix 62

6.4 Logical Operations on Matrices 63

6.5 Arithmetic Operations on Matrices 63

6.6 Vector Views 65

Row and Column Views 66

Diagonal Views 66

Arbitrary Slices 66

6.7 Functions of Matrices 67

Matrix Transposition 67

Matrix Norms 67

Matrix Products 68

Matrix Inverse and Pseudoinverse 69

Rounding Functions 70

Sums and Differences 71

Min/Max Functions 72

Statistical Functions 72

Trigonometric Functions 73

Transcendental Functions 73

Absolute Value and Square Root 74

Sorting Functions 74

Complex Matrix Functions 75

6.8 Generic Functions 75

Applying Elementwise Functions 76

Applying Columnwise Functions 76

6.9 Matrix Enumeration 77

Chapter 7. Solutions of Linear Systems 79

7.1 Class Names 79

7.2 Creating LU Factorizations 80

7.3 Using LU Factorizations 81

Component Matrices 81

Solving for Right-Hand Sides 81

Computing Inverses, Determinants, and Condition Numbers 82

7.4 Static Methods 84

Chapter 8. Least Squares 87

8.1 Class Names 87

8.2 Creating Least Squares Solutions 88

8.3 Using Least Squares Solutions 89

8.4 Nonnegative Least Squares Solutions 90

Chapter 9. Random Number Generators 91

9.1 Scalar Random Number Generators 91

Underlying Uniform Generators 92

Generating Random Numbers 93

Random Seeds 95

9.2 Vectorized Random Number Generators 96

Generating Random Numbers 98

Successive Random Numbers 99

Independent Streams 100

Quasirandom Numbers 102

Chapter 10. Fourier Transforms, Convolution and Correlation 103

10.1 Fast Fourier Transforms 103

FFT Classes 103

Creating FFT Instances 104

Scale Factors 104

Computing FFTs 105

Unpacking Real Results 106

Inverting Real Results 107

Strided Signals 108

10.2 Convolution and Correlation 110

Convolution and Correlation Classes 110

Creating Convolution and Correlation Instances 111

Convolution and Correlation Properties 111

Computing Convolutions and Correlations 112

Windowing Options 112

Chapter 11. Discrete Wavelet Transforms 115

11.1 Creating Wavelets 115

11.2 Computing Discrete Wavelet Transforms 116

Single Step DWT 117

Multilevel DWT 118

Accessing the Coefficients 118

Threshold Calculations 119

Thresholding 119

Chapter 12. Histograms 121

12.1 Creating Histograms 121

12.2 Adding Data to Histograms 122

12.3 Value Operations of Histograms 123

12.4 Displaying Histograms 124

Chapter 13. Calculus 125

13.1 Encapsulating Functions 125

Creating a Function of One Variable 125

Properties of Functions 126

Evaluating Functions 126

Algebraic Manipulation of Functions 127

13.2 Numerical Integration 128

Computing Integrals 129

Romberg Integration 130

Gauss-Kronrod Integration 132

13.3 Differentiation 135

13.4 Polynomials 137

Creating Polynomials 137

Properties of Polynomials 138

Evaluating Polynomials 138

Algebraic Manipulation of Polynomials 139

Integration 140

Differentiation 140

13.5 Function Interpolation 141

Linear Spline Interpolation 142

Cubic Spline Interpolation 142

Smooth Splines 143

Creating Your Own Interpolation Classes 143

Chapter 14. Signal Processing 145

14.1 Moving Window Filtering 145

Creating Moving Window Filter Objects 145

Moving Window Filter Properties 148

Filtering Data 148

14.2 Savitzky-Golay Filtering 149

Creating Savitzky-Golay Filter Objects 149

Savitzky-Golay Filter Properties 150

Filtering Data 150

14.3 Savitzky-Golay Peak Finding 151

Creating Savitzky-Golay Peak Finders 151

Savitzky-Golay Peak Finder Results 152

Advanced Savitzky-Golay Peak Finder Properties 153

14.4 Rule-Based Peak Finding 153

Creating Rule-Based Peak Finders 153

Adding Rules 154

Rule-Based Peak Finder Results 154

Chapter 15. Special Functions 157

15.1 Special Functions 157

Part III - Matrix Analysis

Chapter 16. Matrix Functions 163

Chapter 17. Structured Sparse Matrix Types 165

17.1 Lower Triangular Matrices 165

17.2 Upper Triangular Matrices 166

17.3 Symmetric Matrices 167

17.4 Hermitian Matrices 168

17.5 Banded Matrices 168

17.6 Tridiagonal Matrices 170

17.7 Symmetric Banded Matrices 171

17.8 Hermitian Banded Matrices 172

Chapter 18. Using The Structured Sparse Matrix Classes 173

18.1 Creating Matrices 173

Creating Default Matrices 173

Creating Sparse Matrices from General Matrices 175

Creating Sparse Matrices from Other Sparse Matrices 176

Creating Sparse Matrices from a Data Vector 177

Implicit Conversion 178

Copying Matrices 178

18.2 Value Operations on Matrices 179

Accessing and Modifying Matrix Values 180

Resizing a Matrix 181

18.3 Logical Operations on Matrices 182

18.4 Arithmetic Operations on Matrices 182

18.5 Vector Views 183

18.6 Functions of Matrices 184

Matrix Transposition 184

Matrix Inner Products 184

Matrix Norms 185

Trigonometric and Transcendental Functions 187

Absolute Value 187

Complex Matrix Functions 188

18.7 Generic Functions 188

Chapter 19. General Sparse Vectors and Matrices 191

19.1 Sparse Vectors 191

Storage Format 191

Creating Sparse Vectors 192

Accessing and Modifying Sparse Vector Values 193

Operations on Sparse Vectors 193

Sparse Vector Functions 194

Creating Dense Vectors from Sparse Vectors 194

19.2 Sparse Matrices 195

Storage Format 195

Creating Sparse Matrices 196

Accessing and Modifying Sparse Matrix Values 198

Operations on Sparse Matrices 199

Sparse Matrix Functions 199

Creating Dense Matrices from Sparse Matrices 200

19.3 Sparse Matrix Factorizations 200

Factorization Classes 200

Creating Factorizations 201

Using Factorizations 202

Chapter 20. Structured Sparse Matrix Factorizations 203

20.1 Factorization Classes 203

20.2 Creating Factorizations 204

20.3 Using Factorizations 206

Solving for Right-Hand Sides 206

Computing Inverses, Determinants, and Condition Numbers 208

Chapter 21. Least Squares Solutions 211

21.1 Ordinary Least Squares Methods 211

Least Squares Using Cholesky Factorization 211

Least Squares Using QR Decomposition 212

Least Squares Using SVD 212

21.2 Creating Ordinary Least Squares Objects 212

21.3 Using Ordinary Least Squares Objects 214

Testing for Goodness 214

Solving Least Squares Problems 214

Retrieving Information About the Original Matrix 215

21.4 Weighted Least Squares 215

21.5 Iteratively Reweighted Least Squares 218

Convergence Functions 219

Weighting Functions 221

Chapter 22. Decompositions 223

22.1 QR Decompositions 223

Creating QR Decompositions 223

Using QR Decompositions 225

Reusing QR Decompositions 227

22.2 Singular Value Decompositions 228

Creating Singular Value Decompositions 228

Using Singular Value Decompositions 229

Reusing Singular Value Decompositions 231

Chapter 23. EigenValue Problems 233

23.1 Eigenvalue Classnames 233

23.2 Using the Eigenvalue Classes 234

Constructing Eigenvalue Objects 234

Testing for Goodness 235

Retrieving Eigenvalues and Eigenvectors 235

Retrieving Information About the Original Matrix 236

Reusing Eigenvalue Decompositions 236

23.3 Using the Eigenvalue Server Classes 237

Constructing Eigenvalue Servers 237

Configuring Eigenvalue Servers 237

Creating Eigenvalue Objects from a Server 239

Part IV - Analysis

Chapter 24. The Analysis Namespace 243

Chapter 25. Encapsulating Multivariate Functions 245

25.1 Creating Multivariate Functions 245

25.2 Evaluating Multivariate Functions 246

25.3 Algebraic Manipulation of Multivariate Functions 246

Chapter 26. Minimizing Univariate Functions 249

26.1 Bracketing a Minimum 249

26.2 Minimizing Functions Without Calculating the Derivative 250

26.3 Minimizing Derivable Functions 252

Chapter 27. Minimizing Multivariate Functions 255

27.1 Minimizing Functions Without Calculating the Derivative 255

27.2 Minimizing Derivable Functions 257

Chapter 28. Simulated Annealing 261

28.1 Temperature 261

28.2 Annealing Schedules 261

Linear Annealing Schedules 262

Custom Annealing Schedules 263

28.3 Minimizing Functions by Simulated Annealing 264

28.4 Annealing History 265

Chapter 29. Linear Programming 269

29.1 Encapsulating LP Problems 269

Adding Bounds and Constraints 270

29.2 Solving LP Problems 271

Chapter 30. Nonlinear and Quadratic Programming 273

30.1 Objective and Constraint Function Classes 273

Objective Function Classes 273

Constraint Function Classes 275

30.2 Nonlinear Programming 276

Encapsulating the Problem 276

Adding Bounds and Constraints 278

Solving the Problem 280

30.3 Quadratic Programming 283

Encapsulating the Problem 284

Adding Bounds and Constraints 284

Solving the Problem 285

30.4 Constrained Least Squares 288

Encapsulating the Problem 288

Adding Bounds and Constraints 288

Solving the Problem 289

Chapter 31. Fitting Polynomials 293

31.1 Creating PolynomialLeastSquares 293

31.2 Properties of PolynomialLeastSquares 294

Chapter 32. Nonlinear Least Squares 295

32.1 Nonlinear Least Squares Interfaces 295

Minimization 296

Minimization Results 298

Implementations 298

32.2 Trust-Region Minimization 299

Constructing a TrustRegionMinimizer 299

Minimization 299

Linear Bound Constraints 301

Minimization Results 302

32.3 Levenberg-Marquardt Minimization 303

Constructing a LevenbergMarquardtMinimizer 304

Minimization 304

Minimization Results 305

32.4 Nonlinear Least Squares Curve Fitting 305

Generalized One Variable Functions 305

Encapsulating One Variable Functions 306

Predefined Functions 309

Constructing a OneVariableFunctionFitter 309

Fitting Data 311

Fit Results 312

32.5 Nonlinear Least Squares Surface Fitting 313

Generalized Multivariable Functions 313

Encapsulating Generalized Multivariable Functions 314

Constructing a MultiVariableFunctionFitter 315

Fitting Data 316

Fit Results 318

Chapter 33. Finding Roots of Univariate Functions 321

33.1 Finding Function Roots Without Calculating the Derivative 321

33.2 Finding Function Roots of Derivable Functions 323

Chapter 34. Integrating Multivariable Functions 325

34.1 Creating TwoVariableIntegrators 325

34.2 Integrating Functions of Two Variables 326

Chapter 35. Differential Equations 329

35.1 Encapsulating Differential Equations 329

35.2 Solving Differential Equations 330

Constructing RungeKuttaSolver Instances 330

Solving First Order Initial Value Problems 331

35.3 Dormand–Prince Method 332

35.4 Stiff Equations 335

Part V - Statistics

Chapter 6. Statistics Introduction 1

36.1 Product Features 1

36.2 Namespaces 2

Chapter 37. Data Frames 3

37.1 Column Types 4

Creating Columns 4

Adding and Removing Data 6

Accessing Column Data 7

Column Properties 7

Reordering Column Data 8

Missing Values 8

Transforming Column Data 10

Exporting Column Data 12

37.2 Creating DataFrames 12

Creating Empty DataFrames 12

Creating DataFrames from Arrays of Columns 13

Creating DataFrames from Matrices 14

Creating DataFrames from ADO.NET Objects 14

Creating DataFrames from Strings 15

37.3 Adding and Removing Columns 16

37.4 Adding and Removing Rows 18

Modifying Row Keys 20

37.5 Properties of DataFrames 21

37.6 Accessing DataFrames 22

Accessing Elements 22

Accessing Columns 22

Accessing Rows 23

37.7 Subsets 25

Creating Subsets 25

Properties of Subsets 26

Accessing Elements 26

Logical Operations on Subsets 27

Arithmetic Operations on Subsets 27

Manipulating Subsets 28

Groupings 30

Random Samples 30

37.8 Accessing Sub-Frames 30

37.9 Reordering DataFrames 32

Sorting Rows 32

Permuting Rows and Columns 33

37.10 Factors 34

Creating Factors 34

Properties of Factors 36

Accessing Factors 36

Creating Groupings with Factors 36

37.11 Cross-Tabulation 40

Column Delegates 40

Applying Column Delegates to Tabulated Data 41

37.12 Exporting Data from DataFrames 44

Exporting to a Matrix 44

Exporting to a String 45

Exporting to an ADO.NET DataTable 46

Binary and SOAP Serialization 47

Chapter 38. Descriptive Statistics 49

38.1 Column Types 50

38.2 Missing Values 51

38.3 Counts and Sums 53

38.4 Min/Max Functions 54

38.5 Ranks, Percentiles, Deciles, and Quartiles 54

38.6 Central Tendency 56

38.7 Spread 58

38.8 Shape 59

38.9 Covariance, Correlation, and Autocorrelation 60

38.10 Sorting 62

38.11 Logical Functions 62

Chapter 39. Special Functions 65

39.1 Combinatorial Functions 65

39.2 Gamma Function 65

39.3 Beta Function 66

Chapter 40. Probability Distributions 67

40.1 Distribution Classes 67

Beta Distribution 69

Binomial Distribution 70

Chi-Square Distribution 71

Exponential Distribution 72

F Distribution 73

Gamma Distribution 73

Geometric Distribution 75

Johnson Distribution 75

Logistic Distribution 77

Log-Normal Distribution 78

Negative Binomial Distribution 79

Normal Distribution 80

Poisson Distribution 80

Student’s t Distribution 81

Triangular Distribution 82

Uniform Distribution 83

Weibull Distribution 84

40.2 Correlated Random Inputs 85

Constructing Correlator Instances 85

Correlating Random Inputs 86

Correlator Properties 87

Convenience Method 87

40.3 Box-Cox Power Transformations 89

Chapter 41. Hypothesis Tests 91

41.1 Common Interface 91

Static Properties 91

Creating Hypothesis Test Objects 92

Properties of Hypothesis Test Objects 93

Modifying Hypothesis Test Objects 94

Printing Results 95

41.2 One Sample Z-Test 96

41.3 One Sample T-Test 98

41.4 Two Sample Paired T-Test 100

41.5 Two Sample Unpaired T-Test 103

41.6 Two Sample F-Test 106

41.7 Pearson’s Chi-Square Test 108

41.8 Fisher’s Exact Test 110

Chapter 42. Linear Regression 113

42.1 Creating Linear Regressions 113

Parameter Calculation by Least Squares Minimization 114

Intercept Parameters 115

42.2 Regression Results 115

Variance Inflation Factor 116

42.3 Predictions 117

42.4 Accessing and Modifying the Model 118

Accessing and Modifying Predictors 118

Accessing and Modifying Observations 120

Accessing and Modifying the Intercept Option 122

Updating the Entire Model 122

42.5 Significance of Parameters 123

Creating Linear Regression Parameter Objects 123

Properties Linear Regression Parameters 123

Hypothesis Tests 124

Updating Linear Regression Parameters 124

42.6 Significance of the Overall Model 125

Chapter 43. Logistic Regression 127

43.1 Regression Calculators 127

43.2 Creating Logistic Regressions 128

Design Variables 130

43.3 Checking for Convergence 131

43.4 Goodness of Fit 131

43.5 Parameter Estimates 133

43.6 Predicted Probabilities 134

43.7 Auxiliary Statistics 135

Chapter 44. Analysis of Variance 137

44.1 One-Way ANOVA 137

Creating One-Way ANOVA Objects 137

The One-Way ANOVA Table 139

Grand Mean, Group Means, and Group Sizes 140

Critical Value of the F Statistic 141

Updating One-Way ANOVA Objects 141

44.2 One-Way Repeated Measures ANOVA 141

Creating One-Way RANOVA Objects 142

The One-Way RANOVA Table 143

Grand Mean, Subject Means, and Treatment Means 144

Critical Value of the F Statistic 144

Updating One-Way RANOVA Objects 145

44.3 Two-Way Balanced ANOVA 145

Creating Two-Way ANOVA Objects 145

The Two-Way ANOVA Table 146

Cell Data 147

Grand Mean, Cell Means, and Group Means 148

ANOVA Regression Parameters 148

44.4 Two-Way Unbalanced ANOVA 154

Creating UnbalancedTwo-Way ANOVA Objects 154

Unbalanced Two-Way ANOVA Tables and Regression Parameters 154

44.5 Two-Way Repeated Measures ANOVA 156

Creating Two-Way RANOVA Objects 156

Two-Way RANOVA Tables 157

Chapter 45. Non-Parametric Tests 159

45.1 One Sample Kolmogorov-Smirnov Test 159

45.2 Two Sample Kolmogorov-Smirnov Test 161

45.3 Shapiro-Wilk Test 161

45.4 One Sample Anderson-Darling Test 162

45.5 Kruskal-Wallis Test 163

Creating Kruskal-Wallis Objects 163

The Kruskal-Wallis Table 165

Ranks, Grand Mean Ranks, Group Means Ranks, and Group Sizes 166

Critical Value of the Test Statistic 167

Updating Kruskal-Wallis Test Objects 168

45.6 Wilcoxon Signed-Rank Test 168

Creating Wilcoxon Signed-Rank Objects 168

Chapter 46. Multivariate Techniques 171

46.1 Principal Component Analysis 171

Creating Principal Component Analyses 171

Principal Component Analysis Results 172

46.2 Factor Analysis 174

Creating Factor Analyses 174

Factor Analysis Results 176

Factor Scores 179

46.3 Hierarchical Cluster Analysis 180

Distance Functions 180

Linkage Functions 182

Creating Cluster Analyses 184

Cluster Analysis Results 186

Reusing Cluster Analysis Objects 188

46.4 K-Means Clustering 189

Creating KMeansClustering Objects 189

Stopping Criteria 190

Clustering 190

Cluster Analysis Results 191

Chapter 47. Nonnegative Matrix Factorization 193

47.1 Nonnegative Matrix Factorization 193

Update Algorithms 194

47.2 Data Clustering Using NMF 196

Creating NMFClustering Instances 197

Performing the Factorization 197

Cluster Results 198

Computing a Consensus Matrix 200

Chapter 48. Partial Least Squares 205

48.1 Computing a PLS Regression 206

48.2 Error Checking 207

48.3 Predicted Values 207

48.4 Analysis of Variance 208

48.5 PLS Algorithms 208

48.6 Cross Validation 209

Jackknifing of Regression Coefficients 210

48.7 Partial Least Squares Discriminant Analysis 211

Chapter 49. Goodness of Fit 215

49.1 Significance of the Overall Model 215

49.2 Significance of Parameters 217

Creating Goodness of Fit Parameter Objects 217

Properties of Goodness of Fit Parameters 218

Hypothesis Tests 218

Chapter 50. Process Control 219

50.1 Process Capability 219

50.2 Process Performance 220

50.3 Z Bench 221

Part VI - Miscellaneous Topics

Chapter 51. Serialization 225

51.1 Binary Serialization 225

51.2 SOAP Serialization 226

51.3 XML Serialization 228

Chapter 52. Database Integration 231

52.1 Creating ADO.NET Objects from Vectors and Matrices 231

52.2 Creating Vector and Matrices from ADO.NET Objects 232

Chapter 53. Error Handling 235

53.1 Exception Types 235

Index 237