4_Quarterman_Patrick_HW10A

# 4_Quarterman_Patrick_HW10A - 3.0000 2.7500 2.7500 3.0000...

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

Patrick Quarterman Section 4, HW10A Script: function [root]= bisectionroots(xu,xl) %Patrick Quarterman, Section 4 %HW10A %inputs: an upper guess xu, and lower guess xl %outputs: approximate roots %calculate f @ xl and xu to then check if guesses are above and below axis fu=-1.2*xu^2+1.35*xu+5.9; fl=-1.2*xl^2+1.35*xl+5.9; if fu*fl>0 error( 'Guesses do not contain the root' ) end %run loop until difference in bounds in acceptable %find roots using bisection method while abs(xu-xl)>.0001 xr=(xl+xu)/2; fxr=-1.2*xr^2+1.35*xr+5.9; fxl=-1.2*xl^2+1.35*xl+5.9; disp([xu,xl,xr]) if fxr*fxl>0 %test xr to set if it is the new xl or xu xl=xr; else xu=xr; end end root = xr; Command Window: >> bisectionroots(1,3) 1 3 2 2.0000 3.0000 2.5000 2.5000

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: 3.0000 2.7500 2.7500 3.0000 2.8750 2.7500 2.8750 2.8125 2.8125 2.8750 2.8438 2.8438 2.8750 2.8594 2.8438 2.8594 2.8516 2.8438 2.8516 2.8477 2.8477 2.8516 2.8496 2.8496 2.8516 2.8506 2.8496 2.8506 2.8501 2.8496 2.8501 2.8499 2.8499 2.8501 2.8500 2.8500 2.8501 2.8500 ans = 2.8500 >> bisectionroots(-2,1)-2.0000 1.0000 -0.5000-2.0000 -0.5000 -1.2500-2.0000 -1.2500 -1.6250-2.0000 -1.6250 -1.8125-1.8125 -1.6250 -1.7188-1.8125 -1.7188 -1.7656-1.7656 -1.7188 -1.7422-1.7422 -1.7188 -1.7305-1.7305 -1.7188 -1.7246-1.7305 -1.7246 -1.7275-1.7275 -1.7246 -1.7261-1.7261 -1.7246 -1.7253-1.7253 -1.7246 -1.7250-1.7253 -1.7250 -1.7252-1.7252 -1.7250 -1.7251 ans =-1.7251...
View Full Document

## This note was uploaded on 11/16/2010 for the course EGR 102 taught by Professor Hinds during the Spring '09 term at Michigan State University.

### Page1 / 3

4_Quarterman_Patrick_HW10A - 3.0000 2.7500 2.7500 3.0000...

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

View Full Document
Ask a homework question - tutors are online