summaryrefslogtreecommitdiff
path: root/Numerical_Methods_by_E_Balaguruswamy/CH3
diff options
context:
space:
mode:
Diffstat (limited to 'Numerical_Methods_by_E_Balaguruswamy/CH3')
-rw-r--r--Numerical_Methods_by_E_Balaguruswamy/CH3/EX3.1/Ex3_1.R32
-rw-r--r--Numerical_Methods_by_E_Balaguruswamy/CH3/EX3.10/Ex3_10.R12
-rw-r--r--Numerical_Methods_by_E_Balaguruswamy/CH3/EX3.11/Ex3_11.R12
-rw-r--r--Numerical_Methods_by_E_Balaguruswamy/CH3/EX3.12/Ex3_12.R18
-rw-r--r--Numerical_Methods_by_E_Balaguruswamy/CH3/EX3.2/Ex3_2.R6
-rw-r--r--Numerical_Methods_by_E_Balaguruswamy/CH3/EX3.4/Ex3_4.R8
-rw-r--r--Numerical_Methods_by_E_Balaguruswamy/CH3/EX3.6/Ex3_6.R21
-rw-r--r--Numerical_Methods_by_E_Balaguruswamy/CH3/EX3.8/Ex3_8.R12
-rw-r--r--Numerical_Methods_by_E_Balaguruswamy/CH3/EX3.9/Ex3_9.R12
9 files changed, 133 insertions, 0 deletions
diff --git a/Numerical_Methods_by_E_Balaguruswamy/CH3/EX3.1/Ex3_1.R b/Numerical_Methods_by_E_Balaguruswamy/CH3/EX3.1/Ex3_1.R
new file mode 100644
index 00000000..30dba568
--- /dev/null
+++ b/Numerical_Methods_by_E_Balaguruswamy/CH3/EX3.1/Ex3_1.R
@@ -0,0 +1,32 @@
+# Example 1 Chapter 3 Page no.: 45
+# Binary number to Decimal
+
+#Importing 'DescTools' library
+#install.packages("DescTools")
+library(DescTools)
+
+a <- 1101 # Integer part of binary number
+b <- 0.1101 # Decimal part of binary number
+
+# conversion of Decimal part of binary
+f <- function(x){
+ length(gregexpr("[[:digit:]]", as.character(x))[[1]])
+}
+
+k <- f(b) -1
+A <- ((b %% 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 1:(m+1)) {
+ p <- signif(A[i]*d, digits = 10)
+ p1[i] <- p
+ p <- sum(p1, na.rm = TRUE)
+ d <- d*0.5
+}
+
+D <- p + BinToDec(a)
+
+cat(" The Decimal equivalent of 1101.1101 is",D)
diff --git a/Numerical_Methods_by_E_Balaguruswamy/CH3/EX3.10/Ex3_10.R b/Numerical_Methods_by_E_Balaguruswamy/CH3/EX3.10/Ex3_10.R
new file mode 100644
index 00000000..c8973134
--- /dev/null
+++ b/Numerical_Methods_by_E_Balaguruswamy/CH3/EX3.10/Ex3_10.R
@@ -0,0 +1,12 @@
+# Example 10 Chapter 3 Page no.: 52
+# Floating point notation
+
+x <- 0.00596
+y <- 65.7452
+z <- -486.8
+
+cat(x,"is expressed as 0.596*10^(-2)")
+
+cat(y,"is expressed as 0.657452*10^(2)")
+
+cat(z,"is expressed as -0.4868*10^(3)") \ No newline at end of file
diff --git a/Numerical_Methods_by_E_Balaguruswamy/CH3/EX3.11/Ex3_11.R b/Numerical_Methods_by_E_Balaguruswamy/CH3/EX3.11/Ex3_11.R
new file mode 100644
index 00000000..8d21e8a1
--- /dev/null
+++ b/Numerical_Methods_by_E_Balaguruswamy/CH3/EX3.11/Ex3_11.R
@@ -0,0 +1,12 @@
+# Example 11 Chapter 3 Page no.: 53
+# Integer Arithmetics
+
+a <- 25
+b <- 12
+
+cat("Addition :",a,"+",b,"=",a+b)
+cat("Subtraction :",a,"-",b,"=",a-b)
+cat(" :",b,"-",a,"=",b-a)
+cat("Multiplication :",a,"x",b,"=",a*b)
+cat("Division :",a,"/",b,"=",as.integer(a/b))
+cat("Division :",b,"/",a,"=",as.integer(b/a)) \ No newline at end of file
diff --git a/Numerical_Methods_by_E_Balaguruswamy/CH3/EX3.12/Ex3_12.R b/Numerical_Methods_by_E_Balaguruswamy/CH3/EX3.12/Ex3_12.R
new file mode 100644
index 00000000..90b861a7
--- /dev/null
+++ b/Numerical_Methods_by_E_Balaguruswamy/CH3/EX3.12/Ex3_12.R
@@ -0,0 +1,18 @@
+# Example 12 Chapter 3 Page no.: 53
+# Aritmetic rule
+
+cat(" Let a=5,b=7 and c=3")
+
+a=5
+b=7
+c=3
+
+k <- (a+b)/c
+j <- as.integer(a/c)+as.integer(b/c)
+
+if(k != j){
+ cat("(a+b)/c =",k,"\nWhich is not equal to (a/c)+(b/c)=",j)
+ cat(". \nThus, this Arithmetic rule fails.")
+}else{
+ cat("Both the results are same")
+} \ No newline at end of file
diff --git a/Numerical_Methods_by_E_Balaguruswamy/CH3/EX3.2/Ex3_2.R b/Numerical_Methods_by_E_Balaguruswamy/CH3/EX3.2/Ex3_2.R
new file mode 100644
index 00000000..617ac2bc
--- /dev/null
+++ b/Numerical_Methods_by_E_Balaguruswamy/CH3/EX3.2/Ex3_2.R
@@ -0,0 +1,6 @@
+# Example 2 Chapter 3 Page no.: 46
+# COnversion of Hexadecimal number to Decimal number
+
+x<-'12af' #input value
+a<-strtoi(x,16L)
+cat("The Hex number 12AF is",a,"in Decimal system") \ No newline at end of file
diff --git a/Numerical_Methods_by_E_Balaguruswamy/CH3/EX3.4/Ex3_4.R b/Numerical_Methods_by_E_Balaguruswamy/CH3/EX3.4/Ex3_4.R
new file mode 100644
index 00000000..a414df5a
--- /dev/null
+++ b/Numerical_Methods_by_E_Balaguruswamy/CH3/EX3.4/Ex3_4.R
@@ -0,0 +1,8 @@
+# Example 4 Chapter 3 Page no.: 48
+# COnversion of Decimal number to Octal number
+
+x<-163
+a<-as.octmode(x)
+cat("The number 163 is ")
+a
+cat("in Octal system")
diff --git a/Numerical_Methods_by_E_Balaguruswamy/CH3/EX3.6/Ex3_6.R b/Numerical_Methods_by_E_Balaguruswamy/CH3/EX3.6/Ex3_6.R
new file mode 100644
index 00000000..e1dfbb14
--- /dev/null
+++ b/Numerical_Methods_by_E_Balaguruswamy/CH3/EX3.6/Ex3_6.R
@@ -0,0 +1,21 @@
+# Example 6 Chapter 3 Page no.: 49
+# Octal Number to Hexadecimal
+
+
+oct <- 243 # Octal number
+decimalNumber <- 0
+i=0
+
+#Algorithm for Conversion of octal to decimal
+while(oct != 0)
+{
+ decimalNumber = decimalNumber + (oct %% 10)*(8^i)
+ i =i+1
+ oct = as.integer(oct/10)
+}
+
+H <- as.hexmode(decimalNumber[1])
+
+cat("The number 243 in Octal system is")
+H
+cat("in Hexadecimal system.")
diff --git a/Numerical_Methods_by_E_Balaguruswamy/CH3/EX3.8/Ex3_8.R b/Numerical_Methods_by_E_Balaguruswamy/CH3/EX3.8/Ex3_8.R
new file mode 100644
index 00000000..4fdb5091
--- /dev/null
+++ b/Numerical_Methods_by_E_Balaguruswamy/CH3/EX3.8/Ex3_8.R
@@ -0,0 +1,12 @@
+# Example 8 Chapter 3 Page no.: 50
+# COnversion of integer to Binary
+
+
+x <- -13
+
+install.packages("binaryLogic")
+library("binaryLogic")
+
+y <- as.binary(x, size=0.7, n=0, logic=FALSE)
+
+cat("The integer",x,"can be represented as",print(y),"in binary format")
diff --git a/Numerical_Methods_by_E_Balaguruswamy/CH3/EX3.9/Ex3_9.R b/Numerical_Methods_by_E_Balaguruswamy/CH3/EX3.9/Ex3_9.R
new file mode 100644
index 00000000..605a63de
--- /dev/null
+++ b/Numerical_Methods_by_E_Balaguruswamy/CH3/EX3.9/Ex3_9.R
@@ -0,0 +1,12 @@
+# Example 9 Chapter 3 Page no.: 51
+# COnversion of integer to 16 bit Binary
+
+
+x <- -32768
+
+install.packages("binaryLogic")
+library("binaryLogic")
+
+y <- as.binary(x, size=2, n=0, logic=FALSE)
+
+cat("The integer",x,"can be represented as",print(y),"in 16 Bit binary format")