Lecture 8: Euler s Methods
|
|
- Myra Harris
- 5 years ago
- Views:
Transcription
1 Lecture 8: Euler s Methods Forward Euler Method The formula for the forward Euler method is given by equation (8.2) in the lecture note for week 8, as y i+1 = y i + f(x i, y i )h. (1) where f(x i, y i ) is the differential equation evaluated at x i and y i. The implementation of this equation in Matlab or Python is quite straightforward, because the calculation of y i+1 requires known quantities that have been previously calculated, which is y i. Because of the straightforward calculation, the forward Euler method is also referred to as explicit method. The first step is to calculate dy/dx = f(x i, y i ) at x i and y i. Evaluating differential equations dy/dx is done by using feval function. In Matlab, the feval function is already provided as a built-in function. However, in Python we have to manually define or create this function. For example, we name the function feval and return the evaluated function using the Python s built-in command eval, as follows: def feval ( funcname, * args ): return eval ( funcname )(* args ) We have briefly learned in lecture 7 on how to pass arguments using the asterisk symbol. See file withargs firstordermethods.py. To test this function/method, create a.py file (name the file, for example: example feval.py ). See an example of this file in lecture 7. import numpy as np import math def feval ( funcname, * args ): return eval ( funcname )(* args ) a = feval ( np.cos, np.pi) 1
2 print (" Cos (pi) =", a) b = feval ( math. log, 1000, 10) print (" Log10 ( 1000 ) =", round (b)) def myfunc (x): return x ** 2 cin = 9.0 c = feval ( myfunc, cin ) print ("If x =", str ( cin ), " then x**2 =", c) Running the file will result in the following outputs: Cos (pi) = -1.0 Log10 ( 1000 ) = 3 If x = 9.0 then x ** 2 = 81.0 The next step is to solve for y i+1 by directly implementing the above equation (1). We create a function to implement the forward method. The function takes in several input arguments to be used in calculating y i+1. The input arguments consist of the ODE(s) to be solved (we refer to it as func), initial condition(s) of the ODE(s) (yinit), the range of interval where the ODE(s) to be evaluated (x range), and the step size (h). The function definition with the input arguments mentioned above can be written as follows, def forwardeuler ( func, yinit, x_range, h): We have to make the function as general as possible, and that includes the ability to solve a system of ODEs. The function needs to know how many ODEs to be solved, hence we do this by calculating the length of yinit using the command len. The interval x range also needs to be divided into smaller subintervals whose length is fixed and defined by the step size h. The number of subintervals, along with the number of ODEs to be solved, all will be used in identifying the number of iterations, hence they must be of integer values. After the function definition, we add the following lines: numofodes = len ( yinit ) sub_intervals = int (( x_range [-1] - x_range [0])/h) Next, we initialize variables x and y and fill them with the values from inputs passed in the function definition, x = x_range [0] y = yinit We also need to initialize other variables, xsol and ysol, which will be used as containers to save the results of calculation of x and y after each iteration. The first element of each of these containers is filled with the initial values of x and y, respectively, 2
3 xsol ysol = [x] = [y[0]] After initializations of all variables required in the calculation are done, the next thing do is to calculate the derivative f(x i, y i ). As has been explained above, the derivative can be evaluated using the feval function as follows, yprime = feval (func, x, y) and apply the derivative in to the equation (1), y[j] = y[j] + h* yprime [j] Then we increase the position of x and store the new value in xsol, x += h xsol. append (x) The new value of y (which is the y i+1 ) is also stored in ysol. If there are multiple ODEs, the value of each y m i+1 (where m is the number of ODEs) that has been solved is stored one after the other, such as [y 1 1, y 2 1, y 3 1,, y 1 2, y 2 2, y 3 2, ]. Likewise is the arrangement in ysol, hence our algorithm needs to access each value of y and uses the following commands, ysol. append (y[r]) and this completes one cycle of iteration. The calculation starts over again from the initial loop, and so on. Our function returns the values of calculated x and y stored in xsol and ysol. The full implementation of the forward method can be done as follows (see ex1 forwardeuler.py ), def forwardeuler ( func, yinit, x_range, h): This method performs the forward Euler method steps. numofodes = len ( yinit ) # Number of ODEs sub_intervals = int (( x_range [-1] - x_range [0])/h) # Number of sub - intervals x = x_ range [ 0] # Initialize variables x y = yinit # Initialize variables y # Containers for list of solutions xsol = [x] ysol = [y[0]] 3
4 for i in range ( sub_ intervals ): yprime = feval ( func, x, y) # Evaluate dy/ dx y[j] = y[j] + h* yprime [j] # Eq. (8.2) x + = h # Increase the x- step xsol. append ( x) # Save it in the container ysol. append (y[r]) # Save all new y s return [ xsol, ysol ] When using Numpy, there are little changes such as the following (see ex1 forwardeuler Numpy.py ): To create an empty list/array for container to store solutions, xsol = np. empty (0) ysol = np. empty (0) To fill the first element of the container, xsol = np. append (xsol, x) ysol = np. append (ysol, y) To save the solution x in xsol, xsol = np. append (xsol, x) and ysol, ysol = np. append (ysol, y[r]) Backward Euler Method The formula for the backward Euler method is given by equation (8.19) in the lecture note, y i+1 = y i + f(x i+1, y i+1 )h. (2) In this formulation, we first need to calculate the derivative at i + 1, i.e., y i+1 = f(x i+1, y i+1 ), (3) 4
5 which is a bit tricky because at present (at i) we obviously don t have the future value (at i + 1) of y i+1. Hence, the backward method is referred to as being implicit. To solve such problem, we do calculation by hand using the example equation, dy dx Let s take i = 0, and the equation (2) becomes = 3(1 + x) y (4) y 1 = y 0 + f(x 1, y 1 )h = y 0 + y 1h, (5) where, using the example equation (4), the derivative of y 1 is y 1 = f(x 1, y 1 ) = 3(1 + x 1 ) y 1 (6) Substituting y 1 of the equation (5) into equation (6) gives us y 1 = 3(1 + x 1 ) (y 0 + y 1h). Equating all terms of y 1 on the left hand side, we get from which, we can formulate y i+1 as y 1 + hy 1 = 3(1 + x 1 ) y 0 y 1(1 + h) = 3(1 + x 1 ) y 0 ] y 1 1 = [3(1 + x 1 ) y 0, (7) 1 + h In Python, the implementation of y i+1 can be represented by yprime = feval (func, x+h, y) yp = mult ( yprime, 1/(1+h)) y i+1 = h f(x i+1, y i ). (8) where, the formulation of yp is equal to y i+1. Here we use a function called mult to perform element-wise multiplication operation of yprime (which is a vector or Python s list of single value) and (1/(1+h)) (which is a scalar). The function mult is defined as follows, def mult ( vector, scalar ): newvector = [0]* len ( vector ) for i in range ( len ( vector )): newvector [i] = vector [i]* scalar return newvector 5
6 Without defining and using the mult function, direct multiplication (using the asterisk) of list and scalar will result in repetition of the whole list, such as >>> a = [1.0] >>> b = 3*a >>> b [1.0, 1.0, 1.0] However, when using Numpy, the product of vector/array/list and scalar is done directly, hence there is no need to involve the mult function, yprime = feval (func, x+h, y) yp = yprime * (1/(1+h)) or, even directly with one line of assignment: yprime = feval (func, x+h, y)/(1+h) The full backward method can be implemented in a function as follows, def backwardeuler ( func, yinit, x_range, h): numofodes = len ( yinit ) sub_intervals = int (( x_range [-1] - x_range [0])/h) x = x_range [0] y = yinit xsol ysol = [x] = [y[0]] for i in range ( sub_ intervals ): yprime = feval (func, x+h, y) yp = mult ( yprime, (1/(1+h))) y[j] = y[j] + h*yp[j] x += h xsol. append (x) ysol. append (y[r]) return [ xsol, ysol ] 6
7 Heun s Method This method is formulated as in equation (8.15) in the lecture note, y i+1 = y i + h 2 f(x i, y i ) + h 2 f(x i+1, y 0 i+1), (9) where y 0 i+1 = y i + f(x i, y i )h. (10) To break it down, in our Python code the derivative f(x i, y i ) is represented by, y0prime = feval (func, x, y) while the second term on the right hand side of equation (10) or multiplication of f(x i, y i ) and h is represented by k1 = mult ( y0prime, h) the predictor equation (10) is coded as (element-wise addition of arrays) ypredictor = [u + v for u, v in zip (y, k1)] or if using Numpy, the element-wise addition operation can be done directly: ypredictor = y + k1 the derivative with predictor equation f(x i+1, y 0 i+1) is represented by, y1prime = feval ( func, x +h, ypredictor ) and the equation for Heun s method in (9) is represented by y[j] = y[j] + (h/2)* y0prime [j] + (h/2)* y1prime [j] The full function for implementing Heun s method is given by def HeunsMethod ( func, yinit, x_range, h): numofodes = len ( yinit ) sub_intervals = int (( x_range [-1] - x_range [0])/h) x = x_range [0] y = yinit xsol ysol = [x] = [y[0]] 7
8 for i in range ( sub_ intervals ): y0prime = feval (func, x, y) k1 = mult ( y0prime, h) ypredictor = [u + v for u, v in zip (y, k1)] y1prime = feval ( func, x +h, ypredictor ) y[j] = y[j] + (h/2)* y0prime [j] + (h/2)* y1prime [j] x += h xsol. append (x) ysol. append (y[r]) return [ xsol, ysol ] Midpoint Method The midpoint method is formulated as in equation (8.16) of the lecture note, where y i+1 = y i + hf(x i+ 1, y 2 i+ 1 ), (11) 2 y i+ 1 2 = y i + h 2 f(x i, y i ). (12) Python implementation of the midpoint method is almost similar to the implementation of Heun s method, except for the second term on the right hand side of equation (12) or h 2 f(x i, y i ) is coded as k1 = mult ( y0prime, h/2) and the derivative in equation (11) or f(x i+ 1, y 2 i+ 1 ) is represented by 2 y1prime = feval (func, x+h/2, ypredictor ) and the midpoint equation (11), y[j] = y[j] + h* y1prime [j] 8
9 The full function for midpoint method is given by def midpoint (func, yinit, x_range, h): numofodes = len ( yinit ) sub_intervals = int (( x_range [-1] - x_range [0])/h) x = x_range [0] y = yinit xsol ysol = [x] = [y[0]] for i in range ( sub_ intervals ): y0prime = feval (func, x, y) k1 = mult ( y0prime, h/2) ypredictor = [u + v for u, v in zip (y, k1)] y1prime = feval (func, x+h/2, ypredictor ) y[j] = y[j] + h* y1prime [j] x += h xsol. append (x) ysol. append (y[r]) return [ xsol, ysol ] 9
Euler s Methods (a family of Runge- Ku9a methods)
Euler s Methods (a family of Runge- Ku9a methods) ODE IVP An Ordinary Differential Equation (ODE) is an equation that contains a function having one independent variable: The equation is coupled with an
More informationODE IVP. An Ordinary Differential Equation (ODE) is an equation that contains a function having one independent variable:
Euler s Methods ODE IVP An Ordinary Differential Equation (ODE) is an equation that contains a function having one independent variable: The equation is coupled with an initial value/condition (i.e., value
More informationover The idea is to construct an algorithm to solve the IVP ODE (9.1)
Runge- Ku(a Methods Review of Heun s Method (Deriva:on from Integra:on) The idea is to construct an algorithm to solve the IVP ODE (9.1) over To obtain the solution point we can use the fundamental theorem
More informationover The idea is to construct an algorithm to solve the IVP ODE (8.1)
Runge- Ku(a Methods Review of Heun s Method (Deriva:on from Integra:on) The idea is to construct an algorithm to solve the IVP ODE (8.1) over To obtain the solution point we can use the fundamental theorem
More informationMATH2071: LAB 2: Explicit ODE methods
MATH2071: LAB 2: Explicit ODE methods 1 Introduction Introduction Exercise 1 Euler s method review Exercise 2 The Euler Halfstep (RK2) Method Exercise 3 Runge-Kutta Methods Exercise 4 The Midpoint Method
More informationUser-Defined Function
ENGR 102-213 (Socolofsky) Week 11 Python scripts In the lecture this week, we are continuing to learn powerful things that can be done with userdefined functions. In several of the examples, we consider
More informationApplication 2.4 Implementing Euler's Method
Application 2.4 Implementing Euler's Method One's understanding of a numerical algorithm is sharpened by considering its implementation in the form of a calculator or computer program. Figure 2.4.13 in
More informationOrdinary differential equations solving methods
Radim Hošek, A07237 radhost@students.zcu.cz Ordinary differential equations solving methods Problem: y = y2 (1) y = x y (2) y = sin ( + y 2 ) (3) Where it is possible we try to solve the equations analytically,
More informationQueens College, CUNY, Department of Computer Science Numerical Methods CSCI 361 / 761 Spring 2018 Instructor: Dr. Sateesh Mane.
Queens College, CUNY, Department of Computer Science Numerical Methods CSCI 361 / 761 Spring 2018 Instructor: Dr. Sateesh Mane c Sateesh R. Mane 2018 16 Lecture 16 May 3, 2018 Numerical solution of systems
More informationChE 400: Applied Chemical Engineering Calculations Tutorial 6: Numerical Solution of ODE Using Excel and Matlab
ChE 400: Applied Chemical Engineering Calculations Tutorial 6: Numerical Solution of ODE Using Excel and Matlab Tutorial 6: Numerical Solution of ODE Gerardine G. Botte This handout contains information
More informationFront page. UNIVERSITY OF OSLO Faculty of mathematics and natural sciences
Front page UNIVERSITY OF OSLO Faculty of mathematics and natural sciences Examination in: IN1900/INF1100 Introduction to programming for scientific applications Day of examination: December 18th 2017 Examination
More informationModule 2: Single Step Methods Lecture 4: The Euler Method. The Lecture Contains: The Euler Method. Euler's Method (Analytical Interpretations)
The Lecture Contains: The Euler Method Euler's Method (Analytical Interpretations) An Analytical Example file:///g /Numerical_solutions/lecture4/4_1.htm[8/26/2011 11:14:40 AM] We shall now describe methods
More informationDifferentiation. The Derivative and the Tangent Line Problem 10/9/2014. Copyright Cengage Learning. All rights reserved.
Differentiation Copyright Cengage Learning. All rights reserved. The Derivative and the Tangent Line Problem Copyright Cengage Learning. All rights reserved. 1 Objectives Find the slope of the tangent
More informationODEs occur quite often in physics and astrophysics: Wave Equation in 1-D stellar structure equations hydrostatic equation in atmospheres orbits
Solving ODEs General Stuff ODEs occur quite often in physics and astrophysics: Wave Equation in 1-D stellar structure equations hydrostatic equation in atmospheres orbits need workhorse solvers to deal
More informationOrdinary Differential Equations
Next: Partial Differential Equations Up: Numerical Analysis for Chemical Previous: Numerical Differentiation and Integration Subsections Runge-Kutta Methods Euler's Method Improvement of Euler's Method
More informationEuler s Method with Python
Euler s Method with Python Intro. to Differential Equations October 23, 2017 1 Euler s Method with Python 1.1 Euler s Method We first recall Euler s method for numerically approximating the solution of
More informationComputers in Engineering Root Finding Michael A. Hawker
Computers in Engineering COMP 208 Root Finding Michael A. Hawker Root Finding Many applications involve finding the roots of a function f(x). That is, we want to find a value or values for x such that
More informationReview Initial Value Problems Euler s Method Summary
THE EULER METHOD P.V. Johnson School of Mathematics Semester 1 2008 OUTLINE 1 REVIEW 2 INITIAL VALUE PROBLEMS The Problem Posing a Problem 3 EULER S METHOD Method Errors 4 SUMMARY OUTLINE 1 REVIEW 2 INITIAL
More informationMATLAB Lecture 4. Programming in MATLAB
MATLAB Lecture 4. Programming in MATLAB In this lecture we will see how to write scripts and functions. Scripts are sequences of MATLAB statements stored in a file. Using conditional statements (if-then-else)
More informationMath 225 Scientific Computing II Outline of Lectures
Math 225 Scientific Computing II Outline of Lectures Spring Semester 2003 I. Interpolating polynomials Lagrange formulation of interpolating polynomial Uniqueness of interpolating polynomial of degree
More informationDifferentiation. J. Gerlach November 2010
Differentiation J. Gerlach November 200 D and diff The limit definition of the derivative is covered in the Limit tutorial. Here we look for direct ways to calculate derivatives. Maple has two commands
More informationRendering. A simple X program to illustrate rendering
Rendering A simple X program to illustrate rendering The programs in this directory provide a simple x based application for us to develop some graphics routines. Please notice the following: All points
More informationMath 104: Euler s Method and Applications of ODEs
Math 104: Euler s Method and Applications of ODEs Ryan Blair University of Pennsylvania Tuesday January 29, 2013 Ryan Blair (U Penn) Math 104:Euler s Method and Applications of ODEsTuesday January 29,
More informationB. Examples Set up the integral(s) needed to find the area of the region bounded by
Math 176 Calculus Sec. 6.1: Area Between Curves I. Area between the Curve and the x Axis A. Let f(x) 0 be continuous on [a,b]. The area of the region between the graph of f and the x-axis is A = f ( x)
More informationPython Crash Course Numpy, Scipy, Matplotlib
Python Crash Course Numpy, Scipy, Matplotlib That is what learning is. You suddenly understand something you ve understood all your life, but in a new way. Doris Lessing Steffen Brinkmann Max-Planck-Institut
More informationUNIVERSITETET I OSLO
UNIVERSITETET I OSLO Det matematisk-naturvitenskapelige fakultet Examination in: INF1100 Introduction to programming with scientific applications Day of examination: Wednesday, December 18, 2013 Examination
More informationIntroducing Python Modules
Introducing Python Modules Based on CBSE Curriculum Class -11 By- Neha Tyagi PGT CS KV 5 Jaipur II Shift Jaipur Region Neha Tyagi, PGT CS II Shift Jaipur Introduction A book is generally divided into chapters.
More informationJohn Perry. Spring 2016
MAT 305: Repeating a task on a set (or list, or tuple, or...) University of Southern Mississippi Spring 2016 Outline 1 2 3 4 5 6 7 Outline 1 2 3 4 5 6 7 Differential Equations What is y in terms of x?
More informationmultiprocessing HPC Python R. Todd Evans January 23, 2015
multiprocessing HPC Python R. Todd Evans rtevans@tacc.utexas.edu January 23, 2015 What is Multiprocessing Process-based parallelism Not threading! Threads are light-weight execution units within a process
More informationCS2304: Python for Java Programmers. CS2304: Sequences and Collections
CS2304: Sequences and Collections Sequences In Python A sequence type in python supports: The in membership operator. The len() function. Slicing like we saw with strings, s[1:3]. And is iterable (for
More informationENGR 102 Engineering Lab I - Computation
ENGR 102 Engineering Lab I - Computation Learning Objectives by Week 1 ENGR 102 Engineering Lab I Computation 2 Credits 2. Introduction to the design and development of computer applications for engineers;
More informationx n x n stepnumber k order r error constant C r+1 1/2 5/12 3/8 251/720 abs. stab. interval (α,0) /11-3/10
MATH 573 LECTURE NOTES 77 13.8. Predictor-corrector methods. We consider the Adams methods, obtained from the formula xn+1 xn+1 y(x n+1 y(x n ) = y (x)dx = f(x,y(x))dx x n x n by replacing f by an interpolating
More informationMathematical Methods and Modeling Laboratory class. Numerical Integration of Ordinary Differential Equations
Mathematical Methods and Modeling Laboratory class Numerical Integration of Ordinary Differential Equations Exact Solutions of ODEs Cauchy s Initial Value Problem in normal form: Recall: if f is locally
More informationCh.2: Loops and lists
Ch.2: Loops and lists Joakim Sundnes 1,2 Hans Petter Langtangen 1,2 Simula Research Laboratory 1 University of Oslo, Dept. of Informatics 2 Aug 29, 2018 Plan for 28 August Short quiz on topics from last
More informationCOMP519 Web Programming Lecture 20: Python (Part 4) Handouts
COMP519 Web Programming Lecture 20: Python (Part 4) Handouts Ullrich Hustadt Department of Computer Science School of Electrical Engineering, Electronics, and Computer Science University of Liverpool Contents
More informationENGR 102 Engineering Lab I - Computation
ENGR 102 Engineering Lab I - Computation Week 07: Arrays and Lists of Data Introduction to Arrays In last week s lecture, 1 we were introduced to the mathematical concept of an array through the equation
More informationThe Euler and trapezoidal stencils to solve d d x y x = f x, y x
restart; Te Euler and trapezoidal stencils to solve d d x y x = y x Te purpose of tis workseet is to derive te tree simplest numerical stencils to solve te first order d equation y x d x = y x, and study
More informationAMSC/CMSC 460 Final Exam, Fall 2007
AMSC/CMSC 460 Final Exam, Fall 2007 Show all work. You may leave arithmetic expressions in any form that a calculator could evaluate. By putting your name on this paper, you agree to abide by the university
More informationHow To Think Like A Computer Scientist, chapter 3; chapter 6, sections
6.189 Day 3 Today there are no written exercises. Turn in your code tomorrow, stapled together, with your name and the file name in comments at the top as detailed in the Day 1 exercises. Readings How
More informationDirection Fields; Euler s Method
Direction Fields; Euler s Method It frequently happens that we cannot solve first order systems dy (, ) dx = f xy or corresponding initial value problems in terms of formulas. Remarkably, however, this
More informationJohn Perry. Fall 2013
Repeating a task on a set (or list, or tuple, or... ) University of Southern Mississippi Fall 2013 Outline 1 2 3 4 5 Outline 1 2 3 4 5 ? We often have to repeat a computation that is not a mere operation,
More informationEuler s Method for Approximating Solution Curves
Euler s Method for Approximating Solution Curves As you may have begun to suspect at this point, time constraints will allow us to learn only a few of the many known methods for solving differential equations.
More informationMath (Spring 2009): Lecture 5 Planes. Parametric equations of curves and lines
Math 18.02 (Spring 2009): Lecture 5 Planes. Parametric equations of curves and lines February 12 Reading Material: From Simmons: 17.1 and 17.2. Last time: Square Systems. Word problem. How many solutions?
More informationRendering. A simple X program to illustrate rendering
Rendering A simple X program to illustrate rendering The programs in this directory provide a simple x based application for us to develop some graphics routines. Please notice the following: All points
More information16.1 Runge-Kutta Method
70 Chapter 6. Integration of Ordinary Differential Equations CITED REFERENCES AND FURTHER READING: Gear, C.W. 97, Numerical Initial Value Problems in Ordinary Differential Equations (Englewood Cliffs,
More informationIntroduction to Scientific Computing with Python, part two.
Introduction to Scientific Computing with Python, part two. M. Emmett Department of Mathematics University of North Carolina at Chapel Hill June 20 2012 The Zen of Python zen of python... fire up python
More informationRasterization: Geometric Primitives
Rasterization: Geometric Primitives Outline Rasterizing lines Rasterizing polygons 1 Rasterization: What is it? How to go from real numbers of geometric primitives vertices to integer coordinates of pixels
More informationMath 1206 Calculus Sec. 5.6: Substitution and Area Between Curves (Part 2) Overview of Area Between Two Curves
Math 1206 Calculus Sec. 5.6: Substitution and Area Between Curves (Part 2) III. Overview of Area Between Two Curves With a few modifications the area under a curve represented by a definite integral can
More informationName: Signature: Section and TA:
Name: Signature: Section and TA: Math 7. Lecture 00 (V. Reiner) Midterm Exam I Thursday, February 8, 00 This is a 50 minute exam. No books, notes, calculators, cell phones or other electronic devices are
More informationUnit testing with pytest and nose 1
Unit testing with pytest and nose 1 Hans Petter Langtangen 1,2 1 Center for Biomedical Computing, Simula Research Laboratory 2 Department of Informatics, University of Oslo Mar 23, 2015 Contents 1 Requirements
More informationGeometric Modeling Assignment 3: Discrete Differential Quantities
Geometric Modeling Assignment : Discrete Differential Quantities Acknowledgements: Julian Panetta, Olga Diamanti Assignment (Optional) Topic: Discrete Differential Quantities with libigl Vertex Normals,
More informationDigital Differential Analyzer Bresenhams Line Drawing Algorithm
Bresenham s Line Generation The Bresenham algorithm is another incremental scan conversion algorithm. The big advantage of this algorithm is that, it uses only integer calculations. Difference Between
More informationPolynomial Approximation and Interpolation Chapter 4
4.4 LAGRANGE POLYNOMIALS The direct fit polynomial presented in Section 4.3, while quite straightforward in principle, has several disadvantages. It requires a considerable amount of effort to solve the
More informationSlides from INF3331 lectures optimizing Python code
Slides from INF3331 lectures optimizing Python code p. 1/20 Slides from INF3331 lectures optimizing Python code Ola Skavhaug, Joakim Sundnes and Hans Petter Langtangen Dept. of Informatics, Univ. of Oslo
More informationIntegration. Volume Estimation
Monte Carlo Integration Lab Objective: Many important integrals cannot be evaluated symbolically because the integrand has no antiderivative. Traditional numerical integration techniques like Newton-Cotes
More informationMTH 122 Calculus II Essex County College Division of Mathematics and Physics 1 Lecture Notes #11 Sakai Web Project Material
MTH Calculus II Essex County College Division of Mathematics and Physics Lecture Notes # Sakai Web Project Material Introduction - - 0 - Figure : Graph of y sin ( x y ) = x cos (x + y) with red tangent
More informationDiscussion 1H Notes (Week 3, April 14) TA: Brian Choi Section Webpage:
Discussion 1H Notes (Week 3, April 14) TA: Brian Choi (schoi@cs.ucla.edu) Section Webpage: http://www.cs.ucla.edu/~schoi/cs31 More on Arithmetic Expressions The following two are equivalent:! x = x + 5;
More informationSimulation in Computer Graphics. Particles. Matthias Teschner. Computer Science Department University of Freiburg
Simulation in Computer Graphics Particles Matthias Teschner Computer Science Department University of Freiburg Outline introduction particle motion finite differences system of first order ODEs second
More informationAn introduction introduction to functional functional programming programming using usin Haskell
An introduction to functional programming using Haskell Anders Møller amoeller@cs.au.dkau Haskell The most popular p purely functional, lazy programming g language Functional programming language : a program
More informationMath Homework 3
Math 0 - Homework 3 Due: Friday Feb. in class. Write on your paper the lab section you have registered for.. Staple the sheets together.. Solve exercise 8. of the textbook : Consider the following data:
More informationPython review. 1 Python basics. References. CS 234 Naomi Nishimura
Python review CS 234 Naomi Nishimura The sections below indicate Python material, the degree to which it will be used in the course, and various resources you can use to review the material. You are not
More informationIterators & Generators
Iterators & Generators Sequences A sequence is something that you can: Index into Get the length of What are some examples of sequences? Sequences We ve been working with sequences all semester! Examples:
More informationPython Programming Exercises 1
Python Programming Exercises 1 Notes: throughout these exercises >>> preceeds code that should be typed directly into the Python interpreter. To get the most out of these exercises, don t just follow them
More informationCS 130. Scan Conversion. Raster Graphics
CS 130 Scan Conversion Raster Graphics 2 1 Image Formation Computer graphics forms images, generally two dimensional, using processes analogous to physical imaging systems like: - Cameras - Human visual
More informationCourse May 18, Advanced Computational Physics. Course Hartmut Ruhl, LMU, Munich. People involved. SP in Python: 3 basic points
May 18, 2017 3 I/O 3 I/O 3 I/O 3 ASC, room A 238, phone 089-21804210, email hartmut.ruhl@lmu.de Patrick Böhl, ASC, room A205, phone 089-21804640, email patrick.boehl@physik.uni-muenchen.de. I/O Scientific
More informationHigh Performance Computing with Python
High Performance Computing with Python Pawel Pomorski SHARCNET University of Waterloo ppomorsk@sharcnet.ca April 29,2015 Outline Speeding up Python code with NumPy Speeding up Python code with Cython Using
More informationlambda forms map(), reduce(), filter(), eval(), and apply() estimating π with list comprehensions
Outline 1 Guessing Secrets functions returning functions oracles and trapdoor functions 2 anonymous functions lambda forms map(), reduce(), filter(), eval(), and apply() estimating π with list comprehensions
More informationautograd tutorial Paul Vicol, Slides Based on Ryan Adams January 30, 2017 CSC 321, University of Toronto
autograd tutorial Paul Vicol, Slides Based on Ryan Adams January 30, 2017 CSC 321, University of Toronto 1 tutorial outline 1. Automatic Differentiation 2. Introduction to Autograd 3. IPython Notebook
More informationCSE 251 PROJECT 1. Andrew Christlieb. Monday Class AND Friday Class Abstract. Web:
CSE 51 PROJECT 1 Andrew Christlieb Monday Class 0-03-14 AND Friday Class 01-31-14 Abstract Web: http://www.cse.msu.edu/ cse51 Project 1 due date: (Monday Class) 0-17-14 AND (Friday Class)0-14-14, time:
More informationENCM 339 Fall 2017 Lecture Section 01 Lab 9 for the Week of November 20
page 1 of 9 ENCM 339 Fall 2017 Lecture Section 01 Lab 9 for the Week of November 20 Steve Norman Department of Electrical & Computer Engineering University of Calgary November 2017 Lab instructions and
More informationEL2310 Scientific Programming
Lecture 4: Programming in Matlab Yasemin Bekiroglu (yaseminb@kth.se) Florian Pokorny(fpokorny@kth.se) Overview Overview Lecture 4: Programming in Matlab Wrap Up More on Scripts and Functions Wrap Up Last
More informationWeek 2. Relational Operators. Block or compound statement. if/else. Branching & Looping. Gaddis: Chapters 4 & 5. CS 5301 Spring 2018.
Week 2 Branching & Looping Gaddis: Chapters 4 & 5 CS 5301 Spring 2018 Jill Seaman 1 Relational Operators l relational operators (result is bool): == Equal to (do not use =)!= Not equal to > Greater than
More information=.1( sin(2πx/24) y) y(0) = 70.
Differential Equations, Spring 2017 Computer Project 2, Due 11:30 am, Friday, March 10 The goal of this project is to implement the Euler Method and the Improved Euler Method, and to use these methods
More informationGoals for This Lecture:
Goals for This Lecture: Understand what function subprograms are Understand how to use function subprograms Understand the various kinds of REAL types Understand how to select precision in a processor
More informationWhat is Dan++ Work Flow Examples and Demo. Dan++: A Quick Look. Daniel Driver. April 16, 2015
Dan++: A Quick Look Daniel Driver April 16, 2015 What now 1 What is Dan++ 2 Work Flow 3 Examples and Demo What is Dan++ What is Dan++ Bread And Butter We Need F(x) : R n R m Particle Dynamics Example:
More information1.00 Lecture 19. Numerical Methods: Root Finding
1.00 Lecture 19 Numerical Methods: Root Finding short int Remember Java Data Types Type byte long float double char boolean Size (bits) 8 16 32 64 32 64 16 1-128 to 127-32,768 to 32,767-2,147,483,648 to
More informationRandom Numbers Random Walk
Random Numbers Random Walk Computational Physics Random Numbers Random Walk Outline Random Systems Random Numbers Monte Carlo Integration Example Random Walk Exercise 7 Introduction Random Systems Deterministic
More informationQueens College, CUNY, Department of Computer Science Numerical Methods CSCI 361 / 761 Fall 2018 Instructor: Dr. Sateesh Mane
Queens College, CUNY, Department of Computer Science Numerical Methods CSCI 36 / 76 Fall 28 Instructor: Dr. Sateesh Mane c Sateesh R. Mane 28 6 Homework lecture 6: numerical integration If you write the
More informationCS 61A Interpreters, Tail Calls, Macros, Streams, Iterators. Spring 2019 Guerrilla Section 5: April 20, Interpreters.
CS 61A Spring 2019 Guerrilla Section 5: April 20, 2019 1 Interpreters 1.1 Determine the number of calls to scheme eval and the number of calls to scheme apply for the following expressions. > (+ 1 2) 3
More informationComputer Simulations
Computer Simulations A practical approach to simulation Semra Gündüç gunduc@ankara.edu.tr Ankara University Faculty of Engineering, Department of Computer Engineering 2014-2015 Spring Term Ankara University
More informationScan Converting Circles
Scan Conversion Algorithms CS 460 Computer Graphics Professor Richard Eckert Circles Ellipses and Other 2-D Curves Text February 16, 2004 Scan Converting Circles Given: Center: (h,k) Radius: r Equation:
More informationHomework Project #6. Math 365, Spring Due Wednesday April 27th
Name : Homework Project #6 Math 365, Spring 2016 Due Wednesday April 27th You may work with a partner on this assignment and turn in a single assignment for the both of you. 1. (Using fzero) Consider the
More informationExercises for a Numerical Methods Course
Exercises for a Numerical Methods Course Brian Heinold Department of Mathematics and Computer Science Mount St. Mary s University November 18, 2017 1 / 73 About the class Mix of Math and CS students, mostly
More informationQuestions Q1. (a) Find the values of the constants A, B and C. (4) b) Hence find
Questions Q1. (a) Find the values of the constants A, B and C. (4) b) Hence find (ii) Find, leaving your answer in the form a + ln b, where a and b are constants. (6) (Total 10 marks) Q2. (a) Find the
More informationDefining Functions. CSc 372. Comparative Programming Languages. 5 : Haskell Function Definitions. Department of Computer Science University of Arizona
Defining Functions CSc 372 Comparative Programming Languages 5 : Haskell Function Definitions Department of Computer Science University of Arizona collberg@gmail.com When programming in a functional language
More information4.7 Approximate Integration
4.7 Approximate Integration Some anti-derivatives are difficult to impossible to find. For example, 1 0 e x2 dx or 1 1 1 + x3 dx We came across this situation back in calculus I when we introduced the
More information61A Lecture 4. Monday, September 9
61A Lecture 4 Monday, September 9 Announcements Homework 1 due Tuesday 9/10 at 5pm; Late homework is not accepted! Quiz on Wednesday 9/11 released at 1pm, due Thursday 9/12 at 11:59pm Open-computer: You
More informationMAT 275 Laboratory 3 Numerical Solutions by Euler and Improved Euler Methods (scalar equations)
MATLAB sessions: Laboratory 3 1 MAT 275 Laboratory 3 Numerical Solutions by Euler and Improved Euler Methods (scalar equations) In this session we look at basic numerical methods to help us understand
More informationChapter 2. Python Programming for Physicists. Soon-Hyung Yook. March 31, Soon-Hyung Yook Chapter 2 March 31, / 52
Chapter 2 Python Programming for Physicists Soon-Hyung Yook March 31, 2017 Soon-Hyung Yook Chapter 2 March 31, 2017 1 / 52 Table of Contents I 1 Getting Started 2 Basic Programming Variables and Assignments
More informationRemember Java Data Types
1.00 Lecture 19 October 24, 2005 Numerical Methods: Root Finding Remember Java Data Types Size Type (bits) Range byte 8-128 to 127 short 16-32,768 to 32,767 int 32-2,147,483,648 to 2,147,483,647 long 64-9,223,372,036,854,775,808L
More informationFirst of all, we need to know what it means for a parameterize curve to be differentiable. FACT:
CALCULUS WITH PARAMETERIZED CURVES In calculus I we learned how to differentiate and integrate functions. In the chapter covering the applications of the integral, we learned how to find the length of
More informationHomework 14 solutions
Section 9.1: Ex 1,5,10,15,16 Section 9.: Ex 1,8,9; AP 1-5,9 Section 9.3: AP 1-5 Section 9.1 Homework 14 solutions 1. (a) Show that y( is a solution to the differential equation by substitution. (b) Find
More informationMEI STRUCTURED MATHEMATICS METHODS FOR ADVANCED MATHEMATICS, C3. Practice Paper C3-B
MEI Mathematics in Education and Industry MEI STRUCTURED MATHEMATICS METHODS FOR ADVANCED MATHEMATICS, C3 Practice Paper C3-B Additional materials: Answer booklet/paper Graph paper List of formulae (MF)
More informationMath Analysis Chapter 1 Notes: Functions and Graphs
Math Analysis Chapter 1 Notes: Functions and Graphs Day 6: Section 1-1 Graphs Points and Ordered Pairs The Rectangular Coordinate System (aka: The Cartesian coordinate system) Practice: Label each on the
More informationFrom Ver(ces to Fragments: Rasteriza(on
From Ver(ces to Fragments: Rasteriza(on From Ver(ces to Fragments 3D vertices vertex shader rasterizer fragment shader final pixels 2D screen fragments l determine fragments to be covered l interpolate
More informationHaske k ll An introduction to Functional functional programming using Haskell Purely Lazy Example: QuickSort in Java Example: QuickSort in Haskell
Haskell An introduction to functional programming using Haskell Anders Møller amoeller@cs.au.dk The most popular purely functional, lazy programming language Functional programming language : a program
More informationLine Drawing Algorithms
Chapter 3 " Line Drawing Algorithms ~: Learning Objectives :~ The objectives of this chapter are to acquaint you with: + Scan conversion line drawing + Bresenham s line drawing + Drawing bar chart + Problems
More informationLecture 7. Memory in Python
Lecture 7 Memory in Python Announcements For This Lecture Readings Reread Chapter 3 No reading for Thursday Lab Work on Assignment Credit when submit A Nothing else to do Assignment Moved to Fri, Sep.
More information(Refer Slide Time: 00:03:51)
Computer Graphics Prof. Sukhendu Das Dept. of Computer Science and Engineering Indian Institute of Technology, Madras Lecture 17 Scan Converting Lines, Circles and Ellipses Hello and welcome everybody
More informationMAS212 Scientific Computing and Simulation
MAS212 Scientific Computing and Simulation Dr. Sam Dolan School of Mathematics and Statistics, University of Sheffield Autumn 2017 http://sam-dolan.staff.shef.ac.uk/mas212/ G18 Hicks Building s.dolan@sheffield.ac.uk
More information