This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Objectives• Linear Equations• Solving Linear Equations
• Non-Linear Equations• Solving Non-linear Equations in 1D
• Interval Bisection Method• Newton’s Method
Solving Systems of NLE’s• Newton’s Method
Good Reference: Heath, Scientific Computing 2005 McGraw Hill
Linear Equations• Effects directly proportional to causes
Examples:f(x)=a*x + b
F([x])=[A]x+[b]
F(x)== mxn nx1 nx1
Linear Equations• Examples in building energy modeling:
• Steady state conduction in multi-component wall system
Faca
de s
lab
Insu
latio
n
Gyp
sum
[Q(T)]=[{k}A/L[M]] {T}
Where[M]=
Solving Linear Equations: Fixed Point Iteration/ Jacobi Iteration
• If we start with an initial guess for the solution, we can see how close this guess is, which will inform our next guess, and so on until we arrive at the solution
• In fixed-point iteration schemes, we put equation in form
x=f(x) and use successive guesses for x(RHS) to get our next guess (LHS)
Solving Linear Equations: Fixed Point Iteration/ Jacobi Iteration
• Illustration of Jacobi Iteration for a scalar:• Solve 3x=6 by iterating
– We need a term “x” by itself on one side
– Break x term into just x and what remainsi.e. x + 2x =6
– Rearrange to givex=-x/2+3
Solving Linear Equations: Fixed Point Iteration/ Jacobi Iteration
• Now that we have the equation in the proper form, make an initial guess for x
• xo=…. Say 7
• Plug into right side only to get x=-7/2+3=-0.5
• -0.5 is now our second guess, x1
Solving Linear Equations: Fixed Point Iteration/ Jacobi Iteration
• If we continue in this manner, we approach the solution of x=2 Trial xi xi+1
(“lower triangular” matrix- what if it is “upper triangular”?)
Solving LE’s: Gaussian Elimination• How do we transform our original equation?• Multiplying both sides of any matrix equation by any matrix
[M] does not change equation if M is non-singular• Therefore we can do
[M1] [M2]….. [Mn] [A] {x}=[M1] [M2]…[Mn]{b}until we arrive at
[N]{x}= [P] {b}
Where [N]= [M1] [M2]….. [Mn] [A]
and is lower triangular or upper triangular
Solving LE’s: Gaussian Elimination• How do we transform A into N????• Start with simple example:
Ax=b; A is 2 x 1 matrix , B is
If we pre-multiply both sides by matrix M =
we get
Nx=MAx= x=Mb
Can we now solve for all values of x?
Solving LE’s: Gaussian Elimination
• We transformed a 2 x 1 Matrix into an upper diagonal matrix, N.
• We can do this for any size non-singular matrix by using the following transformation
Solving LE’s: Gaussian Elimination• Given Ax=b, with constituents of A being aij
for k=1 to n-1if akk0for i = k+1 to nmik=aik/akk
endfor j=k+1 to nfor i= k+1 to naij = aij =mikakj
endend
end
Loop over columnsAvoid dividing by 0
Divides each entry below the diagonal by the diagonal entry for that column
Transforms each member of lower part of matrix
What results is a transformed version of A which is upper diagonal
Solving LE’s: Gaussian Elimination
• With the process on the previous slide, we can transform any non-singular matrix, with a few stipulations
• Much more information in handouts on process, derivation, etc.
• One example problem now
Solving LE’s: Gaussian Elimination
Given Ax=
Solve for x
Solving LE’s: Gaussian Elimination
Premultiply first by M1=And then by M2=
Get M2M1Ax =x=M2M1b=
Solving LE’s: Gaussian Elimination
Easily solved by successive substitution to give:x=
Non-Linear Equations• Arise often in building energy modeling
applications• e.g Calculate radiation heat transfer from roof
when sky temperature is known
• Q(Troof)= Fes(Tsky4 - Troof
4) Aroof
Tsky (known)
Troof (quantity of interest)
Solving Non-Linear Equations• Analytical solutions rarely possible• Often large systems of equations• Must use numerical techniques• Will introduce two:
Solving NLE’s: Interval Bisection• All NLE’s can be written as homogeneous
equations, i.ef(x) =0
• Therefore, all solutions of NLE’s are “zero-finding” exercises
• If we know an approximate interval where f(x) crosses x-axis, we can make interval smaller and smaller until we have a tiny interval in which solution lies
Solving NLE’s: Interval Bisection
x
f(x)x=a x=b
Solving NLE’s: Interval Bisection
x
f(x)x=a x=b
x=(a+b)/2
Solving NLE’s: Interval Bisection
x
f(x)x=a x=b
x=(a+b)/2
Is zero between x=a and x=(a+b)/2 or x=(a+b)/2 and x=b?
Repeat process again until interval is smaller than a certain tolerance
Solving NLE’s: Interval Bisection
• Example: Find solution of f(x)=(x-2)2-4– We know the answer is between, say, -3 and 1.1
Solving NLE’s: Newton’s Method• With interval bisection, we only looked at the
sign of the function at a given point• If we also look at the derivative of the
function, we can find a solution faster• Newton’s Method uses a Taylor Series
expansion:
f(x+h) =f(x) +f’(x)h + higher order terms
Solving NLE’s: Newton’s Method• If we drop higher order terms we get
f(x+h) ≈f(x) +f’(x)h• If we start at some value of x (initial guess), we
want to find a value of h for which f(x+h) is as close to 0 as possible.
• This occurs ath=-f(x)/f’(x)
• We then evaluate the function and its derivative at (x+h) and start the process again
Solving NLE’s: Newton’s Method• Mathematically:
k=0x0=initial guesswhile f(xk)>tolerance
xk+1=xk-f(xk)/f’(xk)k=k+1
end
Solving NLE’s: Newton’s Method• Graphically:
x0
x
f(x)
Solving NLE’s: Newton’s Method• This can be extended to systems of NLE’s• Instead of derivative we use Jacobian matrix:
[Jf]ij= • Truncated Taylor series is then
f(x+s)=f(x)+Jf(x)s• And we use iteration:x0=initial guesssolve Jf(xk)sk=-f(sk) for sk
xk+1 = xk + sk
Solving NLE’s: Newton’s MethodExample: Solve f(x)=(x-2)2 -4=0Start at say x=-2
*Notice how much faster Newton’s Method converges • For linear equations it converges in one step• Why?• Newton has “quadratic convergence”• Interval bisection has “linear convergence”
Xi f(xi) f‘(xi)
-2 12 -8
-0.5 2.25 -5
-0.05 0.2025 -4.1
-0.0006 0.0024
Summary
• 2 methods for solving systems of linear equations• 2 methods for solving non-linear equations• Discussed convergence and computational efficiency
• Please contact me with any questions about this or the rest of class.