summaryrefslogtreecommitdiff
path: root/Linear_Algebra_by_Jim_Hefferon/CH1
diff options
context:
space:
mode:
Diffstat (limited to 'Linear_Algebra_by_Jim_Hefferon/CH1')
-rw-r--r--Linear_Algebra_by_Jim_Hefferon/CH1/EX1.11/Ex1_11.R18
-rw-r--r--Linear_Algebra_by_Jim_Hefferon/CH1/EX1.12/Ex1_12.R17
-rw-r--r--Linear_Algebra_by_Jim_Hefferon/CH1/EX1.13/Ex1_13.R18
-rw-r--r--Linear_Algebra_by_Jim_Hefferon/CH1/EX1.3/Ex1_3.R6
-rw-r--r--Linear_Algebra_by_Jim_Hefferon/CH1/EX1.4/Ex1_4.R22
-rw-r--r--Linear_Algebra_by_Jim_Hefferon/CH1/EX1.7/Ex1_7.R20
-rw-r--r--Linear_Algebra_by_Jim_Hefferon/CH1/EX1.8/Ex1_8.R17
-rw-r--r--Linear_Algebra_by_Jim_Hefferon/CH1/EX1.9/Ex1_9.R21
-rw-r--r--Linear_Algebra_by_Jim_Hefferon/CH1/EX2.1/Ex1_2_1.R20
-rw-r--r--Linear_Algebra_by_Jim_Hefferon/CH1/EX2.12/Ex1_2_12.R7
-rw-r--r--Linear_Algebra_by_Jim_Hefferon/CH1/EX2.3/Ex1_2_3.R20
-rw-r--r--Linear_Algebra_by_Jim_Hefferon/CH1/EX2.5/Ex1_2_5.R19
-rw-r--r--Linear_Algebra_by_Jim_Hefferon/CH1/EX2.7/Ex1_2_7.R22
-rw-r--r--Linear_Algebra_by_Jim_Hefferon/CH1/EX3.3/Ex1_3_3.R24
-rw-r--r--Linear_Algebra_by_Jim_Hefferon/CH1/EX3.5/Ex1_3_5.R18
15 files changed, 269 insertions, 0 deletions
diff --git a/Linear_Algebra_by_Jim_Hefferon/CH1/EX1.11/Ex1_11.R b/Linear_Algebra_by_Jim_Hefferon/CH1/EX1.11/Ex1_11.R
new file mode 100644
index 00000000..a005839b
--- /dev/null
+++ b/Linear_Algebra_by_Jim_Hefferon/CH1/EX1.11/Ex1_11.R
@@ -0,0 +1,18 @@
+#Example 1.11,page 6
+#package used: matlib
+#installation run command : install.packages("matlib")
+#package repo : https://github.com/friendly/matlib
+
+#installation and loading library
+#install.packages("matlib")
+library("matlib")
+
+#program
+A <- matrix(c(1,2,0,0,-1,-2,1,0,0,1,0,2,0,2,1,1),ncol=4)
+b <- c(0,4,0,5)
+Ab <- cbind(A,b)
+Ab <- rowadd(Ab,1,2,-1)
+Ab <- rowswap(Ab,2,3)
+Ab <- rowadd(Ab,3,4,-2)
+Ab
+#Back-substitution gives w = 1, z = 2 , y = -1, and x = -1. \ No newline at end of file
diff --git a/Linear_Algebra_by_Jim_Hefferon/CH1/EX1.12/Ex1_12.R b/Linear_Algebra_by_Jim_Hefferon/CH1/EX1.12/Ex1_12.R
new file mode 100644
index 00000000..e7c4bf79
--- /dev/null
+++ b/Linear_Algebra_by_Jim_Hefferon/CH1/EX1.12/Ex1_12.R
@@ -0,0 +1,17 @@
+#Example 1.12 Section I. Solving Linear Systems page7
+#package used matlib v0.9.1
+#install package using command: install.packages("matlib")
+#Github reposiory of matlib :https://github.com/friendly/matlib
+
+#installing and loading library
+#install.packages("matlib")
+library("matlib")
+
+#program
+A <- matrix(c(1,2,2,3,1,2),ncol = 2)
+b <- c(1,-3,-2)
+#for this problem we cannot use normal method because the number of equations is more than number of variables
+#so we use gaussian elimination technique.
+gaussianElimination(A, b, tol = sqrt(.Machine$double.eps), verbose = FALSE,
+ latex = FALSE, fractions = FALSE)
+# result shows that one of the equations is redundant, here x=-2,y=1 \ No newline at end of file
diff --git a/Linear_Algebra_by_Jim_Hefferon/CH1/EX1.13/Ex1_13.R b/Linear_Algebra_by_Jim_Hefferon/CH1/EX1.13/Ex1_13.R
new file mode 100644
index 00000000..a7d7f3c3
--- /dev/null
+++ b/Linear_Algebra_by_Jim_Hefferon/CH1/EX1.13/Ex1_13.R
@@ -0,0 +1,18 @@
+#Example 1.13,page 7
+#package used matlib v0.9.1
+#install package using command: install.packages("matlib")
+#Github reposiory of matlib :https://github.com/friendly/matlib
+
+#installation and loading library
+#install.packages("matlib")
+library("matlib")
+
+#program
+A <- matrix(c(1,2,2,3,1,2),ncol = 2)
+b <- c(1,-3,0)
+Ab <- cbind(A,b)
+Ab <- rowadd(Ab,1,2,-2)
+Ab <- rowadd(Ab,1,3,-2)
+Ab <- rowadd(Ab,2,3,-(4/5))
+Ab
+#the echelon form shows that the system is inconsistent,hence the solution set is empty \ No newline at end of file
diff --git a/Linear_Algebra_by_Jim_Hefferon/CH1/EX1.3/Ex1_3.R b/Linear_Algebra_by_Jim_Hefferon/CH1/EX1.3/Ex1_3.R
new file mode 100644
index 00000000..663ef17b
--- /dev/null
+++ b/Linear_Algebra_by_Jim_Hefferon/CH1/EX1.3/Ex1_3.R
@@ -0,0 +1,6 @@
+#Example 1.3
+#Section I. Solving Linear Systems,page 3
+A <- matrix(c(3,-1,2,1),ncol = 2)
+b <- c(7,6)
+x <- solve(A) %*% b
+x \ No newline at end of file
diff --git a/Linear_Algebra_by_Jim_Hefferon/CH1/EX1.4/Ex1_4.R b/Linear_Algebra_by_Jim_Hefferon/CH1/EX1.4/Ex1_4.R
new file mode 100644
index 00000000..7a1b7ebc
--- /dev/null
+++ b/Linear_Algebra_by_Jim_Hefferon/CH1/EX1.4/Ex1_4.R
@@ -0,0 +1,22 @@
+#Example 1.4,Section I. Solving Linear Systems
+#page 3
+#package used: matlib
+#installation run command : install.packages("matlib")
+#package repo : https://github.com/friendly/matlib
+
+#installing and loading library
+#install.packages("matlib")
+library("matlib")
+
+#program
+A <- matrix(c(0,1,1/3,0,5,2,3,-2,0),ncol = 3,nrow = 3)
+b <- c(9,2,3)
+Ab <- cbind(A,b)
+Ab <- rowswap(Ab,1,3)
+Ab <- rowmult(Ab,1,3)
+Ab <- rowmult(Ab,1,-1)
+Ab <- rowadd(Ab,1,2,1)
+Ab
+#from Ab (X3=3)(since drom row3,3*X3=9)
+#from Ab row2 -1*X2-2*x3=-7,so X2=1
+#from Ab row1 X1+6*x2=9,so X1 = 3 \ No newline at end of file
diff --git a/Linear_Algebra_by_Jim_Hefferon/CH1/EX1.7/Ex1_7.R b/Linear_Algebra_by_Jim_Hefferon/CH1/EX1.7/Ex1_7.R
new file mode 100644
index 00000000..86158a6f
--- /dev/null
+++ b/Linear_Algebra_by_Jim_Hefferon/CH1/EX1.7/Ex1_7.R
@@ -0,0 +1,20 @@
+#Example 1.7,page nO:5
+#package used: matlib
+#installation run command : install.packages("matlib")
+#package repo : https://github.com/friendly/matlib
+
+#installing and loading library
+#install.packages("matlib")
+library("matlib")
+
+#program
+A <- matrix(c(1,2,1,1,-1,-2,0,3,-1),ncol = 3)
+b <- c(0,3,3)
+Ab <- cbind(A,b)
+Ab <- rowadd(Ab,1,2,-2)
+Ab <- rowadd(Ab,1,3,-1)
+Ab <- rowadd(Ab,2,3,-1)
+Ab
+#from row3 : -4z=0,so z=0
+#from row2 : -3y+3z=3,so y=-1
+#from row1 : x+y=0,so x=1 \ No newline at end of file
diff --git a/Linear_Algebra_by_Jim_Hefferon/CH1/EX1.8/Ex1_8.R b/Linear_Algebra_by_Jim_Hefferon/CH1/EX1.8/Ex1_8.R
new file mode 100644
index 00000000..c4f0cdcf
--- /dev/null
+++ b/Linear_Algebra_by_Jim_Hefferon/CH1/EX1.8/Ex1_8.R
@@ -0,0 +1,17 @@
+#Example 1.8,page 5
+#package used: matlib
+#installation run command : install.packages("matlib")
+#package repo : https://github.com/friendly/matlib
+
+#installing and loading library
+#install.packages("matlib")
+library("matlib")
+
+#program
+A <- matrix(c(40,-50,15,25),ncol = 2)
+b <- c(100,50)
+Ab <- cbind(A,b)
+Ab <- rowadd(Ab,1,2,1.25)
+Ab
+#from row2 : 43.75c = 175,so c= 4
+#from row1 : 40h+15c=100,so h=1
diff --git a/Linear_Algebra_by_Jim_Hefferon/CH1/EX1.9/Ex1_9.R b/Linear_Algebra_by_Jim_Hefferon/CH1/EX1.9/Ex1_9.R
new file mode 100644
index 00000000..25e09a21
--- /dev/null
+++ b/Linear_Algebra_by_Jim_Hefferon/CH1/EX1.9/Ex1_9.R
@@ -0,0 +1,21 @@
+#Example 1.9,chapter1 linear systems page 6
+#Example showing gauss method to reduce given system of linear equations
+#package used matlib v0.9.1
+#install package using command: install.packages("matlib")
+#Github reposiory of matlib :https://github.com/friendly/matlib
+
+#installing and loading library
+#install.packages("matlib")
+library("matlib")
+
+#program
+A <- matrix(c(1,2,3,1,4,6,1,-3,-5),ncol = 3)
+b <-c(9,1,0)
+Ab <- cbind(A,b)
+Ab <-rowadd(Ab,1,2,-2)
+Ab <-rowadd(Ab,1,3,-3)
+Ab <-rowadd(Ab,2,3,-(3/2))
+Ab
+#from Ab row3: z=3
+#from Ab row2: y=-1
+#from Ab row1: x=7 \ No newline at end of file
diff --git a/Linear_Algebra_by_Jim_Hefferon/CH1/EX2.1/Ex1_2_1.R b/Linear_Algebra_by_Jim_Hefferon/CH1/EX2.1/Ex1_2_1.R
new file mode 100644
index 00000000..0e4eac30
--- /dev/null
+++ b/Linear_Algebra_by_Jim_Hefferon/CH1/EX2.1/Ex1_2_1.R
@@ -0,0 +1,20 @@
+#Example 2.1,chapter1,section 1.2,page 13
+#package used matlib v0.9.1
+#install package using command: install.packages("matlib")
+#Github reposiory of matlib :https://github.com/friendly/matlib
+
+#installation and loading library
+#install.packages("matlib")
+library("matlib")
+
+#program
+A <- matrix(c(2,1,3,0,-1,-1,1,-1,0),ncol=3)
+b <- c(3,1,4)
+Ab <- cbind(A,b)
+Ab <- rowadd(Ab,1,2,-0.5)
+Ab <- rowadd(Ab,1,3,-1.5)
+Ab <- rowadd(Ab,2,3,-1)
+Ab
+#from the result we can see that the system doesnot have a unique solution.
+#We can represent the solution set by representing the variables that lead(x,y)by the variable that does not lead(z).
+#so solution set {((3/2)-(1/2)z,(1/2)-(3/2)z,z)|z belongs to R} \ No newline at end of file
diff --git a/Linear_Algebra_by_Jim_Hefferon/CH1/EX2.12/Ex1_2_12.R b/Linear_Algebra_by_Jim_Hefferon/CH1/EX2.12/Ex1_2_12.R
new file mode 100644
index 00000000..5c8f03e6
--- /dev/null
+++ b/Linear_Algebra_by_Jim_Hefferon/CH1/EX2.12/Ex1_2_12.R
@@ -0,0 +1,7 @@
+#Example 2.12,section 1.2,chapter 1,page 18.
+#vector addition
+a <- c(2,3,1)
+b <- c(3,-1,4)
+a+b
+c <- c(1,4,-1,-3)
+7*c \ No newline at end of file
diff --git a/Linear_Algebra_by_Jim_Hefferon/CH1/EX2.3/Ex1_2_3.R b/Linear_Algebra_by_Jim_Hefferon/CH1/EX2.3/Ex1_2_3.R
new file mode 100644
index 00000000..0e15eae5
--- /dev/null
+++ b/Linear_Algebra_by_Jim_Hefferon/CH1/EX2.3/Ex1_2_3.R
@@ -0,0 +1,20 @@
+#Example 2.3,chapter1,section 1.2,page 13
+#package used matlib v0.9.1
+#install package using command: install.packages("matlib")
+#Github reposiory of matlib :https://github.com/friendly/matlib
+
+#installation and loading library
+#install.packages("matlib")
+library("matlib")
+
+#program
+A <- matrix(c(1,0,3,0,1,1,0,-1,1,-1,6,1,-1,1,-6,-1),ncol = 4)
+b <- c(1,-1,6,1)
+Ab <- cbind(A,b)
+Ab <- rowadd(Ab,1,3,-3)
+Ab <- rowadd(Ab,2,3,3)
+Ab <- rowadd(Ab,2,4,1)
+Ab
+#from the reduced augmented matrix Ab,we can see that only x and y are leading,while z and w are free.
+#We represent the solution set by expressing the leading variables in terms of the free variables
+#The solution set: {(2 - 2z + 2w,-1 + z - w,z,w)|z,w belongs to R} \ No newline at end of file
diff --git a/Linear_Algebra_by_Jim_Hefferon/CH1/EX2.5/Ex1_2_5.R b/Linear_Algebra_by_Jim_Hefferon/CH1/EX2.5/Ex1_2_5.R
new file mode 100644
index 00000000..c37e92e8
--- /dev/null
+++ b/Linear_Algebra_by_Jim_Hefferon/CH1/EX2.5/Ex1_2_5.R
@@ -0,0 +1,19 @@
+#Example 2.5,section 1.2,page 15
+#package used matlib v0.9.1
+#install package using command: install.packages("matlib")
+#Github reposiory of matlib :https://github.com/friendly/matlib
+
+#installation and loading library
+#install.packages("matlib")
+library("matlib")
+
+#program
+A <- matrix(c(1,2,3,2,0,2,0,1,1,0,0,-1),ncol = 4)
+b <- c(1,2,4)
+Ab <- cbind(A,b) #augmented matrix
+Ab <- rowadd(Ab,1,2,-2)
+Ab <- rowadd(Ab,1,3,-3)
+Ab <- rowadd(Ab,2,3,-1)
+Ab
+#The leading variables are x, y, and w. The variable z is free.
+#although there are infinitely many solutions, the value of w doesn't vary but is constant w = -1. \ No newline at end of file
diff --git a/Linear_Algebra_by_Jim_Hefferon/CH1/EX2.7/Ex1_2_7.R b/Linear_Algebra_by_Jim_Hefferon/CH1/EX2.7/Ex1_2_7.R
new file mode 100644
index 00000000..cd004d7c
--- /dev/null
+++ b/Linear_Algebra_by_Jim_Hefferon/CH1/EX2.7/Ex1_2_7.R
@@ -0,0 +1,22 @@
+#Example 2.7,chapter one,section 1.2,page 16
+#package used: matlib
+#installation run command : install.packages("matlib")
+#package repo : https://github.com/friendly/matlib
+
+#installing and loading library
+#install.packages("matlib")
+library("matlib")
+
+#program
+A <- matrix(c(1,0,1,2,1,0,0,-1,2),ncol = 3)
+b <- c(4,0,4)
+#creating augmented matrix
+Ab <- cbind(A,b)
+Ab
+#applying reduction techniques
+Ab <- rowadd(Ab,1,3,-1)
+Ab <- rowadd(Ab,2,3,2)
+Ab
+#second row: y-z=0
+#first row: x+2*y=4
+#so solution set is : {(4-2*z = 0)} \ No newline at end of file
diff --git a/Linear_Algebra_by_Jim_Hefferon/CH1/EX3.3/Ex1_3_3.R b/Linear_Algebra_by_Jim_Hefferon/CH1/EX3.3/Ex1_3_3.R
new file mode 100644
index 00000000..a8612292
--- /dev/null
+++ b/Linear_Algebra_by_Jim_Hefferon/CH1/EX3.3/Ex1_3_3.R
@@ -0,0 +1,24 @@
+#Example 3.3,section 1.3,chapter 1,page 24
+#package used matlib v0.9.1
+#install package using command: install.packages("matlib")
+#Github reposiory of matlib :https://github.com/friendly/matlib
+
+#installation and loading library
+#install.packages("matlib")
+library("matlib")
+
+#program
+A <- matrix(c(3,2,4,-1),ncol = 2)
+b <- c(3,1)
+c <- c(0,0)
+Ab <- cbind(A,b) # linear system
+Ac <- cbind(A,c) #system of homogeneous equations
+#reduction of original system
+Ab <- rowadd(Ab,1,2,-2/3)
+#reduction of homogeneous system
+Ac <- rowadd(Ac,1,2,-2/3)
+#comparing both
+Ab
+Ac
+#Obviously the two reductions go in the same way.
+#We can study how to reduce a linear systems by instead studying how to reduce the associated homogeneous system. \ No newline at end of file
diff --git a/Linear_Algebra_by_Jim_Hefferon/CH1/EX3.5/Ex1_3_5.R b/Linear_Algebra_by_Jim_Hefferon/CH1/EX3.5/Ex1_3_5.R
new file mode 100644
index 00000000..c0a2bc07
--- /dev/null
+++ b/Linear_Algebra_by_Jim_Hefferon/CH1/EX3.5/Ex1_3_5.R
@@ -0,0 +1,18 @@
+#Example 3.5,chapter 1,section 1.3,page 25
+#package used matlib v0.9.1
+#install package using command: install.packages("matlib")
+#Github reposiory of matlib :https://github.com/friendly/matlib
+
+#installation and loading library
+#install.packages("matlib")
+library("matlib")
+
+#program
+A <- matrix(c(7,8,0,0,0,1,1,3,-7,-5,-3,-6,0,-2,0,-1),ncol=4)
+b <- c(0,0,0,0)
+Ab <- cbind(A,b)
+Ab <- rowadd(Ab,1,2,-8/7)
+Ab <- rowadd(Ab,2,3,-1)
+Ab <- rowadd(Ab,2,4,-3)
+Ab <- rowadd(Ab,3,4,-5/2)
+Ab \ No newline at end of file