Skip to content

MANE 3351

Lecture 8

Classroom Management

Agenda

  • Part 2: Bisection Search lecture
  • Test 1 2024 - available in Solutions
  • Test 1 - scheduled 10/6/2025
  • Lab Section is submitting Lab 3

Resources

Handouts

Assignments


Schedule

Lecture/Lab Date Topic
7 9/24 Taylor Series, Homework 2 (due 10/1 - no late work), Lab 3 (due 10/1)
8 9/29 Roots of Equations, bisection method (not on Test 1)
9 10/1 Bisection Method Error Analysis, False Position (not on Test 1)
10 10/6 Test 1 (lectures 1-7)

Roots of Equations

Introduction

  • Value x such that f(x)=0
  • Extremely useful operations
  • Engineering Economic Examples
    • Break-even analysis
    • Payback period
    • Rate of return

Quadratic Equation

Consider a second-order polynomial \(ax^2+bx+c=0\)

  • The quadratic formula finds the value(s) of x
\[ \frac{-b\pm\sqrt{b^2-4ac}}{2a} \]

Root Bracketing Techniques

  • Many techniques for find roots start by bracketing the root
  • Consider the cumulative distribution function (CDF) of a standard normal distribution
\[ \Phi(z)=\int_{-\infty}^z\frac{1}{\sqrt{2\pi}}\exp\left(-\frac{1}{2}u^2\right)\;du \]
  • Goal: Find first quartile that is the value of z such that \(\phi(z)=0.25\)
  • Start up writing equation
  • Trial and error
  • Python can help

Statistical Functions in Python


Python Code for Statistical Functions

from scipy import stats
p=0.25

x=float(input("Enter the value of x: "))
fx=stats.norm.cdf(x)

print("for x={}, f({})={}".format(x,x,fx))

print("{}-th percentile={}".format(p,stats.norm.ppf(p)))

Bisection Method

  1. Identify an interval [a,b] such that either a or b overshoots the mark while the other undershoots it.
  2. Calculate the midpoint, m, of the identified interval
  3. If a and m both overshoot or both undershoot the mark, the desired value lies in [m,b]
  4. If b and m both overshoots or both undershoot the mark, the desired value lies in [a,m]
  5. Return to step 2 using the newly identified interval

Source: textbook, page 41


Simple Pseudocode

Source: textbook, page 43


Python code for Simple Pseudocode

#from scipy import stats
def f(x):
    return stats.norm.cdf(x)-.25
# initialize code
a=-0.9
b=0.9
i=1
L=f(a)
m=(a+b)/2.0 # discuss divisor
M=f(m)
while True:
    if L*M<0.0:
        b=m
    else:
        a=m
        L=M
    m=(a+b)/2.0
    M=f(m)
    i=i+1
    print("iteration {}, root is located at {}".format(i,m))
print("{} iterations processed".format(i))
print("the root is {} with f({})={}".format(m,m,M))

Pseudocode 2

Source: textbook, page 43


Python Code for Pseudocode 2

# Pseudo-code 2
from scipy import stats
import math
def f(x):
    return stats.norm.cdf(x)-.25
# initialize code
a=-3.0
b=0.0
tol=0.0005
N=100
err=math.fabs(b-a)
L=f(a)
for i in range(0,N+1):
    m=(a+b)/2.0
    M=f(m)
    err=err/2.0
    if (M==0) or (err<tol):
        print("stopping inside for loop at iteration {}".format(i))
        break
    if (L*M<0):
        b=m
    else:
        a=m
        L=M
print("the root is {} with f({})={}".format(m,m,M))