summaryrefslogtreecommitdiff
path: root/Numerical_Methods_by_E_Balaguruswamy/CH9/EX9.3/Ex9_3.R
diff options
context:
space:
mode:
Diffstat (limited to 'Numerical_Methods_by_E_Balaguruswamy/CH9/EX9.3/Ex9_3.R')
-rw-r--r--Numerical_Methods_by_E_Balaguruswamy/CH9/EX9.3/Ex9_3.R29
1 files changed, 29 insertions, 0 deletions
diff --git a/Numerical_Methods_by_E_Balaguruswamy/CH9/EX9.3/Ex9_3.R b/Numerical_Methods_by_E_Balaguruswamy/CH9/EX9.3/Ex9_3.R
new file mode 100644
index 00000000..11388f7a
--- /dev/null
+++ b/Numerical_Methods_by_E_Balaguruswamy/CH9/EX9.3/Ex9_3.R
@@ -0,0 +1,29 @@
+#Example 3 Chapter 9 Page no.: 280
+#Determining square root using linear interpolation
+
+
+#GIven table
+mydata<- data.frame(x=c(1,2,3,4,5),
+ fx=c(sqrt(1), sqrt(2), sqrt(3), sqrt(4), sqrt(5)),
+ stringsAsFactors = TRUE
+)
+mydata
+
+val<-mydata$x
+fun<-mydata$fx
+
+#since 2.5 lie between 2 & 3;
+var=2.5
+x1<- val[2]
+x2<- val[3]
+f1<- fun[2]
+f2<- fun[3]
+
+Ans<- signif(f1 + (var-x1)*((f2-f1)/(x2-x1)),5)
+cat("Calculated square root of 2.5 is :", Ans)
+
+Original<- signif(sqrt(var),5)
+cat("Original square root of 2.5 is :", Original)
+
+error<- Original-Ans
+cat("Error is :", error)