diff options
Diffstat (limited to 'Numerical_Methods_by_E_Balaguruswamy/CH9/EX9.5/Ex9_5.R')
-rw-r--r-- | Numerical_Methods_by_E_Balaguruswamy/CH9/EX9.5/Ex9_5.R | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/Numerical_Methods_by_E_Balaguruswamy/CH9/EX9.5/Ex9_5.R b/Numerical_Methods_by_E_Balaguruswamy/CH9/EX9.5/Ex9_5.R new file mode 100644 index 00000000..1813dcb5 --- /dev/null +++ b/Numerical_Methods_by_E_Balaguruswamy/CH9/EX9.5/Ex9_5.R @@ -0,0 +1,39 @@ +#Example 5 Chapter 9 Page no.: 283
+#Lagrange's Polynomial
+
+# Installing and importing required packages
+
+install.packages("polynom")
+install.packages("stats")
+library("polynom")
+library("stats")
+
+#Given data
+mydata<- data.frame( i=c(0,1,2,3),
+ xi=c(0,1,2,3),
+ ex=c(0,1.7183,6.3891,19.0855),
+
+ stringsAsFactors = TRUE
+)
+mydata
+
+q<-poly.calc(mydata$xi, mydata$ex) #function to calculate lagrange interpolation polynomial
+q
+beta<-coef(q) #obtain coefficients
+beta
+y1<-beta[2]
+y2<-beta[3]
+y3<-beta[4]
+
+#substituting x=1.5 in above equation :
+x=1.5
+uno<-x
+cube<-x*x*x
+square<-x*x
+
+pot<-(y3*cube)+ (y2*square) + (y1*uno)
+pot
+Ans<- pot+1
+
+cat("Value of e^1.5 is :", signif(Ans,5))
+
|