updown {lmfor}R Documentation

Solve a simple equation using a step halving algorithm.

Description

Solves equations of form f(x)=0f(x)=0, for scalar xx (l<=x<=u)(l<=x<=u) using a simple step halving algorithm, where f(x)f(x) is a monotonic continuous function. Initial finite upper and lower bounds for x are required. The algorithm first computes ff for x=ux=u and x=lx=l. If the sign was different then another call is performed at the midpoint x=(u+l)/2x=(u+l)/2, and the midpoint is taken as a new upper or lower bound, according to the location of sign change. The upper or lower bound are repeatedly updated until the absolute value of f at the midpoint is below a specified criteria.

Usage

updown(l, u, fn, crit = 6)

Arguments

l

The initial lower bound

u

The initial upper bound

fn

R-function for f(x)f(x)

crit

The convergence criteria (Maximum accepted value of f at the solution is 10crit10^{-\code{crit}}).

Value

A scalar giving the value of xx at the solution. If the sign did not change between l and u, NA is returned.

Warning

May lead to infinite loop for non-continuous functions. Works only with monotonic functions.

Author(s)

Lauri Mehtatalo <lauri.mehtatalo@uef.fi>

Examples

## Compute the median of Weibull distibution
fn<-function(x) pweibull(x,5,15)-0.5
updown(1,50,fn)

[Package lmfor version 1.6 Index]