40 likes | 158 Vues
This document provides essential programming tips for using while loops and performing comparisons in the context of numerical methods for chemical engineers. Written by Daniel Baur from ETH Zurich's Institute for Chemical and Bioengineering, it details strategies to prevent infinite loops and directly compare vectors and matrices. Additionally, an addendum discusses the implicit trapezoid method, highlighting the efficiency of using a constant Jacobian matrix. For more insights and resources, visit the Morbidelli Group's educational page.
E N D
Programming Tips:While Loops and Comparisons Daniel BaurETH Zurich, Institut für Chemie- und BioingenieurwissenschaftenETH Hönggerberg / HCI F128 – ZürichE-Mail: daniel.baur@chem.ethz.chhttp://www.morbidelli-group.ethz.ch/education/index Daniel Baur / Numerical Methods for Chemical Engineerse
While Loops with limited Iterations • In order to keep a while loop from iterating forever, use one of the following two schemes: Daniel Baur / Numerical Methods for Chemical Engineerse
Comparing Entire Vectors and Matrices • The easiest way to compare two vectors or matrices is to do it directly: Daniel Baur / Numerical Methods for Chemical Engineerse
Addendum: Implicit Trapezoid Method • If the Jacobian matrix is constant, there is no need to solve linear systems in the iteration equations: • Where A can be calculated once using • A = (I – h/2*J) \ (I + h/2*J); Daniel Baur / Numerical Methods for Chemical Engineerse