Jonathan Worthington > Math-Calculus-NewtonRaphson-0.1 > Math::Calculus::NewtonRaphson



Annotate this POD

View/Report Bugs
Module Version: 0.1   Source  


Math::Calculus::NewtonRaphson - Algebraic Newton Raphson Implementation


  use Math::Calculus::NewtonRaphson;

  # Create an object.
  my $exp = Math::Calculus::NewtonRaphson->new;
  # Set a variable and expression.
  $exp->setExpression('x^2 - 5') or die $exp->getError;
  # Apply Newton Raphson.
  my $result = $exp->newtonRaphson(2) or die $exp->getError;
  print $result; # Prints 1.4142...


This module can take an algebraic expression, parses it and then uses the Newton Raphson method to solve the it. The Newton Raphson method relies on the fact that the expression you pass in evaluates to zero where there is a solution. That is, to solve:-

x^2 = 5

You would need to pass in:-

x^2 - 5

It understands expressions containing any of the operators +, -, *, / and ^ (raise to power), bracketed expressions to enable correct precedence and the functions ln, exp, sin, cos, tan, sec, cosec, cot, sinh, cosh, tanh, sech, cosech, coth, asin, acos, atan, asinh, acosh and atanh.


None by default.



Creates a new instance of the Newton Raphson object, which can hold an individual expression.





  $expr = $exp->getExpression;


  $result = $exp->newtonRaphson($variable, $guess, %mappings);

Attempts to solve the expression for the given variable using the Newton Raphson method, using the passed value as the first guess. The mappings hash allows any other non-numeric constants to be mapped to numeric values - a pre-requisite for solving such equations.






The author of this module has a website at, which has the latest news about the module and a web-based frontend to allow you to test the module out for yourself.


Jonathan Worthington, <>


Copyright (C) 2004 by Jonathan Worthington


syntax highlighting: