summaryrefslogtreecommitdiff
path: root/Numerical_Methods_by_E_Balaguruswamy/CH6/EX6.5/Ex6_5.R
diff options
context:
space:
mode:
Diffstat (limited to 'Numerical_Methods_by_E_Balaguruswamy/CH6/EX6.5/Ex6_5.R')
-rw-r--r--Numerical_Methods_by_E_Balaguruswamy/CH6/EX6.5/Ex6_5.R37
1 files changed, 37 insertions, 0 deletions
diff --git a/Numerical_Methods_by_E_Balaguruswamy/CH6/EX6.5/Ex6_5.R b/Numerical_Methods_by_E_Balaguruswamy/CH6/EX6.5/Ex6_5.R
new file mode 100644
index 00000000..eb9d2313
--- /dev/null
+++ b/Numerical_Methods_by_E_Balaguruswamy/CH6/EX6.5/Ex6_5.R
@@ -0,0 +1,37 @@
+# Example 5 Chapter 6 Page no.: 140
+# False Position Method
+
+#Given Function
+f <- function(x) {
+ (x^2)-(x)-2
+}
+
+# Given Values
+x1=1
+x2=3
+
+# False Position Function
+
+xr=x1-(f(x1)*(x2-x1))/(f(x2)-f(x1))
+cat("Iteration:",1,"\n","xl:",x1,"\n","xu:",x2,"\n","*************************")
+
+for (i in 2:11){
+ if (f(x1)*f(xr)>0){
+ x1=xr
+ xr=x1-(f(x1)*(x2-x1))/(f(x2)-f(x1))
+ }
+ else if (f(x1)*f(xr)<0){
+ x2=xr
+ xr=x1-(f(x1)*(x2-x1))/(f(x2)-f(x1))
+ }
+ if (f(x1)*f(xr)==0){
+ break
+ }
+ cat("Iteration:",i,"\n")
+ cat("xlow:",x1,"\n")
+ cat("xup: ",x2,"\n")
+ cat("xcur:",xr,"\n")
+ cat("*************************\n")
+}
+
+cat("After",i,"th iteration","the root approximation stablized and the root is",xr) \ No newline at end of file