lec18_roots - # Root search methods ' Supplied functions:...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
# Root search methods ''' Supplied functions: 1. bisect() Usage: root=bisect(f,xlow,xhigh,switch=0,tol=1.0e-8) Returns: the root in the bracket (float) Parameters: f - function f(x) to find the root of xlow,xhigh - lower and upper bounds of root switch - whether to check whether |f(x)| is getting smaller with each step tol - accuracy of root 2. newtonraphson() Usage: root = newtonraphson(f,xlow,xhigh,xStart,maxIter=10,tol=1.0e-8,plotit=True) Returns: the closest root to xStart (float) Parameters: f - function f(x) to find the root of xlow,xhigh - lower and upper bounds of root xStart = starting guess for root maxIter - upper limit to number of iterations tol - accuracy of root plotit - flag whether to plot ouput ''' __all__=('bisect()','newtonraphson()') from pylab import * def bisect(f,xlow,xhigh,switch=0,tol=1.0e-8): from math import ceil,log #for single numbers, these are more efficient than those supplied by numpy f1=f(xlow) if f1 == 0. : return xlow f2=f(xhigh) if f2 == 0. : return xhigh
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 3

lec18_roots - # Root search methods ' Supplied functions:...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online