summaryrefslogtreecommitdiff
path: root/Numerical_Methods_by_E_Balaguruswamy/CH4/EX4.6/Ex4_6.R
diff options
context:
space:
mode:
Diffstat (limited to 'Numerical_Methods_by_E_Balaguruswamy/CH4/EX4.6/Ex4_6.R')
-rw-r--r--Numerical_Methods_by_E_Balaguruswamy/CH4/EX4.6/Ex4_6.R31
1 files changed, 31 insertions, 0 deletions
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))
+