R_handout_1[1]

R_handout_1[1] - A First Look at R Exploring Gaussian...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: A First Look at R : Exploring Gaussian Elimination Bruce Cohen and David Sklar January 24, 2008 v0.2 1 Introduction The purpose of this handout is to introduce you to the R-Project [2]. We assume you also have a handout on Gaussian elimination taken from Burden’s book on numerical analysis [1]. Mathematically, we will be heading towards this plan. We want to solve linear system that looks like this: E 1 : 9 x 1 + 3 x 2 + 4 x 3 = 7 E 2 : 4 x 1 + 3 x 2 + 4 x 3 = 8 E 3 : x 1 + x 2 + x 3 = 3 Using matrix notation, we get a coefficient matrix times an x-vector equal to some constant vector. 9 3 4 4 3 4 1 1 1 x 1 x 2 x 3 = 7 8 3 We concatenate the coefficient matrix and the constant matrix to build an augmented matrix, 9 3 4 7 4 3 4 8 1 1 1 3 and use elementary row operations to get a upper triangle matrix like this. 9 3 4 7 0 1 . 66667 2 . 22222 4 . 88889 0 0-0 . 33333 0 . 26667 We then use backsubstitution to get values for x 1 , x 2 and x 3 . The plan for this handout is to walk you through a little bit of R , and then use R to solve the given linear system. 2 Starting with R 2.1 Using the command line R is an interpreted language which can be run from an R-command line. You can do very simple arithmetic (e.g. add two digits), > 4 + 5 [1] 9 and not so simple (e.g. approximate e π ), > exp(pi) [1] 23.14069 The [1] is part of the way R prints results and is used to help you navigate the output. R is designed to work with data and various data structures. Let’s store our answer into a variable named a . > a = exp(pi) We can see a by typing it > a [1] 23.14069 Note that R does not need “type” declarations. It can determine (at least a temporary) initial type for the data structure. We can make b a list of the 10 normally distributed random numbers. > b = rnorm(9) > b [1] 0.22503607 -0.20218255 0.04255864 [4] -0.31573391 0.55462685 1.90294722 [7] 0.18024143 -0.24645664 -1.55614012 1 By entering > b[7] [1] 0.1802414 we get the seventh element of the b “vector” which is also the first number printed on the third row of the R-output. Now you can see that the number in brackets (e.g. [7] ) at the beginning of each line is the index of the first entry on that line. Note we could avoid printing the navigation index by typing, > cat(b[7]) 0.1802414 The function cat() outputs an object. For people who have used a UNIX command line, cat() will look familiar....
View Full Document

This note was uploaded on 09/16/2011 for the course MATH 400 taught by Professor Staff during the Spring '11 term at S.F. State.

Page1 / 6

R_handout_1[1] - A First Look at R Exploring Gaussian...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online