summaryrefslogtreecommitdiff
path: root/Numerical_Methods_by_E_Balaguruswamy/CH6/EX6.14/Ex6_14.R
diff options
context:
space:
mode:
Diffstat (limited to 'Numerical_Methods_by_E_Balaguruswamy/CH6/EX6.14/Ex6_14.R')
-rw-r--r--Numerical_Methods_by_E_Balaguruswamy/CH6/EX6.14/Ex6_14.R37
1 files changed, 37 insertions, 0 deletions
diff --git a/Numerical_Methods_by_E_Balaguruswamy/CH6/EX6.14/Ex6_14.R b/Numerical_Methods_by_E_Balaguruswamy/CH6/EX6.14/Ex6_14.R
new file mode 100644
index 00000000..554c0ecf
--- /dev/null
+++ b/Numerical_Methods_by_E_Balaguruswamy/CH6/EX6.14/Ex6_14.R
@@ -0,0 +1,37 @@
+# Example 14 Chapter 6 Page no.: 172
+# Newton-Raphson Method for system of nonlinear equations
+
+
+#First function
+u <- function(x,y) {
+ x^2+x*y-6
+}
+#Second function
+v <- function(x,y) {
+ (x^2)-(y^2) -3
+}
+
+#Initial values
+x=1
+y=1
+
+#Error
+e<-c(100, 100)
+
+#Computing roots
+while (e[1]>0.00001 & e[2]>0.00001){
+ J=matrix(data = c(2*x+y, x, 2*x, -2*y),nrow = 2,ncol = 2,byrow = TRUE)
+ deter=det(J)
+ u1=u(x,y)
+ v1=v(x,y)
+ x=x-((u1*J[2,2]-v1*J[1,2])/deter)
+ y=y-((v1*J[1,1]-u1*J[2,1])/deter)
+ e[1]=abs(2-x)
+ e[2]=abs(3-y)
+}
+
+Roots<-c(x, y)
+cat("Value of x converges to",Roots[1])
+cat("Value of y converges to",Roots[2])
+
+#Only 2 iterations has been shown in the textbook.