Solution of Nonlinear Functions

Slides:



Advertisements
Similar presentations
M. Dumbser 1 / 23 Analisi Numerica Università degli Studi di Trento Dipartimento dIngegneria Civile ed Ambientale Dr.-Ing. Michael Dumbser Lecture on Numerical.
Advertisements

Programming Tips: While Loops and Comparisons 1Daniel Baur / Numerical Methods for Chemical Engineerse Daniel Baur ETH Zurich, Institut für Chemie- und.
Boundary Value Problems and Partial Differential Equations (PDEs)
Instabilities of SVD Small eigenvalues -> m+ sensitive to small amounts of noise Small eigenvalues maybe indistinguishable from 0 Possible to remove small.
Numerical Computation Lecture 4: Root Finding Methods - II United International College.
Lecture 5 Newton-Raphson Method
Fixed point iterations and solution of non-linear functions
Numerical Solution of Nonlinear Equations
Optimization.
Partial Differential Equations (PDEs) 1Daniel Baur / Numerical Methods for Chemical Engineers / BVP and PDE Daniel Baur ETH Zurich, Institut für Chemie-
Numerical Differentiation and Quadrature (Integration) 1Daniel Baur / Numerical Methods for Chemical Engineers / Numerical Quadrature Daniel Baur ETH Zurich,
Linear Regression 1Daniel Baur / Numerical Methods for Chemical Engineers / Linear Regression Daniel Baur ETH Zurich, Institut für Chemie- und Bioingenieurwissenschaften.
Optimization of thermal processes
Separating Hyperplanes
Systems of Linear Equations
Response Surface Method Principle Component Analysis
Linear Systems of Equations Ax = b Marco Lattuada Swiss Federal Institute of Technology - ETH Institut für Chemie und Bioingenieurwissenschaften ETH Hönggerberg/
Lecture #18 EEE 574 Dr. Dan Tylavsky Nonlinear Problem Solvers.
ENGG 1801 Engineering Computing MATLAB Lecture 7: Tutorial Weeks Solution of nonlinear algebraic equations (II)
12 1 Variations on Backpropagation Variations Heuristic Modifications –Momentum –Variable Learning Rate Standard Numerical Optimization –Conjugate.
Non Linear Regression Y i = f(  x i ) +  i Marco Lattuada Swiss Federal Institute of Technology - ETH Institut für Chemie und Bioingenieurwissenschaften.
Ordinary Differential Equations (ODEs) 1Daniel Baur / Numerical Methods for Chemical Engineers / Implicit ODE Solvers Daniel Baur ETH Zurich, Institut.
Nonlinear Algebraic Systems 1.Iterative solution methods 2.Fixed-point iteration 3.Newton-Raphson method 4.Secant method 5.Matlab tutorial 6.Matlab exercise.
1cs426-winter-2008 Notes  SIGGRAPH crunch time - my apologies :-)
Linear Regression Y i =  0 +  1 x i +  i Marco Lattuada Swiss Federal Institute of Technology - ETH Institut für Chemie und Bioingenieurwissenschaften.
Ordinary Differential Equations (ODEs)
Ordinary Differential Equations (ODEs) 1Daniel Baur / Numerical Methods for Chemical Engineers / Explicit ODE Solvers Daniel Baur ETH Zurich, Institut.
Ordinary Differential Equations (ODEs) 1Daniel Baur / Numerical Methods for Chemical Engineers / Implicit ODE Solvers Daniel Baur ETH Zurich, Institut.
Ordinary Differential Equations (ODEs) 1Daniel Baur / Numerical Methods for Chemical Engineers / Explicit ODE Solvers Daniel Baur ETH Zurich, Institut.

9 1 Performance Optimization. 9 2 Basic Optimization Algorithm p k - Search Direction  k - Learning Rate or.
UNCONSTRAINED MULTIVARIABLE
Systems of Linear Equations Iterative Methods
84 b Unidimensional Search Methods Most algorithms for unconstrained and constrained optimisation use an efficient unidimensional optimisation technique.
Optimization in Engineering Design Georgia Institute of Technology Systems Realization Laboratory 101 Quasi-Newton Methods.
Application of Differential Applied Optimization Problems.
Boundary Value Problems and Least Squares Minimization
MA/CS 375 Fall MA/CS 375 Fall 2002 Lecture 31.
Newton’s Method Other Recursive Methods Modified Fixed Point Method.
Numerical Methods for Engineering MECN 3500
Quadrature rules 1Michael Sokolov / Numerical Methods for Chemical Engineers / Numerical Quadrature Michael Sokolov ETH Zurich, Institut für Chemie- und.
Numerical Differentiation and Quadrature (Integration)
Ordinary Differential Equations (ODEs) 1Michael Sokolov / Numerical Methods for Chemical Engineers / Explicit ODE Solvers Michael Sokolov ETH Zurich, Institut.
Newton’s Method, Root Finding with MATLAB and Excel
4 Numerical Methods Root Finding Secant Method Modified Secant
Circuits Theory Examples Newton-Raphson Method. Formula for one-dimensional case: Series of successive solutions: If the iteration process is converged,
linear  2.3 Newton’s Method ( Newton-Raphson Method ) 1/12 Chapter 2 Solutions of Equations in One Variable – Newton’s Method Idea: Linearize a nonlinear.
Lecture 5 - Single Variable Problems CVEN 302 June 12, 2002.
Numerical Methods Solution of Equation.
1 Chapter 6 General Strategy for Gradient methods (1) Calculate a search direction (2) Select a step length in that direction to reduce f(x) Steepest Descent.
Variations on Backpropagation.
Linear Regression 1Michael Sokolov / Numerical Methods for Chemical Engineers / Linear Regression Michael Sokolov ETH Zurich, Institut für Chemie- und.
Chapter 2-OPTIMIZATION G.Anuradha. Contents Derivative-based Optimization –Descent Methods –The Method of Steepest Descent –Classical Newton’s Method.
Linear Systems of Equations Iterative and Relaxation Methods Ax = b Marco Lattuada Swiss Federal Institute of Technology - ETH Institut für Chemie und.
INTRO TO OPTIMIZATION MATH-415 Numerical Analysis 1.
ACSL, POSTECH1 MATLAB 입문 CHAPTER 8 Numerical Calculus and Differential Equations.
Nonlinear Regression 1Michael Sokolov / Numerical Methods for Chemical Engineers / Nonlinear Regression Michael Sokolov ETH Zurich, Institut für Chemie-
Zero of a Nonlinear Function f(x) = 0
CS5321 Numerical Optimization
ENGG 1801 Engineering Computing
Zero of a Nonlinear System of Algebraic Equations f(x) = 0
Collaborative Filtering Matrix Factorization Approach
Computers in Civil Engineering 53:081 Spring 2003
Chapter 10. Numerical Solutions of Nonlinear Systems of Equations
Some Comments on Root finding
Performance Optimization
L23 Numerical Methods part 3
Programming assignment #1 Solving an elliptic PDE using finite differences Numerical Methods for PDEs Spring 2007 Jim E. Jones.
1 Newton’s Method.
Pivoting, Perturbation Analysis, Scaling and Equilibration
Presentation transcript:

Solution of Nonlinear Functions Michael Sokolov ETH Zurich, Institut für Chemie- und Bioingenieurwissenschaften ETH Hönggerberg / HCI F135 – Zürich E-Mail: michael.sokolov@chem.ethz.ch http://www.morbidelli-group.ethz.ch/education/index Michael Sokolov / Numerical Methods for Chemical Engineers / Nonlinear Equations

Zero of a Nonlinear Function Problem definition: Find the solution of the equation f(x) = 0 for scalar valued f and x; Look for the solution either in An interval, generally –∞ < x < ∞ In the uncertainty interval [a, b], where f(a)f(b) < 0 Types of algorithms available: Bisection method Substitution methods Methods based on function approximation Assumptions: In the defined intervals, at least one solution exists We are looking for one solution, not all of them Michael Sokolov / Numerical Methods for Chemical Engineers / Nonlinear Equations

Fixed point iterations Fixed point iterations generally have the form A fixed point of F is a point x*, where A fixed point iteration is called consistent with a non-linear equation f(x), if Michael Sokolov / Numerical Methods for Chemical Engineers / Nonlinear Equations

Convergence order of fixed point iterations For any (converging) fixed point iteration, we can write where c is the rate of convergence and q is the convergence order If we take the logarithm on both sides, we get Which we can use to fit an average q and c Michael Sokolov / Numerical Methods for Chemical Engineers / Nonlinear Equations

Solution of Nonlinear Equation Systems Michael Sokolov ETH Zurich, Institut für Chemie- und Bioingenieurwissenschaften ETH Hönggerberg / HCI F135 – Zürich E-Mail: michael.sokolov@chem.ethz.ch http://www.morbidelli-group.ethz.ch/education/index Michael Sokolov / Numerical Methods for Chemical Engineers / Nonlinear Equations

Zero of Nonlinear Equation Systems Problem definition: Find the solution of F(x) = 0, where both F and x are vector (or matrix) valued; Look for the solution either In an interval xlb < x < xub Types of algorithm available: Substitution algorithms Methods based on function approximation Assumptions: At least one zero exists in the defined interval We are looking for one zero, not all of them Michael Sokolov / Numerical Methods for Chemical Engineers / Nonlinear Equations

Function linearization Let us again consider Taylor expansion In matrix form, this reads Which is equivalent to Newton Method! Michael Sokolov / Numerical Methods for Chemical Engineers / Nonlinear Equations

The Jacobian matrix Consider a continuous, differentiable function Michael Sokolov / Numerical Methods for Chemical Engineers / Nonlinear Equations

The Multidimensional Newton-Algorithm Define a starting point x Compute –f(x) Compute J(x) Either analytically or numerically Solve the linear system of equations J(x)*Δx = -f(x) for Δx, then set x = x + Δx Iterate 2 through 4 until some stopping criteria are fulfilled Michael Sokolov / Numerical Methods for Chemical Engineers / Nonlinear Equations

Improvements on the Algorithm It might not be necessary to compute the Jacobian at every iteration, the algorithm can also work nicely if the Jacobian is only computed every few iterations When doing this, instead of solving the linear system of equations, it might be more efficient to compute inv(J) when recomputing J, or factorize it in a convenient manner A numerical Jacobian can sometimes lead to better (numerical) results than an analytical one Another option is to adapt the step size, so before accepting a Δx, one checks if norm(f(x+Δx)) is in fact smaller than norm(f(x)), and if not, a step of size λ*Δx with λ < 1 is tried instead Michael Sokolov / Numerical Methods for Chemical Engineers / Nonlinear Equations

How does Matlab do it? Nonlinear Systems fsolve is the general solver for non-linear equation systems; It can use different algorithms, namely Trust-region algorithms: Instead of just going in the direction that the Newton step suggests, a check is performed if xk+1 is really better than xk. This is done by approximating the behavior of the (maximally quadratic) function around xk (the trust-region). An optimization is then performed to find an optimal step. Trust-region-dogleg: The so-called dogleg method is used to solve the optimization problem, which constructs the step as a convex combination of the Cauchy step (steepest descent) and a Gauss- Newton step. Trust-region-reflective: The optimization problem is solved via a conjugate gradient method in a 2-D subspace. The Levenberg-Marquardt method, which finds the step by solving Michael Sokolov / Numerical Methods for Chemical Engineers / Nonlinear Equations

Matlab Syntax Hints fsolve uses the syntax x = fsolve(nl_fun, x0, options); where nl_fun is a function taking as input x, returning as output the function values f at x, both can be vectors or matrices x0 is an initial guess options can be set by options = optimset(...) to choose algorithms, give analytical Jacobians, etc.; see doc fsolve for details Michael Sokolov / Numerical Methods for Chemical Engineers / Nonlinear Equations

Exercise: CSTR with multiple reactions Consider a CSTR where two reactions take place We assume the following V = const., i.e. Qin = Qout = const. Constant temperature and density of the reaction mixture Constant feed, i.e. cA,in = const., cB,in = const. Michael Sokolov / Numerical Methods for Chemical Engineers / Nonlinear Equations

CSTR mass balance (Accumulation) = Flow*(In – Out) + Reaction Michael Sokolov / Numerical Methods for Chemical Engineers / Nonlinear Equations

CSTR steady state where is the residence time Michael Sokolov / Numerical Methods for Chemical Engineers / Nonlinear Equations

Assignment 1 For each of the iterative formulas try to find a fixed point Define a starting guess x0 between 0 and 1 while abs(xk – xk-1) > 1e-8, calculate the next x value Store the values calculated in a vector xvec Also terminate the while-loop if 1e5 iterations are exceeded Is there a fixed point and is it consistent with (1)? Estimate the convergence orders and the rates of convergence for the formulas which have a fixed point Calculate dX = log(abs(diff(xvec))); Set X = dX(1:end-1); and Y = dX(2:end); Perform a linear fit with p = polyfit(X,Y,1); Calculate q and c from the fitting coefficients in p, remember that Michael Sokolov / Numerical Methods for Chemical Engineers / Nonlinear Equations

Assignment 2 Write down the analytical Jacobian matrix for the steady state CSTR shown on slide 15. Implement the basic Newton method as shown on slide 5. Use a function of the form function [x, info] = newtonMethod(f, J, x0, tol); where f is a function handle to the function you want to solve, J is a function handle that returns the Jacobian matrix, x0 is an initial guess and tol is a vector of tolerances. As in with the secand method, use a while loop to find the solution. Suggest stopping criteria and failure checks. When can the Newton method fail in general? Use left division «\» to solve the linear system at every iteration (do not use inv(J)!) Let info be a struct you can use to return additional information, like reason of termination and number of steps needed. Michael Sokolov / Numerical Methods for Chemical Engineers / Nonlinear Equations

Assignment 2 (continued) Use your Newton algorithm to solve the steady state CSTR numerically. Create two function files; one that calculates the CSTR equations (1) as functions of x, and one that calculates the analytical Jacobian as a function of x. Use xIn1 = 1; xIn2 = 1.5; k1 = 0.5; k2 = 10; and τ = 5 What is the total conversion of A to D? Compare your result to what fsolve() finds. Try different starting guesses. Can you find more than one solution? Find online the function jacobianest. Modify your Newton algorithm so that it uses jacobianest to approximate the Jacobian if the input J is empty (use isempty(J) to check). To provide an empty input, use [] in the call. How many steps are required with the analytical Jacobian compared to the numerical Jacobian? Which algorithm takes longer? Michael Sokolov / Numerical Methods for Chemical Engineers / Nonlinear Equations