summaryrefslogtreecommitdiff
path: root/Numerical_Methods_by_E_Balaguruswamy/CH13
diff options
context:
space:
mode:
authorPrashant S2019-10-04 12:27:32 +0530
committerGitHub2019-10-04 12:27:32 +0530
commitac2986488a9731cff5cbb517d8f0ef98e2561d64 (patch)
tree7bb3f64824627ef179d5f341266a664fd0b69011 /Numerical_Methods_by_E_Balaguruswamy/CH13
parentcbb2770fb2f88246175add29623103a56ba338b8 (diff)
parentb3f3a8ecd454359a2e992161844f2fb599f8238a (diff)
downloadR_TBC_Uploads-master.tar.gz
R_TBC_Uploads-master.tar.bz2
R_TBC_Uploads-master.zip
Merge pull request #1 from prashantsinalkar/masterHEADmaster
Added R TBC
Diffstat (limited to 'Numerical_Methods_by_E_Balaguruswamy/CH13')
-rw-r--r--Numerical_Methods_by_E_Balaguruswamy/CH13/EX13.10/Ex13_10.R53
-rw-r--r--Numerical_Methods_by_E_Balaguruswamy/CH13/EX13.4/Ex13_4.R40
-rw-r--r--Numerical_Methods_by_E_Balaguruswamy/CH13/EX13.6/Ex13_6.R43
-rw-r--r--Numerical_Methods_by_E_Balaguruswamy/CH13/EX13.7/Ex13_7.R21
-rw-r--r--Numerical_Methods_by_E_Balaguruswamy/CH13/EX13.8/Ex13_8.R30
5 files changed, 187 insertions, 0 deletions
diff --git a/Numerical_Methods_by_E_Balaguruswamy/CH13/EX13.10/Ex13_10.R b/Numerical_Methods_by_E_Balaguruswamy/CH13/EX13.10/Ex13_10.R
new file mode 100644
index 00000000..320eae02
--- /dev/null
+++ b/Numerical_Methods_by_E_Balaguruswamy/CH13/EX13.10/Ex13_10.R
@@ -0,0 +1,53 @@
+# Example 10 Chapter 13 Page no.: 446
+# Milne-Simpson predictor-corrector method
+
+#for the solution
+cat(" Milne and Simpson method")
+h <- 0.25
+y <- c()
+x <- c()
+x[1] = 1
+y[1] = 2
+
+cat("h=",h)
+cat("x=",x)
+cat("y=",y)
+
+f <- function(x,y){
+ 2 * y / x
+}
+
+#Creating algorithm and displaying
+for (i in 2:10) {
+
+ print(signif(y[i-1],3))
+ m1 <- f(x[i-1],y[i-1])
+ m2 <- f(x[i-1] + 0.5*h, y[i-1] + 0.5*h*m1)
+ m3 <- f(x[i-1] + 0.5*h, y[i-1] + 0.5*h*m2)
+ m4 <- f(x[i-1] + h, y[i-1] + h*m3)
+ x[i] <- x[i-1] + h
+ y[i] <- y[i-1] + h * (m1 + m4 + 2*m2 + 2*m3) / 6
+
+
+}
+
+g <- c()
+
+for (i in 1:3) {
+ g[i] <- f(x[i+1],y[i+1])
+ print(g[i])
+
+}
+
+#Milne's formula
+Y1 <- y[1] + 4*h * (2*g[1] - g[2] + 2*g[3]) /3
+cat("Solution obtained using Milne's method is", Y1,3)
+
+g[4] <- f(x[5],Y1)
+print(g[4])
+
+#Simpson formula
+Y2 <- y[3] + h * ( g[2] + 4*g[3] + g[4]) /3
+cat("Solution obtained using Simpson's method is", Y2,3)
+
+#Values are not approximated here ao value slightly differs from the textbook value \ No newline at end of file
diff --git a/Numerical_Methods_by_E_Balaguruswamy/CH13/EX13.4/Ex13_4.R b/Numerical_Methods_by_E_Balaguruswamy/CH13/EX13.4/Ex13_4.R
new file mode 100644
index 00000000..22d907da
--- /dev/null
+++ b/Numerical_Methods_by_E_Balaguruswamy/CH13/EX13.4/Ex13_4.R
@@ -0,0 +1,40 @@
+# Example 4 Chapter 13 Page no.: 420
+# Euler Method
+
+#for the first solution
+cat("Case A:")
+h <- 0.5
+x <- 1
+y <- 2
+cat("h=",h)
+#Creating algorithm and displaying
+for (i in 1:2) {
+
+ dy <- (3 * (x *x)) + 1
+ y <- y + (h * dy)
+ x <- x + h
+ cat("y(",x,")= ",y,"\n")
+}
+
+#for the second solution
+cat("Case B:")
+h <- 0.25
+x <- 1
+y <- 2
+cat("h=",h)
+
+print(x)
+print(y)
+
+#Creating algorithm and displaying
+for (i in 1:5) {
+
+ cat("y(",x,")= ",y,"\n")
+ x <- x + h
+ dy <- (3 * ((x-h)^2)) + 1
+ y <- y + (h * dy)
+
+
+}
+
+#For Case B, textbook answer is false. \ No newline at end of file
diff --git a/Numerical_Methods_by_E_Balaguruswamy/CH13/EX13.6/Ex13_6.R b/Numerical_Methods_by_E_Balaguruswamy/CH13/EX13.6/Ex13_6.R
new file mode 100644
index 00000000..63140ef0
--- /dev/null
+++ b/Numerical_Methods_by_E_Balaguruswamy/CH13/EX13.6/Ex13_6.R
@@ -0,0 +1,43 @@
+# Example 6 Chapter 13 Page no.: 427
+# Heun Method and Euler Method
+
+#for the solution - Euler method
+cat("Case A: Euler's Method")
+h <- 0.25
+x <- 1
+y <- 2
+cat("h=",h)
+cat("x=",x)
+cat("y=",y)
+
+#Creating euler algorithm and displaying
+for (i in 1:5) {
+
+ cat("y(",x,")= ",y,"\n")
+ x <- x + h
+ f <- (2 * y / (x-h))
+ y <- y + (h * f)
+
+}
+
+#for the solution - Heun's method
+cat("Case B: Heun's Method")
+h <- 0.25
+x <- 1
+y <- 2
+cat("h=",h)
+
+#Creating heun algorithm and displaying
+for (i in 1:4) {
+
+
+ f1 <- (2 * y / (x))
+ m <- y + h*f1
+ f2 <- (2 * m / (x+h))
+ y <- y + ((h/2) * (f1 + f2))
+ x <- x + h
+ cat("y(",x,")= ",y,"\n")
+
+}
+
+#Values slightly differ but are more precise than what is given in the textbook \ No newline at end of file
diff --git a/Numerical_Methods_by_E_Balaguruswamy/CH13/EX13.7/Ex13_7.R b/Numerical_Methods_by_E_Balaguruswamy/CH13/EX13.7/Ex13_7.R
new file mode 100644
index 00000000..f5a9d53e
--- /dev/null
+++ b/Numerical_Methods_by_E_Balaguruswamy/CH13/EX13.7/Ex13_7.R
@@ -0,0 +1,21 @@
+# Example 7 Chapter 13 Page no.: 433
+# Polygon Method
+
+#for the solution
+cat("Polygon Method")
+h <- 0.25
+x = 1
+y = 2
+cat("h=",h)
+cat("x=",x)
+cat("y=",y)
+
+#Creating algorithm and displaying
+for (i in 1:3) {
+
+ cat("y(",x,")= ",signif(y,3),"\n")
+ f1 <- (2 * y / x)
+ f2 <- (2 * (y + ( h * f1 / 2 ) ) / (x + ( h / 2 ) ))
+ x <- x + h
+ y <- y + (h * f2)
+}
diff --git a/Numerical_Methods_by_E_Balaguruswamy/CH13/EX13.8/Ex13_8.R b/Numerical_Methods_by_E_Balaguruswamy/CH13/EX13.8/Ex13_8.R
new file mode 100644
index 00000000..40f50985
--- /dev/null
+++ b/Numerical_Methods_by_E_Balaguruswamy/CH13/EX13.8/Ex13_8.R
@@ -0,0 +1,30 @@
+# Example 8 Chapter 13 Page no.: 439
+# Classic Runge Kutta Method
+
+#for the solution
+cat("Classic Runge Kutta Method")
+h <- 0.2
+x = 0
+y = 0
+
+cat("h=",h)
+cat("x=",x)
+cat("y=",y)
+
+#Given Function
+f <- function(x,y){
+ x^2 + y^2
+}
+
+#Creating algorithm and displaying
+for (i in 1:2) {
+
+ m1 <- f(x,y)
+ m2 <- f(x + 0.5*h, y + 0.5*h*m1)
+ m3 <- f(x + 0.5*h, y + 0.5*h*m2)
+ m4 <- f(x + h, y + h*m3)
+ x <- x + h
+ y <- y + h * (m1 + m4 + 2*m2 + 2*m3) / 6
+ cat("y(",x,")= ", signif(y,6),"\n")
+
+}