Description Usage Arguments Value Author(s) References Examples
Finds the roots of univariate functions by using the Secant method.
1 |
fun |
a function for which the root is searched. |
x0 |
a numeric value to be used to start the algorithm (first initial). |
x1 |
a numeric value to be used to start the algorithm (second initial). |
eps |
a numeric value to be considered as the tolerance for convergence of the algorithm. |
maxit |
a numeric value which denotes maximum number of iterations to be consumed. |
silent |
a logical statement which decides whether the iterations should be printed. |
Returns a numeric result.
Ozlem Ilk, Ozgur Asar
Ilk, O. (2011). R Yazilimina Giris [Introduction to R Language]. ODTU Yayincilik [METU Press].
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | ## Example-1
f1=function(x) x^3+sqrt(x)-1
secant(f1,0.5,0.55,10^-10,silent=FALSE)
## Example-2
f2=function(x) x^3-sinh(x)+4*x^2+6*x+9
# searching for reasonable initials
x0=seq(-10,10,,100)
plot(x0,f2(x0),type="n")
lines(x0,f2(x0))
x0=seq(6,8,,100)
plot(x0,f2(x0),type="n")
lines(x0,f2(x0))
abline(h=0,lty=2)
secant(f2,7,7.2,10^-10,maxit=30,silent=FALSE)
|
Iterasyon: 1 , Result= 0.610619
Iterasyon: 2 , Result= 0.6051663
Iterasyon: 3 , Result= 0.6054222
Iterasyon: 4 , Result= 0.6054234
Iterasyon: 5 , Result= 0.6054234
Solution: 0.6054234
[1] 0.6054234
Iterasyon: 1 , Result= 7.106078
Iterasyon: 2 , Result= 7.112647
Iterasyon: 3 , Result= 7.113065
Iterasyon: 4 , Result= 7.113063
Iterasyon: 5 , Result= 7.113063
Solution: 7.113063
[1] 7.113063
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.