Description Usage Arguments Details Value Author(s) See Also Examples

Solves an equation equation of form *f(x)=0*, for scalar *x* using the Newton-Raphson algorithm.

1 |

`init` |
Numeric scalar, The initial guess for |

`fn` |
An R-function returning the scalar value of |

`gr` |
An R-function returning the first derivative of |

`crit` |
Convergence criteria. The upper limit for the absolute value of |

`range` |
A two-unit vector giving the upper and lower bounds for |

The function is a straightforward implementation of the well-known Newton-Raphson algorithm.

A list of components

`par ` |
the value of |

`crit ` |
the value of |

If estimation fails (no solution is found during 100000 iterations), both e lements of the solution are NA's.

Lauri Mehtatalo <lauri.mehtatalo@uef.fi>

See `NRnum`

for a vector-valued x without analytical gradients.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | ```
## Numerically solve Weibull shape for a stand
## where DGM=15cm, G=15m^2/ha and N=1000 trees per ha
func<-function(shape,G,N,DGM) {
## print(G,DGM,N)
val<-pi/(4*gamma(1-2/shape)*log(2)^(2/shape))-G/(N*DGM^2)
val
}
grad<-function(shape) {
pi/4*(-1)*
(gamma(1-2/shape)*log(2)^(2/shape))^(-2)*
(gamma(1-2/shape)*digamma(1-2/shape)*2*shape^(-2)*log(2)^(2/shape)+
log(2)^(2/shape)*log(log(2))*(-2)*shape^(-2)*gamma(1-2/shape))
}
shape<-NR(5,fn=function(x) func(x,G=10000*15,1000,15),gr=grad,crit=10,range=c(2.1,Inf))$par
``` |

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.