summaryrefslogtreecommitdiff
path: root/Numerical_Methods_by_E_Balaguruswamy/CH10/EX10.1/Ex10_1.R
diff options
context:
space:
mode:
Diffstat (limited to 'Numerical_Methods_by_E_Balaguruswamy/CH10/EX10.1/Ex10_1.R')
-rw-r--r--Numerical_Methods_by_E_Balaguruswamy/CH10/EX10.1/Ex10_1.R30
1 files changed, 30 insertions, 0 deletions
diff --git a/Numerical_Methods_by_E_Balaguruswamy/CH10/EX10.1/Ex10_1.R b/Numerical_Methods_by_E_Balaguruswamy/CH10/EX10.1/Ex10_1.R
new file mode 100644
index 00000000..1dfe5184
--- /dev/null
+++ b/Numerical_Methods_by_E_Balaguruswamy/CH10/EX10.1/Ex10_1.R
@@ -0,0 +1,30 @@
+# Example 1 Chapter 10 Page no.: 326
+# Straight Line fitting
+
+x<-c(1,2,3,4,5) # Define table
+y<-c(3,4,5,6,8)
+#Square of X values
+x2<-x^2
+#Product of X and Y
+xy<-x*y
+#Sum of X
+sx<-sum(x)
+#Sum of y
+sy<-sum(y)
+#Sum of x^2
+sx2<-sum(x2)
+#Sum of x*y
+sxy<-sum(xy)
+# number of elements
+n =5
+# calculating slope
+b <- ((n*sxy) -(sx*sy))/((n*sx2)-(sx^2))
+# calculating intercept
+a <- (sy)/n - (b*(sx))/n
+
+cat("The Linear equation y=",a,"+",b,"x")
+
+#Plotting curve and fitting the Straight line
+plot(x,y)
+
+abline(a=a,b=b)