Title: Chem 302 Lab Assignment
1Chem 302 Lab Assignment
- Tuesday 230 400ColinChris MJohnathan
PCraigJonathan EAlex
- Tuesday 400 530CurtisMattChris
LJanetCoryKristen
2Chem 302 - Math 252
- Chapter 1Solutions of nonlinear equations
3Roots of Nonlinear Equations
- Many problems in chemistry involve nonlinear
equations - Linear and quadratic equations are trivial, can
be solved analytically - Cubic and higher order solve numerically
- Present a overview of basic methods
- Not a complete discussion
4Successive Approximations
- Simplest method
- Want to solve f(x)0rearrange into the
form xg(x) - Use as iteration formula xi1g(xi)
- Use initial guess and iterate until self
consistent
5Successive Approximations
6(No Transcript)
7Successive Approximations
8Successive Approximations
9Successive Approximations
Will find x2, will not find x1
Different formula different results No one
formula is best Slow to converge
10Successive Approximations
- How to find initial guesses?
- Grid search
Course to start Get finer
11Analysis of Convergence
- Each stage of iteration xi1g(xi)
- For convergence
- Intersection of two functions x g(x)
12Analysis of Convergence
13Analysis of Convergence
- Four possibilities
- Monotonic convergence
- Oscillating convergence
- Monotonic divergence
- Oscillating divergence
14Monotonic convergence
15Oscillating convergence
16Monotonic divergence
17Oscillating divergence
18Analysis of Convergence
- Key is g?(x)
- Mean Value Theorem
- If g(x) and g?(x) are continuous on the interval
a,b then there exists an e (alteltb) such that
19Analysis of Convergence
20Analysis of Convergence
If M lt 1 guaranteed to converge
Sufficient but not necessary
To converge LHS ? 0
21Speed of Convergence
Taylor expansion about root
For xi
When close to convergence
- Dominant term will be 1st nonzero derivative
- Order of Convergence
22Newton-Raphson Method
- One of most common methods
- Usually 2nd order convergence
- Generally superior to simple iteration
- Uses function and 1st derivative to predict root
(assume f is linear)
23Newton-Raphson Method
24Newton-Raphson Method
- Fairly robust
- Need analytic expressions for f(x) and f'(x)
- May be complicated or not available
- Need to evaluate f(x) and f'(x) many times
- Maximum efficiency
- f'(x) close to zero will cause problems
- Especially important for multiple roots
- Need to checks in program
- Value of f'(x)
- Max iterations
25Newton-Raphson Method
Convergence
26Secant Method
- NR but use numeric derivative
27False-Position Method
- Similar to Secant Method
- Uses two points (one on each side of root) (need
search) - Find where function would be zero if linear
between two points - During each iteration one point is held fixed
(pivot), other is moved - More stable but slower than NR
- If pivot far from root then slow
- If pivot close to root then denominator can be
small
28False-Position Method
- Algorithm
- Pick xL xR (xL lt lt xR)
- Evaluate
- Calculate
- Calculate
- If then xM is the root
- Replace xL or xR with xM (depends on sign of
)
xM
xL
xR
Repeat
29False-Position Method
30Bisection Method
- Same as FP Method but xM is average of xL xR
- Drawbacks of both FP Bisection
- Two initial guesses on opposite sides of root
- Multiple or close roots a problem
- f always same sign a problem
- Round-off error as xM gets close to root
- Secant, FP Bisection methods do not require
analtyic expression of f'(x)
31Roots of Polynomials
- Want as efficient an algorithm as possible
- Efficiency of operations
-
-
- /
- Power
- Naive method (10 , 4 )
- Most efficient method for polynomial of order m
requires m additions and m multiplications - Nesting (Horners Method)
32Horners Method
- For polynomial of degree m
33Horners Method
m , m
34Horners Method
1 is a root
35Horners Method
2 is a root
36Horners Method
- If b0 0 (i.e. r is a root)
- Have factored (x-r) from equation (i.e. reduced
order, called deflating) - Continue to find roots of reduced equation
37Horners Method
2 is a root (i.e. a double root of original
equation)
38Birge-Vieta Method
- NR method with f(x) and f'(x) evaluated using
Horners method - Once a root is found, reduce order of polynomial
39Birge-Vieta Method
40Birge-Vieta Method
41Birge-Vieta Method
42Birge-Vieta Method
43Birge-Vieta Method
44Example
45Example
- x0 ? 4.33 ? 3
- x0 gt 4.33 ? 5
- Third root?
Try it!!!
46 47Roots of Polynomials
- What about complex roots?
- Occur in pairs
- Have form a ib a ib
- Roots of quadratic equation f(x) x2 2ax
a2 b2 - BV method we removed factors of x r.
- Quadratic can be solved analytically therefore
best to remove quadratic factors
48Lin-Bairstow Method
49Lin-Bairstow Method
50Lin-Bairstow Method
- Algorithm
- m gt 3 determine quadratic roots, reduce order of
problem by 2 - m 3 determine linear root then quadratic roots
- m 2 determine quadratic roots
- m 1 determine linear root
51- // Lin Biarstow.cpp
- include "stdafx.h"
- include ltfstreamgt
- include ltconio.hgt
- include ltstdio.hgt
- include ltmath.hgt
- include ltstdlib.hgt
- include ltstringgt
- include ltdos.hgt
- include ltiostreamgt
- using namespace std
- int _tmain(int argc, _TCHAR argv)
-
- double t1e-8, a, b, c,u,v,du,dv,r1,r2,ep,f,d
- int n,i
- FILE logfile
- anew doublen1
- bnew doublen1
- cnew doublen1
- for(i0iltn1i)
- coutltlt"\nInput coefficient a"ltltiltlt" "
- cingtgtai
-
- fprintf(logfile,"\nlf lfx",a0,a1)
- for(i2iltn1i)fprintf(logfile,"
lfxd",ai,i) - coutltlt"\n\nRoots of the polynomial are\n"
- fprintf(logfile,"\n\nRoots are\n")
- while (an0)n--
- // make sure ngt3
- while(ngt3)
52- b0a0ub1vb2
- fc2c2-c1c3
- if(f0)dudv1
- elsedu(b0c3-b1c2)/fdv(c1b1
-c2b0)/f - udu
- vdv
- epsqrt(dududvdv)
-
- duu4v
- if(dlt0) //complex roots
-
- r1u/2r2sqrt(-d)/2
- coutltltr1ltlt" i"ltltr2ltltendl
- coutltltr1ltlt" - i"ltltr2ltltendl
- fprintf(logfile,"lf ilf\nlf -
ilf\n",r1,r2,r1,r2) -
- else // real roots
- if(n3)
- u0
- bncnanep1
- while(epgtt)
- for(in-1igt0i--)
-
- biaiubi1
- cibiuci1
-
- b0a0ub1
- if(c10)du1
- else du-b0/c1
- udu
- epsqrt(dudu)
-
- coutltltultltendl
- fprintf(logfile,"lf\n",u)
- n--
53- if(dlt0) //complex roots
-
- r1u/2r2sqrt(-d)/2
- coutltltr1ltlt" i"ltltr2ltltendl
- coutltltr1ltlt" - i"ltltr2ltltendl
- fprintf(logfile,"lf ilf\nlf -
ilf\n",r1,r2,r1,r2) -
- else
-
- r1u/2sqrt(d)/2
- r2u/2-sqrt(d)/2
- coutltltr1ltltendl
- coutltltr2ltltendl
- fprintf(logfile,"lf\nlf\n",r1,r2)
-
-
- else if(n1)
- r1-a0/a1
54(No Transcript)
55- Roots of the polynomial
- -130.000000 120.000000x -2.000000x2
-9.000000x3 1.000000x4 - Roots are
- 3.972068
- -3.600135
- 7.399477
- 1.228589