diff options
author | Prashant S | 2019-10-04 12:27:32 +0530 |
---|---|---|
committer | GitHub | 2019-10-04 12:27:32 +0530 |
commit | ac2986488a9731cff5cbb517d8f0ef98e2561d64 (patch) | |
tree | 7bb3f64824627ef179d5f341266a664fd0b69011 /Introduction_To_Linear_Algebra_by_Gilbert_Strang/CH5 | |
parent | cbb2770fb2f88246175add29623103a56ba338b8 (diff) | |
parent | b3f3a8ecd454359a2e992161844f2fb599f8238a (diff) | |
download | R_TBC_Uploads-master.tar.gz R_TBC_Uploads-master.tar.bz2 R_TBC_Uploads-master.zip |
Added R TBC
Diffstat (limited to 'Introduction_To_Linear_Algebra_by_Gilbert_Strang/CH5')
10 files changed, 157 insertions, 0 deletions
diff --git a/Introduction_To_Linear_Algebra_by_Gilbert_Strang/CH5/EX5.2.1/Ex5.2_1.r b/Introduction_To_Linear_Algebra_by_Gilbert_Strang/CH5/EX5.2.1/Ex5.2_1.r new file mode 100644 index 00000000..92f5d7c0 --- /dev/null +++ b/Introduction_To_Linear_Algebra_by_Gilbert_Strang/CH5/EX5.2.1/Ex5.2_1.r @@ -0,0 +1,10 @@ +# Example : 1 Chapter : 5.2 Page No: 255
+# Determinant of matrices by multiplying pivots
+A<-matrix(c(0,0,4,0,2,5,1,3,6),ncol=3)
+P<-matrix(c(0,0,1,0,1,0,1,0,0),ncol=3)
+PA<-P%*%A
+print(PA)
+detA<--1*PA[1,1]*PA[2,2]*PA[3,3]
+print(detA)
+det(A)
+print("detA is the determinant of the given matrix")
\ No newline at end of file diff --git a/Introduction_To_Linear_Algebra_by_Gilbert_Strang/CH5/EX5.2.5/Ex5.2_5.r b/Introduction_To_Linear_Algebra_by_Gilbert_Strang/CH5/EX5.2.5/Ex5.2_5.r new file mode 100644 index 00000000..f86ef826 --- /dev/null +++ b/Introduction_To_Linear_Algebra_by_Gilbert_Strang/CH5/EX5.2.5/Ex5.2_5.r @@ -0,0 +1,6 @@ +# Example : 5 Chapter : 5.2 Page No: 259
+# Determinants of matrices
+A4<-matrix(c(0,1,0,0,1,0,1,0,0,1,0,1,0,0,1,0),ncol=4)
+P4<-matrix(c(0,1,0,0,1,0,0,0,0,0,0,1,0,0,1,0),ncol=4)
+print(det(A4))
+print(det(P4))
diff --git a/Introduction_To_Linear_Algebra_by_Gilbert_Strang/CH5/EX5.2.7/Ex5.2_7.r b/Introduction_To_Linear_Algebra_by_Gilbert_Strang/CH5/EX5.2.7/Ex5.2_7.r new file mode 100644 index 00000000..f1556c83 --- /dev/null +++ b/Introduction_To_Linear_Algebra_by_Gilbert_Strang/CH5/EX5.2.7/Ex5.2_7.r @@ -0,0 +1,4 @@ +# Example : 7 Chapter : 5.2 Page No: 261
+# Determinants of matrices
+B4<-matrix(c(1,-1,0,0,-1,2,-1,0,0,-1,2,-1,0,0,-1,2),ncol=4)
+print(det(B4))
\ No newline at end of file diff --git a/Introduction_To_Linear_Algebra_by_Gilbert_Strang/CH5/EX5.3.1/Ex5.3_1.r b/Introduction_To_Linear_Algebra_by_Gilbert_Strang/CH5/EX5.3.1/Ex5.3_1.r new file mode 100644 index 00000000..1e6818aa --- /dev/null +++ b/Introduction_To_Linear_Algebra_by_Gilbert_Strang/CH5/EX5.3.1/Ex5.3_1.r @@ -0,0 +1,13 @@ +# Example : 1 Chapter : 5.3 Page No: 269
+# Cramers rule for solving system of equations
+A<-matrix(c(3,5,4,6),ncol=2)
+b<-c(2,4)
+B1<-A
+B1[,1]<-b
+B2<-A
+B2[,2]<-b
+x1<-det(B1)/det(A)
+x2<-det(B2)/det(A)
+print("SOlution is ")
+print(x1)
+print(x2)
diff --git a/Introduction_To_Linear_Algebra_by_Gilbert_Strang/CH5/EX5.3.3/Ex5.3_3.r b/Introduction_To_Linear_Algebra_by_Gilbert_Strang/CH5/EX5.3.3/Ex5.3_3.r new file mode 100644 index 00000000..546b936b --- /dev/null +++ b/Introduction_To_Linear_Algebra_by_Gilbert_Strang/CH5/EX5.3.3/Ex5.3_3.r @@ -0,0 +1,6 @@ +# Example : 3 Chapter : 5.3 Page No: 271
+# The inverse of the traingular matrix is traingular
+A<-matrix(c(1,1,1,1,0,1,1,1,0,0,1,1,0,0,0,1),ncol=4)
+A1<-solve(A)
+print("The inverse of A is")
+print(A1)
\ No newline at end of file diff --git a/Introduction_To_Linear_Algebra_by_Gilbert_Strang/CH5/EX5.3.7/Ex5.3_7.r b/Introduction_To_Linear_Algebra_by_Gilbert_Strang/CH5/EX5.3.7/Ex5.3_7.r new file mode 100644 index 00000000..cccd7f3a --- /dev/null +++ b/Introduction_To_Linear_Algebra_by_Gilbert_Strang/CH5/EX5.3.7/Ex5.3_7.r @@ -0,0 +1,14 @@ +# Packages used : pracma
+# To install pracma,type following in command line while connected to internet
+# install.packages("pracma")
+# package can be included by command " library(pracma) "
+# for more information about pracma visit https://cran.r-project.org/web/packages/pracma/index.html
+
+# Example : 7 Chapter : 5.3 Page No: 275
+# CrossProduct of Vectors
+library(pracma)
+u<-c(3,2,0)
+v<-c(1,4,0)
+cp<-cross(u,v)
+print("u * v is ")
+print(cp)
diff --git a/Introduction_To_Linear_Algebra_by_Gilbert_Strang/CH5/EX5.3.8/Ex5.3_8.r b/Introduction_To_Linear_Algebra_by_Gilbert_Strang/CH5/EX5.3.8/Ex5.3_8.r new file mode 100644 index 00000000..aa1cf744 --- /dev/null +++ b/Introduction_To_Linear_Algebra_by_Gilbert_Strang/CH5/EX5.3.8/Ex5.3_8.r @@ -0,0 +1,15 @@ +# Packages used : pracma
+# To install pracma,type following in command line while connected to internet
+# install.packages("pracma")
+# package can be included by command " library(pracma) "
+# for more information about pracma visit https://cran.r-project.org/web/packages/pracma/index.html
+
+# Example : 8 Chapter : 5.3 Page No: 276
+# CrossProduct of Vectors
+
+library(pracma)
+u<-c(1,1,1)
+v<-c(1,1,2)
+cp<-cross(u,v)
+print("u * v is ")
+print(cp)
diff --git a/Introduction_To_Linear_Algebra_by_Gilbert_Strang/CH5/EX5.3.9/Ex5.3_9.r b/Introduction_To_Linear_Algebra_by_Gilbert_Strang/CH5/EX5.3.9/Ex5.3_9.r new file mode 100644 index 00000000..c8b42029 --- /dev/null +++ b/Introduction_To_Linear_Algebra_by_Gilbert_Strang/CH5/EX5.3.9/Ex5.3_9.r @@ -0,0 +1,15 @@ +# Packages used : pracma
+# To install pracma,type following in command line while connected to internet
+# install.packages("pracma")
+# package can be included by command " library(pracma) "
+# for more information about pracma visit https://cran.r-project.org/web/packages/pracma/index.html
+
+# Example : 9 Chapter : 5.3 Page No: 276
+# The right hand rule - cross product of x-axis and y-axis is z-axis
+
+library(pracma)
+u<-c(1,0,0)
+v<-c(0,1,0)
+cp<-cross(u,v)
+print("u * v is ")
+print(cp)
\ No newline at end of file diff --git a/Introduction_To_Linear_Algebra_by_Gilbert_Strang/CH5/EX5.3.a/Ex5_5.3A.r b/Introduction_To_Linear_Algebra_by_Gilbert_Strang/CH5/EX5.3.a/Ex5_5.3A.r new file mode 100644 index 00000000..ac70393c --- /dev/null +++ b/Introduction_To_Linear_Algebra_by_Gilbert_Strang/CH5/EX5.3.a/Ex5_5.3A.r @@ -0,0 +1,28 @@ +# Example : 5.3A Chapter : 5.3 Page No: 277
+# Nullspace of matrix as transpose of Cofactor matrix
+nullspacebasis<-function(A){
+ C<-matrix(c(1:9),ncol=3)
+ for(i in 1:3){
+ for(j in 1:3){
+ if((i+j)%%2==0){
+ x<-1
+ }
+ else{
+ x<--1
+ }
+ C[i,j]<-x*det(A[-i,-j])
+ }
+ }
+ C<-t(C)
+ return(C)
+}
+
+A1<-matrix(c(1,2,2,4,3,2,7,9,8),ncol=3)
+N1<-nullspacebasis(A1)
+print("The null space basis are given by columns of transpose of cofactor matrix")
+print("Null space of A1 is")
+print(N1)
+A2<-matrix(c(1,1,1,1,1,1,2,1,1),ncol=3)
+N2<-nullspacebasis(A2)
+print("Null space of A2 is ")
+print(N2)
\ No newline at end of file diff --git a/Introduction_To_Linear_Algebra_by_Gilbert_Strang/CH5/EX5.3.b/Ex5_5.3B.r b/Introduction_To_Linear_Algebra_by_Gilbert_Strang/CH5/EX5.3.b/Ex5_5.3B.r new file mode 100644 index 00000000..2dfb1feb --- /dev/null +++ b/Introduction_To_Linear_Algebra_by_Gilbert_Strang/CH5/EX5.3.b/Ex5_5.3B.r @@ -0,0 +1,46 @@ +# Example : 5.3B Chapter : 5.3 Page No: 278
+# Solve by crammers rule and inverse of the matrix
+
+solve_by_crammersrule<-function(A,b){
+ B1<-A
+ B2<-A
+ B3<-A
+ B1[,1]<-b
+ B2[,2]<-b
+ B3[,3]<-b
+ x1<-det(B1)/det(A)
+ x2<-det(B2)/det(A)
+ x3<-det(B3)/det(A)
+ x<-c(x1,x2,x3)
+ return(x)
+}
+inverse<-function(A){
+ C<-matrix(c(1:9),ncol=3)
+ for(i in 1:3){
+ for(j in 1:3){
+ if((i+j)%%2==0){
+ x<-1
+ }
+ else{
+ x<--1
+ }
+ C[i,j]<-x*det(A[-i,-j])
+ }
+ }
+ CT<-t(C)
+ A1<-(1/det(A))*CT
+ return(A1)
+}
+
+A<-matrix(c(2,1,5,6,4,9,2,2,0),ncol=3)
+b<-c(0,0,1)
+x<-solve_by_crammersrule(A,b)
+print("x is ")
+print(x)
+A1<-inverse(A)
+print("Inverse of A is ")
+print(A1)
+print("A * inverse of A is Identity matrix")
+I<-A%*%A1
+print(I)
+#The answer may slightly vary due to rounding off values
\ No newline at end of file |