Skip to content

Latest commit

 

History

History
19 lines (15 loc) · 508 Bytes

README.md

File metadata and controls

19 lines (15 loc) · 508 Bytes

NewtonRaphson

Newton Raphson Method to solve an equation

Assuming f(x) = x^ + 2x, so the differential function f'(x) = 2x + 2

giving an initial value of x0 = 1, so the equation can be solved by this snippet:

let solver = NewtonRaphson(
   initialValue: 1,
   function: { x in
       return x * x + 2 * x
   }, differential: { x in
       return 2 * x + 2
   })
let result = try solver.solve()
XCTAssertEqual(result.x, 0)