summaryrefslogtreecommitdiff
path: root/Numerical_Methods_by_E_Balaguruswamy/CH4
diff options
context:
space:
mode:
Diffstat (limited to 'Numerical_Methods_by_E_Balaguruswamy/CH4')
-rw-r--r--Numerical_Methods_by_E_Balaguruswamy/CH4/EX4.10/Ex4_10.R35
-rw-r--r--Numerical_Methods_by_E_Balaguruswamy/CH4/EX4.3/Ex4_3.R29
-rw-r--r--Numerical_Methods_by_E_Balaguruswamy/CH4/EX4.4/Ex4_4.R17
-rw-r--r--Numerical_Methods_by_E_Balaguruswamy/CH4/EX4.5/Ex4_5.R31
-rw-r--r--Numerical_Methods_by_E_Balaguruswamy/CH4/EX4.6/Ex4_6.R31
-rw-r--r--Numerical_Methods_by_E_Balaguruswamy/CH4/EX4.7/Ex4_7.R33
-rw-r--r--Numerical_Methods_by_E_Balaguruswamy/CH4/EX4.9/Ex4_9.R28
7 files changed, 204 insertions, 0 deletions
diff --git a/Numerical_Methods_by_E_Balaguruswamy/CH4/EX4.10/Ex4_10.R b/Numerical_Methods_by_E_Balaguruswamy/CH4/EX4.10/Ex4_10.R
new file mode 100644
index 00000000..b2d8c768
--- /dev/null
+++ b/Numerical_Methods_by_E_Balaguruswamy/CH4/EX4.10/Ex4_10.R
@@ -0,0 +1,35 @@
+# Example 10 Chapter 4 Page no.: 77
+# Error propagation
+
+# Given Values
+x <- 2.35
+y <- 6.74
+z <- 3.45
+
+#Given Arithmetic operation
+w <- x*y +z
+
+#Roundoff error in x,y &z
+erx <- 5E-3
+ery <- 5E-3
+erz <- 5E-3
+
+cat("Roundoff error in x,y &z is",erx,",",ery,"&",erz)
+
+#Error in x,y&z
+
+ex <- x*erx
+ey <- y*ery
+ez <- z*erz
+cat("Error in x=",ex)
+cat("Error in y=",ey)
+cat("Error in z=",ez)
+
+# Error in x*y
+exy <- x*ey + y*ex
+cat("Absolute Error in x*y=",exy)
+
+# Absolute error in computing w
+ew <- exy + ez
+cat("Absolute error in computing w=",ew)
+
diff --git a/Numerical_Methods_by_E_Balaguruswamy/CH4/EX4.3/Ex4_3.R b/Numerical_Methods_by_E_Balaguruswamy/CH4/EX4.3/Ex4_3.R
new file mode 100644
index 00000000..328cea79
--- /dev/null
+++ b/Numerical_Methods_by_E_Balaguruswamy/CH4/EX4.3/Ex4_3.R
@@ -0,0 +1,29 @@
+# Example 3 Chapter 4 Page no.: 64
+# Error in Conversion
+
+# Given Binary values
+x0.1 <- 0.00011001
+x0.4 <- 0.01100110
+
+#length of number
+f <- function(x){
+ length(gregexpr("[[:digit:]]", as.character(x))[[1]])
+}
+
+S <- x0.4 + x0.1
+k <- f(S) -1
+A <- ((S %% 1)*(10^k))
+# Converting into vector
+A <- as.numeric(strsplit(as.character(A), "")[[1]])
+m <- length(A)
+d <- 0.5
+p1 <- c()
+for (i in (m+1):1) {
+ p <- signif(A[i]*d, digits = 10)
+ p1[i] <- p
+ p <- sum(p1, na.rm = TRUE)
+ d <- d*0.5
+}
+cat("The decimal obtained when summing the binary is:",p)
+cat("But the true value is 0.5 when 0.4 and 0.1 are added together.")
+cat("Error:",0.5-p) \ No newline at end of file
diff --git a/Numerical_Methods_by_E_Balaguruswamy/CH4/EX4.4/Ex4_4.R b/Numerical_Methods_by_E_Balaguruswamy/CH4/EX4.4/Ex4_4.R
new file mode 100644
index 00000000..9da6415f
--- /dev/null
+++ b/Numerical_Methods_by_E_Balaguruswamy/CH4/EX4.4/Ex4_4.R
@@ -0,0 +1,17 @@
+# Example 4 Chapter 4 Page no.: 66
+# Roundoff error
+
+x <- 752.6835 #Given value
+
+tx1 <- 0.7526*(10^3) #using 4 mantissa to store value
+tx2 <- 0.835*(10^-1) #using 4 mantissa to store value
+
+Tx <- tx1+tx2 # True value
+
+cat("CHOPPING METHOD")
+cat("Approximate x=",tx1,"\n Error=",tx2)
+
+cat("Symmetric Rounding")
+cat("Error = (g(x)-1)*(10^-1) \n"," =",(tx2*10 -1)*10^-1)
+
+cat("Approximate x=0.7527*(10^3)") \ No newline at end of file
diff --git a/Numerical_Methods_by_E_Balaguruswamy/CH4/EX4.5/Ex4_5.R b/Numerical_Methods_by_E_Balaguruswamy/CH4/EX4.5/Ex4_5.R
new file mode 100644
index 00000000..ef801a79
--- /dev/null
+++ b/Numerical_Methods_by_E_Balaguruswamy/CH4/EX4.5/Ex4_5.R
@@ -0,0 +1,31 @@
+# Example 5 Chapter 4 Page no.: 68
+# Truncation error
+
+install.packages("pracma")
+library("pracma")
+
+x <- 1/5
+
+# Numerical Error function
+e <- function(x,n){
+ E <- 0
+ for (i in n:6) {
+ E <- E + (x^i)/fact(i)
+ }
+ return(E)
+}
+cat(" CASE A:")
+n1 <-3
+cat("When first 3 terms are added n=",n1)
+cat("Truncation error =", e(x,n1))
+
+cat(" CASE B:")
+n2 <-4
+cat("When first",n2,"terms are added, n=",n2)
+cat("Truncation error =", e(x,n2))
+
+cat(" CASE C:")
+n3 <-5
+cat("When first",n3,"terms are added n=",n3)
+cat("Truncation error =", e(x,n3))
+
diff --git a/Numerical_Methods_by_E_Balaguruswamy/CH4/EX4.6/Ex4_6.R b/Numerical_Methods_by_E_Balaguruswamy/CH4/EX4.6/Ex4_6.R
new file mode 100644
index 00000000..0cd4e14e
--- /dev/null
+++ b/Numerical_Methods_by_E_Balaguruswamy/CH4/EX4.6/Ex4_6.R
@@ -0,0 +1,31 @@
+# Example 6 Chapter 4 Page no.: 68
+# Truncation error
+
+install.packages("pracma")
+library("pracma")
+
+x <- -(1/5)
+
+# Numerical Error function
+e <- function(x,n){
+ E <- 0
+ for (i in n:6) {
+ E <- E + (x^i)/fact(i)
+ }
+ return(E)
+}
+cat(" CASE A:")
+n1 <-3
+cat("When first 3 terms are added n=",n1)
+cat("Truncation error =", e(x,n1))
+
+cat(" CASE B:")
+n2 <-4
+cat("When first",n2,"terms are added, n=",n2)
+cat("Truncation error =", e(x,n2))
+
+cat(" CASE C:")
+n3 <-5
+cat("When first",n3,"terms are added n=",n3)
+cat("Truncation error =", e(x,n3))
+
diff --git a/Numerical_Methods_by_E_Balaguruswamy/CH4/EX4.7/Ex4_7.R b/Numerical_Methods_by_E_Balaguruswamy/CH4/EX4.7/Ex4_7.R
new file mode 100644
index 00000000..949c7046
--- /dev/null
+++ b/Numerical_Methods_by_E_Balaguruswamy/CH4/EX4.7/Ex4_7.R
@@ -0,0 +1,33 @@
+# Example 7 Chapter 4 Page no.: 71
+# Absolute and Relative Error
+
+# Height of building as measured
+H1 <- 2950
+cat("Height of building as measured by Civil engineer =",H1,"cm.")
+
+#True Height of Building
+H2 <- 2945
+cat("True Height of Building=",H2,"cm.")
+
+# Height of each beam as measured
+B1 <- 35
+cat("Height of each beam as measured by Civil engineer=",B1,"cm.")
+
+# True Height of beam
+B2 <- 30
+cat("True Height of beam",B2,"cm.")
+
+#Absolute error in measuring building height
+e1 <- H1-H2
+cat("Absolute error in measuring building height=",e1,"cm")
+
+#Relative error
+er1 <- signif((e1/H2)*100, digits = 2)
+cat("Relative error in measuring building height",er1,"%")
+
+#Absolute error in measuring Beam height
+e2 <- B1-B2
+cat("Absolute error in measuring Beam height=",e2,"cm")
+#Relative error
+er2 <- signif((e2/B2)*100, digits = 2)
+cat("Relative error in measuring Beam height",er2,"%")
diff --git a/Numerical_Methods_by_E_Balaguruswamy/CH4/EX4.9/Ex4_9.R b/Numerical_Methods_by_E_Balaguruswamy/CH4/EX4.9/Ex4_9.R
new file mode 100644
index 00000000..dcc46913
--- /dev/null
+++ b/Numerical_Methods_by_E_Balaguruswamy/CH4/EX4.9/Ex4_9.R
@@ -0,0 +1,28 @@
+# Example 9 Chapter 4 Page no.: 75
+# Error propagation
+
+# Given Values
+x <- 0.1234E4
+y <- 0.1232E4
+
+#Given Arithmetic operation
+z <- x-y
+
+#Roundoff error in x & y
+erx <- 0.5E-3
+ery <- 0.5E-3
+cat("Roundoff error in x & y is",erx,"&",ery)
+#Absolute Error in x & y
+ex <- x*erx
+ey <- y*ery
+cat("Absolute Error in x=",ex)
+cat("Absolute Error in y=",ey)
+
+# Absolute error in computing z
+ez <- ex+ey
+cat("Absolute error in computing z=",ez)
+
+
+#Relative Error in computing z
+Erz <- (ez/z)*100
+cat("Relative Error in computing z is",Erz,"%.")