Newton

com.phasmidsoftware.number.core.misc.Newton
case class Newton(f: Double => Double, dfByDx: Double => Double)

A case class for solving equations using Newton's approximation method (Newton-Raphson) https://en.wikipedia.org/wiki/Newton%27s_method. Newton-Raphson is a special case of Householder's more general method https://en.wikipedia.org/wiki/Householder%27s_method. CONSIDER implementing Halley's method https://en.wikipedia.org/wiki/Halley%27s_method.

Value parameters

dfByDx

The derivative of the function.

f

The function whose root is to be found.

Attributes

Constructor

Creates a new Newton solver with the given function and its derivative.

Graph
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Members list

Value members

Concrete methods

def solve(tries: Int, threshold: Double, initial: Double): Try[Double]

Solves the given equation using the Newton-Raphson method by iteratively refining an initial guess. The method attempts to find a root of the function f(x) = 0 within a specified threshold of accuracy. If the solution does not converge within the given number of tries, it returns a failure.

Solves the given equation using the Newton-Raphson method by iteratively refining an initial guess. The method attempts to find a root of the function f(x) = 0 within a specified threshold of accuracy. If the solution does not converge within the given number of tries, it returns a failure.

Value parameters

initial

The initial guess for the root of the equation.

threshold

The convergence threshold, representing the acceptable difference between f(x) and 0.

tries

The maximum number of iterations allowed for convergence.

Attributes

Returns

A Try[Double] containing the root if converged successfully, or a Failure if the method fails.

Inherited methods

def productElementNames: Iterator[String]

An iterator over the names of all the elements of this product.

An iterator over the names of all the elements of this product.

Attributes

Inherited from:
Product
def productIterator: Iterator[Any]

An iterator over all the elements of this product.

An iterator over all the elements of this product.

Attributes

Returns

in the default implementation, an Iterator[Any]

Inherited from:
Product