{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

cosRoot

# cosRoot - /than tolerance/Arguments/xStart-left end of...

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

//============================================ //cosRoot.cpp //Finds the root of cosine between 1.5 and 1.6 radians. //============================================ #include  #include  using namespace std; //Declare functions double bisect(double xStart, double yStart, double tolerance, double f(double)); //==============>>main<<====================== int main() { cout.precision(14); // show 14 decimal places of resolution cout<<"The root of cosine between 1.5 and 1.6 is "; cout<<bisect(1.5,1.6,1e-6,cos)<<endl; }</bisect(1.5,1.6,1e-6,cos)<<endl; #include  using namespace std; //====================>> bisect << ============================ //Seeks root of function f(double r) using bisection //in the interval [xStart,yStart]. A root must be verified //in this intervalor the code will abort. Bisection proceeds //until the next root is bracketed by an interval of length of less

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: //than tolerance. //Arguments //xStart--left end of initial interval //yStart--right end of initial interval //tolerance--maximum length of final interval //f--function whose root will be found //============================================================ = double bisect(double xStart, double yStart, double tolerance, double f(double)) { assert(tolerance>0.0); assert(xStart<ystart); assert(f(xStart)*f(yStart)<=0.0); double x=xStart;//point to left of root double y=yStart;//point to right of root while(y-x>tolerance) { //f(x)*f(y)<=0.0 double midPoint=0.5*(x+y); if(f(x)*f(midPoint)<=0.0) { y=midPoint; //shorten interval,maintain invariant } else { x=midPoint; //shorten interval , maintain invariant } } return 0.5*(x+y); }</ystart);...
View Full Document

{[ snackBarMessage ]}