summaryrefslogtreecommitdiff
path: root/Numerical_Methods_by_E_Balaguruswamy/CH11
diff options
context:
space:
mode:
Diffstat (limited to 'Numerical_Methods_by_E_Balaguruswamy/CH11')
-rw-r--r--Numerical_Methods_by_E_Balaguruswamy/CH11/EX11.5/Ex11_5.R39
-rw-r--r--Numerical_Methods_by_E_Balaguruswamy/CH11/EX11.6/Ex11_6.R25
-rw-r--r--Numerical_Methods_by_E_Balaguruswamy/CH11/EX11.8/Ex11_8.R40
3 files changed, 104 insertions, 0 deletions
diff --git a/Numerical_Methods_by_E_Balaguruswamy/CH11/EX11.5/Ex11_5.R b/Numerical_Methods_by_E_Balaguruswamy/CH11/EX11.5/Ex11_5.R
new file mode 100644
index 00000000..78868bc6
--- /dev/null
+++ b/Numerical_Methods_by_E_Balaguruswamy/CH11/EX11.5/Ex11_5.R
@@ -0,0 +1,39 @@
+# Example 5 Chapter 11 Page no.: 358
+# Estimating velocity
+
+T <- c(5,6,7,8,9) # Time
+S <- c(10.0,14.5,19.5,25.5,32.0) # Distance
+
+#distance time function
+ss <- function(t1){
+ s <- S[t1-4]
+ return(s)
+}
+
+#Difference value h
+h1 <- 1
+
+# We have velocity as the first derivative of distance
+v <- function(t,h){
+ return(((-3*ss(t))+(4*ss(t+h))-ss(t+2*h))/(2*h))
+}
+
+#First given time is 5s
+t2 <- 5
+cat("Velocity of car at t=5s is",v(t2,h1),"km/s")
+
+# Central difference formula gives
+vcf <- function(t,h){
+ return((ss(t+h)-ss(t-h))/(2*h))
+}
+#second time given is 7s
+t3 <- 7
+cat("Velocity of car at t=",t3,"s is",vcf(t3,h1),"km/s")
+
+# Backward diffeerence formula
+vb <- function(t,h){
+ return(((3*ss(t))-(4*ss(t-h))+ss(t-2*h))/(2*h))
+}
+#Third given time is 9s
+t4 <- 9
+cat("Velocity of car at t=",t4,"s is",vb(t4,h1),"km/s") \ No newline at end of file
diff --git a/Numerical_Methods_by_E_Balaguruswamy/CH11/EX11.6/Ex11_6.R b/Numerical_Methods_by_E_Balaguruswamy/CH11/EX11.6/Ex11_6.R
new file mode 100644
index 00000000..fb55e716
--- /dev/null
+++ b/Numerical_Methods_by_E_Balaguruswamy/CH11/EX11.6/Ex11_6.R
@@ -0,0 +1,25 @@
+# Example 6 Chapter 11 Page no.: 359
+# Estimating Acceleration
+
+T <- c(5,6,7,8,9) # Time
+S <- c(10.0,14.5,19.5,25.5,32.0) # Distance
+
+#distance time function
+ss <- function(t1){
+ s <- S[t1-4]
+ return(s)
+}
+
+#Difference value h
+h1 <- 1
+
+#Acceleration is given by second derivative of distance
+
+a <- function(t,h){
+ return((ss(t+h)-(2*ss(t))+ss(t-h))/(h^2))
+}
+
+h1 <- 1
+t1 <- 7 # given time
+
+cat("Acceleration of car at t=",t1,"s is",a(t1,h1),"km/s^2") \ No newline at end of file
diff --git a/Numerical_Methods_by_E_Balaguruswamy/CH11/EX11.8/Ex11_8.R b/Numerical_Methods_by_E_Balaguruswamy/CH11/EX11.8/Ex11_8.R
new file mode 100644
index 00000000..fad41028
--- /dev/null
+++ b/Numerical_Methods_by_E_Balaguruswamy/CH11/EX11.8/Ex11_8.R
@@ -0,0 +1,40 @@
+# Example 8 Chapter 11 Page no.: 364
+# Richardson Extrapolation
+
+f <- function(x){
+ return(exp(x))
+}
+h1<- 0.5
+r1 <- 1/2
+x1<- 0.5
+
+#First order forward difference formula
+D1 <- function(x,h) {
+ return((f(x+h) - f(x-h))/(2*h))
+}
+
+Dr1 <- function(x,r,h){
+ return((f(x+(r*h)) - f(x-(r*h)))/(2*r*h))
+}
+
+f1 <- function(x,r,h){
+ return((Dr1(x,r,h)-(r^2)*D1(x,h))/(1-(r^2)))
+}
+F <- signif(f1(x1,r1,h1), digits = 5)
+
+cat("The value of function e^x at",x1," with parameters")
+cat("h=",h1)
+cat("r=",r1)
+cat("is",F)
+
+# The value deviates slighly from the value of the textbook becaues of approximation in the text
+
+r2 <- 2
+F1 <- signif(f1(x1,r2,h1), digits = 5)
+
+cat("The value of function e^x at",x1," with parameters")
+cat("h=",h1)
+cat("r=",r2)
+cat("is",F1)
+
+cat(" This shows that estimate with r=",r1,"is better than the estimate with r=",2) \ No newline at end of file