diff options
Diffstat (limited to 'Introduction_To_Linear_Algebra_by_Gilbert_Strang/CH8')
9 files changed, 108 insertions, 0 deletions
diff --git a/Introduction_To_Linear_Algebra_by_Gilbert_Strang/CH8/EX8.1.1/Ex8.1_1.r b/Introduction_To_Linear_Algebra_by_Gilbert_Strang/CH8/EX8.1.1/Ex8.1_1.r new file mode 100644 index 00000000..25d952f3 --- /dev/null +++ b/Introduction_To_Linear_Algebra_by_Gilbert_Strang/CH8/EX8.1.1/Ex8.1_1.r @@ -0,0 +1,14 @@ +# Example : 1 Chapter : 8.1 Page No: 413 +# Find movements , tensions, elongations of spring +K<-matrix(c(2,-1,0,-1,2,-1,0,-1,2),ncol=3) +K1<-solve(K) +f<-c(1,1,1)#since all mi=m +u<-K1%*%f +print("Movements are given by mg/c * u and u is") +print(u) +A<-matrix(c(1,-1,0,0,0,1,-1,0,0,0,1,-1),ncol=3) +e<-A%*%u +print("Elongations are given by mg/c * e and e is") +print(e) +print("Tensions are given by mg * e and e is") +print(e)
\ No newline at end of file diff --git a/Introduction_To_Linear_Algebra_by_Gilbert_Strang/CH8/EX8.1.2/Ex8.1_2.r b/Introduction_To_Linear_Algebra_by_Gilbert_Strang/CH8/EX8.1.2/Ex8.1_2.r new file mode 100644 index 00000000..5a83baa2 --- /dev/null +++ b/Introduction_To_Linear_Algebra_by_Gilbert_Strang/CH8/EX8.1.2/Ex8.1_2.r @@ -0,0 +1,15 @@ +# Example : 2 Chapter : 8.1 Page No: 414 +# Find movements , tensions, elongations of spring +K1<-matrix(c(2,-1,0,-1,2,-1,0,-1,1),ncol=3) +K11<-solve(K1) +f<-c(1,1,1) +u<-K11%*%f +print("Movements are given by mg/c * u and u is") +print(u) +A<-matrix(c(1,-1,0,0,1,-1,0,0,1),ncol=3) +e<-A%*%u +print("Elongations are given by mg/c * e and e is") +print(e) +y<-solve(t(A))%*%f +print("Tensions are given by mg * y and y is") +print(y)
\ No newline at end of file diff --git a/Introduction_To_Linear_Algebra_by_Gilbert_Strang/CH8/EX8.2.1/Ex8.2_1.r b/Introduction_To_Linear_Algebra_by_Gilbert_Strang/CH8/EX8.2.1/Ex8.2_1.r new file mode 100644 index 00000000..d5687138 --- /dev/null +++ b/Introduction_To_Linear_Algebra_by_Gilbert_Strang/CH8/EX8.2.1/Ex8.2_1.r @@ -0,0 +1,15 @@ +# Example : 1 Chapter : 8.2 Page No: 427 +# Find the currents +A<-matrix(c(-1,-1,0,-1,0,0,1,0,-1,0,-1,0,0,1,1,0,0,-1,0,0,0,1,1,1),ncol=4) +AT<-t(A) +Laplacian_matrix<-AT%*%A +Laplacian_matrix<-Laplacian_matrix[-4,-4] +b<-c(1,0,0) +x<-solve(Laplacian_matrix,b) +x<-c(x,0) +print("Voltages are given by S * ") +print(x) +print("S is source") +y<--1*A%*%x +print("Currents are given by S * ") +print(y)
\ No newline at end of file diff --git a/Introduction_To_Linear_Algebra_by_Gilbert_Strang/CH8/EX8.3.1/Ex8.3_1.r b/Introduction_To_Linear_Algebra_by_Gilbert_Strang/CH8/EX8.3.1/Ex8.3_1.r new file mode 100644 index 00000000..08516b62 --- /dev/null +++ b/Introduction_To_Linear_Algebra_by_Gilbert_Strang/CH8/EX8.3.1/Ex8.3_1.r @@ -0,0 +1,8 @@ +# Example : 1 Chapter : 8.3 Page No: 432 +# Positive Markov matrix Application. +A<-matrix(c(0.8,0.2,0.05,0.95),ncol=2) +u0<-c(0.02,0.98) +u1<-A%*%u0 +print(u1) +u2<-A%*%u1 +print(u2)
\ No newline at end of file diff --git a/Introduction_To_Linear_Algebra_by_Gilbert_Strang/CH8/EX8.3.3/Ex8.3_3.r b/Introduction_To_Linear_Algebra_by_Gilbert_Strang/CH8/EX8.3.3/Ex8.3_3.r new file mode 100644 index 00000000..e66f77d2 --- /dev/null +++ b/Introduction_To_Linear_Algebra_by_Gilbert_Strang/CH8/EX8.3.3/Ex8.3_3.r @@ -0,0 +1,11 @@ +# Example : 3 Chapter : 8.3 Page No: 433 +# Markov matrix Application. +A<-matrix(c(0,0.5,0.5,0.5,0,0.5,0.5,0.5,0),ncol=3) +u0<-c(8,16,32) +u1<-A%*%u0 +u2<-A%*%u1 +u3<-A%*%u2 +print("Populations in three groups in subsequent months") +print(u1) +print(u2) +print(u3)
\ No newline at end of file diff --git a/Introduction_To_Linear_Algebra_by_Gilbert_Strang/CH8/EX8.3.4/Ex8.3_4.r b/Introduction_To_Linear_Algebra_by_Gilbert_Strang/CH8/EX8.3.4/Ex8.3_4.r new file mode 100644 index 00000000..f94b4967 --- /dev/null +++ b/Introduction_To_Linear_Algebra_by_Gilbert_Strang/CH8/EX8.3.4/Ex8.3_4.r @@ -0,0 +1,10 @@ +# Example : 4 Chapter : 8.3 Page No: 437 +# Linear Algebra in Economy +A<-matrix(c(0.2,0.4,0.5,0.3,0.4,0.1,0.4,0.1,0.3),ncol=3) +lambda<-eigen(A)$values +print("Lambda max is ") +print(lambda[1]) +I<-matrix(c(1,0,0,0,1,0,0,0,1),ncol=3) +A1<-solve(I-A) +print(A1) +#The answers may vary due to rounding off values diff --git a/Introduction_To_Linear_Algebra_by_Gilbert_Strang/CH8/EX8.3.5/Ex8.3_5.r b/Introduction_To_Linear_Algebra_by_Gilbert_Strang/CH8/EX8.3.5/Ex8.3_5.r new file mode 100644 index 00000000..1858f801 --- /dev/null +++ b/Introduction_To_Linear_Algebra_by_Gilbert_Strang/CH8/EX8.3.5/Ex8.3_5.r @@ -0,0 +1,10 @@ +# Example : 5 Chapter : 8.3 Page No: 437 +# Linear Algebra in Economy +A<-matrix(c(0,1,4,0),ncol=2) +lambda<-eigen(A)$values +print("Lambda max is ") +print(lambda[1]) +I<-matrix(c(1,0,0,1),ncol=2) +A1<-solve(I-A) +print(A1) +#The answers may vary due to rounding off values diff --git a/Introduction_To_Linear_Algebra_by_Gilbert_Strang/CH8/EX8.5.2/Ex8.5_2.r b/Introduction_To_Linear_Algebra_by_Gilbert_Strang/CH8/EX8.5.2/Ex8.5_2.r new file mode 100644 index 00000000..634de0d9 --- /dev/null +++ b/Introduction_To_Linear_Algebra_by_Gilbert_Strang/CH8/EX8.5.2/Ex8.5_2.r @@ -0,0 +1,19 @@ +#integrate is a function from package stats which is included in R by default
+#if not install package stats
+# Example : 2 Chapter : 8.5 Page No: 448
+# length of function sinx and sinx and cosx are orthogonal in function space
+f1<-function(x){
+ return (sin(x)*sin(x))
+}
+f2<-function(x){
+ return (sin(x)*cos(x))
+}
+print("Inner product of sinx and sinx is ")
+lsin2x<-integrate(f1,0,2*pi)
+print(lsin2x)
+print("Length of sinx is square root of above inner product")
+print(sqrt(lsin2x$value))
+print("Cos x and sinx are orthogonal in functional space because their inner product equals zero")
+lsinxcosx<-integrate(f2,0,2*pi)
+print(lsinxcosx)
+#The answer may slightly vary due to rounding off values
\ No newline at end of file diff --git a/Introduction_To_Linear_Algebra_by_Gilbert_Strang/CH8/EX8.6.2/Ex8.6_6.r b/Introduction_To_Linear_Algebra_by_Gilbert_Strang/CH8/EX8.6.2/Ex8.6_6.r new file mode 100644 index 00000000..91c1dffb --- /dev/null +++ b/Introduction_To_Linear_Algebra_by_Gilbert_Strang/CH8/EX8.6.2/Ex8.6_6.r @@ -0,0 +1,6 @@ +# Example : 6 Chapter : 8.6 Page No: 457 +# Singualar Value Decomposition +gradematrixA<-matrix(c(-6,0,4,2,2,4,0,-6,0,-6,2,4,4,2,-6,0),ncol=4) +print("SVD of Grade matrix is") +print(svd(gradematrixA)) +#The answers may vary due to rounding off values
\ No newline at end of file |