Ch1.1.2 Numerical Analysis in R

Numerical Methods vs Numerical Analysis

  • Recall the distinction between numerical methods and numerical analysis:
  • Numerical methods is concerned with the different formulas available for common problems in computational science.
  • Numerical analysis is concerned with analzying how fast, efficient and accurate the different numerical methods are.

title

Numerical Analysis and Computing

  • Methods of numerical analysis are independent of computational software used.
  • Algebra and calculus are used to optimize algorithms for speed and accuracy, and to determine useful error bounds for computational results.
  • Taylor polynomials are often used to formulate numerical methods and develop error bounds.

Numerical Analysis and Computing

  • We will use computational software ( R ) and numerical methods to enrich our treatment of numerical analysis.
  • Other common choices for numerical methods include MATLAB, Python, Mathematica, and Maple.
  • Mathematical and Maple are computer algebra systems, while the others are not.

Computer Algebra Systems (CAS)

  • In a symbolic computation platform, expressions are first class objects, like numbers are to R.
  • Maple is a computer algebra system because performs algebra operations on symbolic quantities and variables.

R is not a CAS

In general, R does not work well with symbolic computation on expressions.

Using RStudio in Math Courses

  • R is a free and widely used programming language.
  • Typically used with RStudio, also free.
  • Not just for statistics - can also be used for math in the same way as MATLAB (Octave) or Python (Jupyter Notebook).
  • Knowing multiple languages good because of their strengths: https://www.ibm.com/cloud/blog/python-vs-r

From Wikipedia

  • The official R software environment is a GNU package.
  • R is written in C, Fortran, and R (partially self-hosting).
  • R is freely available under the GNU General Public License.
  • Pre-compiled executables for various operating systems.
  • R has a command line interface, but third-party graphical user interfaces include RStudio (an integrated development environment, or IDE), and Jupyter (a notebook interface).
  • See history on Wikipedia page.

Where to Get R and RStudio

Version of R

  • This command from Ch1.1.2 shows version of R being used.
print(version$version.string)
[1] "R version 4.0.4 (2021-02-15)"

RStudio Document Options

  • Presentations (RPres = R Presentation)
  • Written work (RMD = R Markdown)
  • Other document options available

This is an RPres Slide

\( e^{i \pi} + 1 = 0 \)

z <- complex(real = 0, imaginary = pi)
w <- exp(z) + 1
w
[1] 0+1.224606e-16i
round(w)
[1] 0+0i

Finding Help

Design Features of R

  • R is developed primarily by volunteers working for companies.
  • R has a modular environment that is extensible and flexible.
  • Users create modules which can be installed as packages.
  • The language provides specific features for using and managing datasets and numerical computation.
  • Because of its power and ready availability, R is a good environment for learning numerical analysis.

R Packages

  • The author of our book has written a program package (cmna) that can be downloaded from https://cran.rstudio.com.
  • cmna = “computational methods for numerical analysis.”
  • Other common packages can be downloaded as well.

CMNA Package

  • Here are some commands found in Ch1.1.2.
  • The library call makes package available for use.

library(cmna)
fibonacci(10)
[1] 55
3 + 8
[1] 11

CMNA Programs

  • The functions in cmna are typically simple in design and serve as a starting point in programming numerical methods.
  • Concepts in numerical analysis lead to more robust functions that are fast and accurate over a wide range of problems.
fibonacci <- function(n) {
    if(n == 0)
        return(0)
    if(n == 1)
        return(1)
    return(fibonacci(n - 1) + fibonacci(n - 2)) }
fibonacci(6)
[1] 8