summaryrefslogtreecommitdiff
path: root/Numerical_Methods_by_E_Balaguruswamy/CH7
diff options
context:
space:
mode:
Diffstat (limited to 'Numerical_Methods_by_E_Balaguruswamy/CH7')
-rw-r--r--Numerical_Methods_by_E_Balaguruswamy/CH7/EX7.1/Ex7_1.R12
-rw-r--r--Numerical_Methods_by_E_Balaguruswamy/CH7/EX7.5/Ex7_5.R29
2 files changed, 41 insertions, 0 deletions
diff --git a/Numerical_Methods_by_E_Balaguruswamy/CH7/EX7.1/Ex7_1.R b/Numerical_Methods_by_E_Balaguruswamy/CH7/EX7.1/Ex7_1.R
new file mode 100644
index 00000000..31f25f49
--- /dev/null
+++ b/Numerical_Methods_by_E_Balaguruswamy/CH7/EX7.1/Ex7_1.R
@@ -0,0 +1,12 @@
+# Example 1 Chapter 7 Page no.: 211
+# Solving System of Equations
+
+#Define Sysytem of Equations in Matrix form
+A<-matrix(c(3,2,1,2,3,2,1,2,3),nrow = 3,ncol = 3,byrow = TRUE)
+A
+b<-matrix(c(10,14,14),nrow = 3,ncol = 1)
+b
+
+k <- solve(A,b)
+cat("Solution:\n x=",k[1],"\n y=",k[2],"\n z=",k[3])
+
diff --git a/Numerical_Methods_by_E_Balaguruswamy/CH7/EX7.5/Ex7_5.R b/Numerical_Methods_by_E_Balaguruswamy/CH7/EX7.5/Ex7_5.R
new file mode 100644
index 00000000..58ded1ad
--- /dev/null
+++ b/Numerical_Methods_by_E_Balaguruswamy/CH7/EX7.5/Ex7_5.R
@@ -0,0 +1,29 @@
+# Example 5 Chapter 7 Page no.: 234
+# Dolittle Algorithm
+
+#import 'matrixcalc' library
+install.packages("matrixcalc")
+library(matrixcalc)
+
+#Define system of equations in matrix form
+A<-matrix(c(3,2,1,2,3,2,1,2,3),nrow = 3,ncol = 3,byrow = TRUE)
+A
+B<-matrix(c(10,14,14),nrow = 3,ncol = 1)
+B
+
+#LU Decomposition
+luA<-lu.decomposition(A)
+L<-luA$L
+L
+U<-luA$U
+U
+
+z1<-B[1]
+z2<-B[2]-L[2,1]*z1
+z3<-B[3]-L[3,1]*z1-L[3,2]*z2
+
+#By Back Substitution we get,
+x3=z3/(U[3,3])
+x2=(z2-U[2,3]*x3)/U[2,2]
+x1=(z1-U[1,2]*x2-U[1,3]*x3)/U[1,1]
+sprintf("Values of x1, x2 and x3 are %f,%f and %f",x1,x2,x3)