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 /Numerical_Methods_by_E_Balaguruswamy/CH12 | |
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 'Numerical_Methods_by_E_Balaguruswamy/CH12')
7 files changed, 174 insertions, 0 deletions
diff --git a/Numerical_Methods_by_E_Balaguruswamy/CH12/EX12.10/Ex12_10.R b/Numerical_Methods_by_E_Balaguruswamy/CH12/EX12.10/Ex12_10.R new file mode 100644 index 00000000..30ce157f --- /dev/null +++ b/Numerical_Methods_by_E_Balaguruswamy/CH12/EX12.10/Ex12_10.R @@ -0,0 +1,22 @@ +# Example 10 Chapter 12 Page no.: 400
+#Gauss-Legendre Three point formula
+
+# Installing and attaching 'pracma' library
+install.packages("pracma")
+library("pracma")
+
+#Gauss-Legendre nodes and weights
+f <- function(x) {
+ (x^4)+1
+}
+
+# Given values
+n1 = 3
+a1 = 2
+b1 = 4
+
+cc <- gaussLegendre(n1, a1, b1)
+Q <- sum(cc$w * f(cc$x))
+cat("The Gauss-Legendre Three point integral of (x^4)+1 is", Q)
+
+# The value in the textbook and the calculated value vary slightly due to approximations assumed in textbook.
\ No newline at end of file diff --git a/Numerical_Methods_by_E_Balaguruswamy/CH12/EX12.3/Ex12_3.R b/Numerical_Methods_by_E_Balaguruswamy/CH12/EX12.3/Ex12_3.R new file mode 100644 index 00000000..afc5ab90 --- /dev/null +++ b/Numerical_Methods_by_E_Balaguruswamy/CH12/EX12.3/Ex12_3.R @@ -0,0 +1,39 @@ +# Example 3 Chapter 12 Page no.: 381
+# Simpson's 1/3 Rule
+
+#CASE A
+
+#Given Function
+f <- function(x){
+ exp(x)
+}
+
+a1 <- -1
+b1 <- 1
+h1 <- (b1-a1)/2
+
+Is <- function(a,b,h){
+ return((h/3)*(f(a)+f(b)+4*f((a+b)/2)))
+}
+
+Is1 <- Is(a1,b1,h1)
+cat("The Integrant value of e^x between -1 and 1 is", Is1)
+
+
+#CASE B
+
+#Given function
+ff <- function(x){
+ sqrt(sin(x))
+}
+
+a2 <- 0
+b2 <- pi/2
+h2 <- (b2-a2)/2
+
+Isp <- function(k,l,m){
+ return((m/3)*(ff(k)+ff(l)+4*ff((k+l)/2)))
+}
+
+Is2 <- Isp(a2,b2,h2)
+cat("The Integrant value of sqrt(sin(x)) between 0 and pi/2 is", Is2)
\ No newline at end of file diff --git a/Numerical_Methods_by_E_Balaguruswamy/CH12/EX12.5/Ex12_5.R b/Numerical_Methods_by_E_Balaguruswamy/CH12/EX12.5/Ex12_5.R new file mode 100644 index 00000000..eb7c657d --- /dev/null +++ b/Numerical_Methods_by_E_Balaguruswamy/CH12/EX12.5/Ex12_5.R @@ -0,0 +1,40 @@ +# Example 5 Chapter 12 Page no.: 386
+#Simpson's 3/8 Rule
+
+#CASE A
+#Given Function
+f <- function(x){
+ return((x^3)+1)
+}
+
+a1 <- 1
+b1 <- 2
+h1 <- (b1-a1)/3 #Since there are 4 sampling points the value of n is 3
+
+# Simpson's 3/8 function
+
+Is <- function(a,b,h){
+ return(((3*h)/8)*(f(a)+f(b)+(3*f((a+h)))+(3*f((a+(2*h))))))
+}
+
+Is1 <- Is(a1,b1,h1)
+cat("The Integrant value of (x^3)+1 between 1 and 2 is", Is1)
+
+# CASE B
+# Given Function
+ff <- function(x){
+ return(sqrt(sin(x)))
+}
+
+a2 <- 0
+b2 <- pi/2
+h2 <- (b2-a2)/3 #Since there are 4 sampling points the value of n is 3
+
+# Simpson's 3/8 function
+
+IS <- function(a,b,h){
+ return(((3*h)/8)*(ff(a)+ff(b)+(3*ff((a+h)))+(3*ff((a+(2*h))))))
+}
+
+IS1 <- IS(a2,b2,h2)
+cat("The Integrant value of sqrt(sin(x)) between 0 and pi/2 is", signif(IS1, digits = 6))
\ No newline at end of file diff --git a/Numerical_Methods_by_E_Balaguruswamy/CH12/EX12.6/Ex12_6.R b/Numerical_Methods_by_E_Balaguruswamy/CH12/EX12.6/Ex12_6.R new file mode 100644 index 00000000..c2fa7c5e --- /dev/null +++ b/Numerical_Methods_by_E_Balaguruswamy/CH12/EX12.6/Ex12_6.R @@ -0,0 +1,20 @@ +# Example 6 Chapter 12 Page no.: 387
+#Boole's five point Formula
+
+#Given function
+f <- function(x){
+ sqrt(sin(x))
+}
+
+a1 <- 0
+b1 <- pi/2
+h1 <- (b1-a1)/4 #Since there are 5 sampling points the value of n is 4
+
+# Boole's function
+
+Bl <- function(a,b,h){
+ return(((2*h)/45)*((7*f(a))+(7*f(b))+(32*f(a+h))+(12*f(a+(2*h)))+(32*f(a+(3*h)))))
+}
+
+BL1 <- Bl(a1,b1,h1)
+cat("The Boole integrant value of sqrt(sin(x)) between 0 and pi/2 is", signif(BL1, digits = 6))
\ No newline at end of file diff --git a/Numerical_Methods_by_E_Balaguruswamy/CH12/EX12.7/Ex12_7.R b/Numerical_Methods_by_E_Balaguruswamy/CH12/EX12.7/Ex12_7.R new file mode 100644 index 00000000..45c19d99 --- /dev/null +++ b/Numerical_Methods_by_E_Balaguruswamy/CH12/EX12.7/Ex12_7.R @@ -0,0 +1,16 @@ +# Example 7 Chapter 12 Page no.: 391
+# Romberg Estimation
+
+# Installing and importing 'pracma' library
+install.packages("pracma")
+library("pracma")
+
+#Given function
+f <- function(x){
+ return(1/x)
+}
+
+#Romberg function
+u <- romberg(f,1 ,2)
+
+cat("The value of Romberg integration of 1/x is",u$value,"and relative error is",u$rel.error,"completed in",u$iter,"iterations" )
\ No newline at end of file diff --git a/Numerical_Methods_by_E_Balaguruswamy/CH12/EX12.8/Ex12_8.R b/Numerical_Methods_by_E_Balaguruswamy/CH12/EX12.8/Ex12_8.R new file mode 100644 index 00000000..a7d66c5d --- /dev/null +++ b/Numerical_Methods_by_E_Balaguruswamy/CH12/EX12.8/Ex12_8.R @@ -0,0 +1,17 @@ +# Example 8 Chapter 12 Page no.: 397
+#Gauss-Legendre Two point formula
+
+#Given functions and values
+f <- function(x){
+ exp(x)
+}
+a1 <- -1
+b1 <- 1
+
+#Gauss-Legendre Two point formula
+I <- function(a,b){
+ return(f(a/sqrt(3))+f(b/sqrt(3)))
+}
+
+I1 <- I(a1,b1)
+cat("The Gauss-Legendre two point integral of exp(x) is", signif(I1, digits = 8))
\ No newline at end of file diff --git a/Numerical_Methods_by_E_Balaguruswamy/CH12/EX12.9/Ex12_9.R b/Numerical_Methods_by_E_Balaguruswamy/CH12/EX12.9/Ex12_9.R new file mode 100644 index 00000000..c6d4b401 --- /dev/null +++ b/Numerical_Methods_by_E_Balaguruswamy/CH12/EX12.9/Ex12_9.R @@ -0,0 +1,20 @@ +# Example 9 Chapter 12 Page no.: 398
+#Gaussian Two point formula
+
+# Installing and attaching 'pracma' library
+install.packages("pracma")
+library("pracma")
+
+#Gauss-Legendre nodes and weights
+f <- function(x) {
+ exp(-x/2)
+}
+
+# Given values
+n1 = 2
+a1 =-2
+b1 = 2
+
+cc <- gaussLegendre(n1, a1, b1)
+Q <- sum(cc$w * f(cc$x))
+cat("The Gaussian two point integral of exp(-x/2) is", signif(Q, digits = 9))
\ No newline at end of file |