Num. #1: Recalls on Numerical Methods for Linear Systems and Ordinary differential equations (ODEs) - CORRECTION

Similar documents
Num. #2: Hyperbolic PDE equation : transport equation - Correction

ChE 400: Applied Chemical Engineering Calculations Tutorial 6: Numerical Solution of ODE Using Excel and Matlab

Chemical Engineering 541

CE890 / ENE801 Lecture 1 Introduction to MATLAB

Discontinuous Galerkin Sparse Grid method for Maxwell s equations

ODEs occur quite often in physics and astrophysics: Wave Equation in 1-D stellar structure equations hydrostatic equation in atmospheres orbits

Homework Set 5 (Sections )

Simulation in Computer Graphics. Particles. Matthias Teschner. Computer Science Department University of Freiburg

Module1: Numerical Solution of Ordinary Differential Equations. Lecture 6. Higher order Runge Kutta Methods

Data-Driven Modeling. Scientific Computation J. NATHAN KUTZ OXPORD. Methods for Complex Systems & Big Data

Finite difference methods

Jason Yalim. Here we perform a few tasks to ensure a clean working environment for our script.

CS205b/CME306. Lecture 9

Contents. I Basics 1. Copyright by SIAM. Unauthorized reproduction of this article is prohibited.

Mathematics for chemical engineers

2.29 Numerical Marine Hydrodynamics Spring 2007

1/8/08 5:28 PM \\eng\files\numerical Methods\simulatio...\mtl_ode_sim_RK2ndconv.m 1 of 5

INTRODUCTION TO LINEAR AND NONLINEAR PROGRAMMING

over The idea is to construct an algorithm to solve the IVP ODE (8.1)

Solving systems of nonlinear equations with arbitrary precision

Mass-Spring Systems. Last Time?

37 Self-Assessment. 38 Two-stage Runge-Kutta Methods. Chapter 10 Runge Kutta Methods

CS 6210 Fall 2016 Bei Wang. Review Lecture What have we learnt in Scientific Computing?

MATH2071: LAB 2: Explicit ODE methods

Introduction to Optimization Problems and Methods

The Jello Cube Assignment 1, CSCI 520. Jernej Barbic, USC

Workpackage 5 - Ordinary Differential Equations

Application 7.6A The Runge-Kutta Method for 2-Dimensional Systems

Ordinary Differential Equations

Thursday 1/8 1 * syllabus, Introduction * preview reading assgt., chapter 1 (modeling) * HW review chapters 1, 2, & 3

Approximate Solutions to Differential Equations Slope Fields (graphical) and Euler s Method (numeric) by Dave Slomer

Performance Evaluation of Multiple and Mixed Precision Iterative Refinement Method and its Application to High-Order Implicit Runge-Kutta Method

Lecture 1: Introduction to Scilab

Physics Tutorial 2: Numerical Integration Methods

GPUs and Einstein s Equations

Parallel Implementations of Gaussian Elimination

Probabilistic Graphical Models

The jello cube. Undeformed cube. Deformed cube

MAT 275 Laboratory 3 Numerical Solutions by Euler and Improved Euler Methods (scalar equations)

Building More Efficient Time Parallel Solvers with Applications to Multiscale Modeling and Gyrokinetics

Math 225 Scientific Computing II Outline of Lectures

Variational Methods II

Documentation. David Grellscheid

Solving Systems of Equations Using Matrices With the TI-83 or TI-84

David G. Luenberger Yinyu Ye. Linear and Nonlinear. Programming. Fourth Edition. ö Springer

4 Visualization and. Approximation

over The idea is to construct an algorithm to solve the IVP ODE (9.1)

LAB #8 Numerical Methods

MBI REU Matlab Tutorial

Computational Methods CMSC/AMSC/MAPL 460. Vectors, Matrices, Linear Systems, LU Decomposition, Ramani Duraiswami, Dept. of Computer Science

Replacing Neural Networks with Black-Box ODE Solvers

Advanced Programming in Engineering Saurabh Srivastava, Thomas Weinhart Martin Robinson, and Stefan Luding MSM, CTW, UTwente, NL

Euler s Methods (a family of Runge- Ku9a methods)

Modelling and Simulation for Engineers

Contents Computing with Formulas

Exercises for a Numerical Methods Course

(Part - 1) P. Sam Johnson. April 14, Numerical Solution of. Ordinary Differential Equations. (Part - 1) Sam Johnson. NIT Karnataka.

Numerical Methods for Solving the Vorticity-Stream function Equations ME535 Final Project Frank Bremer June 5, 2008

THE IMPLICIT CLOSEST POINT METHOD FOR THE NUMERICAL SOLUTION OF PARTIAL DIFFERENTIAL EQUATIONS ON SURFACES

ODE IVP. An Ordinary Differential Equation (ODE) is an equation that contains a function having one independent variable:

Communications in Applied Mathematics and Computational Science

Final Report. Discontinuous Galerkin Compressible Euler Equation Solver. May 14, Andrey Andreyev. Adviser: Dr. James Baeder

Chemical Reaction Engineering - Part 4 - Integration Richard K. Herz,

Data Visualization. Fall 2017

SECOND SEMESTER BCA : Syllabus Copy

MPI OpenMP algorithms for the parallel space time solution of Time Dependent PDEs

All routines were built with VS2010 compiler, OpenMP 2.0 and TBB 3.0 libraries were used to implement parallel versions of programs.

Image Deconvolution.

Model parametrization strategies for Newton-based acoustic full waveform

C3 Numerical methods

Inverse Kinematics (part 1) CSE169: Computer Animation Instructor: Steve Rotenberg UCSD, Winter 2018

Mid-Year Report. Discontinuous Galerkin Euler Equation Solver. Friday, December 14, Andrey Andreyev. Advisor: Dr.

Solving for dynamic user equilibrium

Convolution Neural Nets meet

Math 1B03/1ZC3 - Tutorial 3. Jan. 24th/28th, 2014

Addition/Subtraction flops. ... k k + 1, n (n k)(n k) (n k)(n + 1 k) n 1 n, n (1)(1) (1)(2)

MAT 275 Laboratory 2 Matrix Computations and Programming in MATLAB

Iterative Methods for Solving Linear Problems

6. Fast Fourier Transform

MAT 275 Laboratory 3 Numerical Solutions by Euler and Improved Euler Methods (scalar equations)

Double Pendulum. Freddie Witherden. February 10, 2009

MPI OpenMP algorithms for the parallel space time solution of Time Dependent PDEs

Skåne University Hospital Lund, Lund, Sweden 2 Deparment of Numerical Analysis, Centre for Mathematical Sciences, Lund University, Lund, Sweden

Advanced Techniques for Mobile Robotics Graph-based SLAM using Least Squares. Wolfram Burgard, Cyrill Stachniss, Kai Arras, Maren Bennewitz

Semester Final Report

(Sparse) Linear Solvers

Queens College, CUNY, Department of Computer Science Numerical Methods CSCI 361 / 761 Spring 2018 Instructor: Dr. Sateesh Mane.

Introduction to Matlab

Study and implementation of computational methods for Differential Equations in heterogeneous systems. Asimina Vouronikoy - Eleni Zisiou

QP-Collide: A New Approach to Collision Treatment

Goals for This Lecture:

Sparse Matrices. This means that for increasing problem size the matrices become sparse and sparser. O. Rheinbach, TU Bergakademie Freiberg

Linear Equation Systems Iterative Methods

Exploring unstructured Poisson solvers for FDS

Uppsala University Department of Information technology. Hands-on 1: Ill-conditioning = x 2

Contents. Hilary Term. Summary of Numerical Analysis for this term. Sources of error in numerical calculation. Solving Problems

Homework Set #2-3, Math 475B

(Sparse) Linear Solvers

1.7.1 Laplacian Smoothing

MATLAB Premier. Asst. Prof. Dr. Melik DÖLEN. Middle East Technical University Department of Mechanical Engineering 10/30/04 ME 304 1

Transcription:

Num. #1: Recalls on Numerical Methods for Linear Systems and Ordinary differential equations (ODEs) - CORRECTION The programs are written with the SCILAB software. 1 Resolution of a linear system & Computation of the eigenvalues of a matrix For the exercise, the following functions are needed : LU decomposition : //Data n=20; A=2*eye(n,n)-diag(ones(n-1,1),1)-diag(ones(n-1,1),-1); U=A; L=eye(A); //LU decomposition with loops for k=1:n-1 p=u(k,k); if p==0 then disp( la matrice n admet pas de decomposition LU ); abort; for i=k+1:n L(i,k)=U(i,k)/p; for j=k+1:n, U(i,j)=U(i,j)-U(i,k)*U(k,j)/p; U(i,k)=0; // LU decomposition - Vectorial form for k=1:n-1 p=u(k,k); if p==0 then disp( la matrice n admet pas de decomposition LU ); abort; L(k+1:n,k)=U(k+1:n,k)/p; w=(k+1:n) ; U(w,w)=U(w,w)-U(w,k)*U(k,w)/p; U(w,k)=zeros(w); Gradient descent method with optimal step : // Data n=3; T. Goudon, M. Ribot 1/7 Analysis and Numerical Simulations for PDEs

A=[2,-1,0;-1,2,-1;0,-1,2]; b=[1;0;1]; x=zeros(n,1); epsilon=0.0001; erreur=1; iter=0; // Gradient descent method while erreur>epsilon, iter=iter+1; xold=x; d=a*x-b; rho=(d *d)/(d *A*d); x=x-rho*d; erreur=norm(x-xold); Conjugate gradient method : //Data n=3; A=[2,-1,0;-1,2,-1;0,-1,2]; b=[2;3;6]; //b=[1;0;1]; // Conjugate gradient method epsilon=0.0001; test=1;it=0; x=zeros(n,1); d=a*x-b; r=d; while (test>epsilon) it=it+1; rho=(r *d)/(d *A*d); x=x-rho*d; r2=r; r=a*x-b; test=norm(r)/norm(b); d=r+norm(r)^2*d/norm(r2)^2; Power method : // Data n=10; T. Goudon, M. Ribot 2/7 Analysis and Numerical Simulations for PDEs

A=2*diag(ones(1,n))-diag(ones(1,n-1),1)-diag(ones(1,n-1),-1); niter=200; x=zeros(n,1);x(1)=1; // Power method for i=1:niter, q=x/norm(x); x=a*q; vp(i)=x(1)/q(1); Inverse power method : // Data n=10; A=2*diag(ones(1,n))-diag(ones(1,n-1),1)-diag(ones(1,n-1),-1); niter=200; x=zeros(n,1);x(1)=1; // Inverse power method for i=1:niter, q=x/norm(x); x=a\q; vp(i)=1/(x(1)/q(1)); 2 Resolution of ordinary differential equations (ODEs) For the exercise, the following functions are needed Forward/Explicit Euler method : // T is the final time, dt the time step // uinit is the initial value, f is the function of the ODE function [u]=euler(t,dt,uinit,f) u(1)=uinit; u(i+1)=u(i)+dt*f(u(i)); T. Goudon, M. Ribot 3/7 Analysis and Numerical Simulations for PDEs

// Plot a graphic plot(time,u); Midpoint (or Runge-Kutta 2) method : function[u]=rk2(t,dt,uinit,f) u(1)=uinit; v=u(i)+dt*f(u(i))/2; u(i+1)=u(i)+dt*f(v); // Plot a graphic plot(time,u, r ); Forward/Explicit Euler method for a system : // T is the final time, dt the time step // uinit is the initial value, f is the function of the ODE // The output u is a matrix // Column n corresponds to a vector at a discrete time t^n function[u]=eulersystem(t,dt,uinit,f) u(:,1)=uinit; u(:,i+1)=u(:,i)+dt*f(u(:,i)); Midpoint (or Runge-Kutta 2) method for a system : T. Goudon, M. Ribot 4/7 Analysis and Numerical Simulations for PDEs

function[u]=rk2system(t,dt,uinit,f) u(:,1)=uinit; v=u(:,i)+dt*f(u(:,i))/2; u(:,i+1)=u(:,i)+dt*f(v); Exercise 1. Implement the resolution of the following equation : t u = 1 u 2 with u(0) = 0 (1) using the four methods presented above and a time step t = 0.1 until time T = 1. T=1; dt=0.1; f=inline( 1-x^2 ); uinit=0; Euler(T,dt,uinit,f) RK2(T,dt,uinit,f) 2. Remark that the exact solution of equation (1) can be computed exactly and is equal to : u(t) = t anh(t) = e2t 1 e 2t + 1. Enhance the convergence property of the methods by letting t go to 0. Compare the order of the four methods by plotting a graph in a log-log scale, which represents the evolution of L 2 error with respect to the time step t. clear; uinit=0; f=inline( 1-x^2 ); // Different time steps T=1; T. Goudon, M. Ribot 5/7 Analysis and Numerical Simulations for PDEs

TimeStep=[0.1, 0.05, 0.01, 0.005, 0.001, 0.0005, 0.0001]; for k=1:length(timestep), dt=timestep(k); // Exact solution uexact=(exp(2*time)-ones(size(time)))./(exp(2*time)+ones(size(time))); // Approximated solutions ueuler=euler(t,dt,uinit,f); urk2=rk2(t,dt,uinit,f); // errors between exact and approximated solutions ErrorEuler(k)=sqrt(dt)*norm(uexact-uEuler); ErrorRK2(k)=sqrt(dt)*norm(uexact-uRK2); // Clear the figure clf; // Graph of the errors loglog(timestep,erroreuler) hold on; loglog(timestep,errorrk2, g ) // Leg for the graph leg( Euler, RK2 ); 3. Implement the resolution of the following system of equations, called the Lorenz system using the two first methods presented above. The parameters will be : (x 0, y 0, z 0 ) = (1,1,1), T = 30 and t = 0.001. t x = 10(y x) t y = x(28 z) y t z = x y 8 3 z (2) clear; T=30; dt=0.001; for a system xinit=1;yinit=1;zinit=1; uinit=[xinit;yinit;zinit]; // Function for a system f=inline( [10*(u(2)-u(1));u(1)*(28-u(3))-u(2);u(1)*u(2)-8*u(3)/3], u ); u=eulersystem(t,dt,uinit,f); // RK2System(T,dt,uinit,f); // Plot a graphic T. Goudon, M. Ribot 6/7 Analysis and Numerical Simulations for PDEs

clf; plot3(u(1,:),u(2,:),u(3,:)) T. Goudon, M. Ribot 7/7 Analysis and Numerical Simulations for PDEs