• Tidak ada hasil yang ditemukan

Thư viện số Văn Lang: Finite Difference Computing with Exponential Decay Models

N/A
N/A
Nguyễn Gia Hào

Academic year: 2023

Membagikan "Thư viện số Văn Lang: Finite Difference Computing with Exponential Decay Models"

Copied!
8
0
0

Teks penuh

(1)

Hans Petter Langtangen

Finite Diff erence Computing

with Exponential Decay Models

Editorial Board T. J. Barth M. Griebel D. E. Keyes R. M. Nieminen D. Roose T. Schlick

110

(2)

110

Editors:

Timothy J. Barth Michael Griebel David E. Keyes Risto M. Nieminen Dirk Roose Tamar Schlick

Lecture Notes

in Computational Science

and Engineering

(3)

More information about this series athttp://www.springer.com/series/3527

(4)

Hans Petter Langtangen

Finite Difference Computing with

Exponential Decay Models

(5)

Hans Petter Langtangen Simula Research Laboratory Lysaker, Norway

On leave from:

Department of Informatics University of Oslo Oslo, Norway

ISSN 1439-7358 ISSN 2197-7100 (electronic)

Lecture Notes in Computational Science and Engineering

ISBN 978-3-319-29438-4 ISBN 978-3-319-29439-1 (eBook) DOI 10.1007/978-3-319-29439-1

Springer Cham Heidelberg New York Dordrecht London Library of Congress Control Number: 2016932614

Mathematic Subject Classification (2010): 34, 65, 68

© The Editor(s) (if applicable) and the Author(s) 2016 This book is published open access.

Open Access This book is distributed under the terms of the Creative Commons Attribution- NonCommercial 4.0 International License (http://creativecommons.org/licenses/by-nc/4.0/), which permits any noncommercial use, duplication, adaptation, distribution and reproduction in any medium or format, as long as you give appropriate credit to the original author(s) and the source, a link is provided to the Creative Commons license and any changes made are indicated.

The images or other third party material in this book are included in the work’s Creative Commons license, unless indicated otherwise in the credit line; if such material is not included in the work’s Creative Commons license and the respective action is not permitted by statutory regulation, users will need to obtain permission from the license holder to duplicate, adapt or reproduce the material.

This work is subject to copyright. All commercial rights are reserved by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed.

The use of general descriptive names, registered names, trademarks, service marks, etc. in this publica- tion does not imply, even in the absence of a specific statement, that such names are exempt from the relevant protective laws and regulations and therefore free for general use.

The publisher, the authors and the editors are safe to assume that the advice and information in this book are believed to be true and accurate at the date of publication. Neither the publisher nor the authors or the editors give a warranty, express or implied, with respect to the material contained herein or for any errors or omissions that may have been made.

Printed on acid-free paper

Springer International Publishing AG Switzerland is part of Springer Science+Business Media (www.springer.com)

(6)

Preface

This book teaches the basic components in the scientific computing pipeline: mod- eling, differential equations, numerical algorithms, programming, plotting, and software testing. The pedagogical idea is to treat these topics in the context of a very simple mathematical model, the differential equation for exponential decay, u0.t /D au.t /, whereuis unknown andais a given parameter. By keeping the mathematical problem simple, the text can go deep into all details about how one must combine mathematics and computer science to create well-tested, reliable, and flexible software for such a mathematical model.

The writing style is gentle and aims at a broad audience. I am much inspired by Nick Trefethen’s praise of easy learning:

Some people think that stiff challenges are the best device to induce learning, but I am not one of them. The natural way to learn something is by spending vast amounts of easy, enjoyable time at it. This goes whether you want to speak German, sight-read at the piano, type, or do mathematics. Give me the German storybook for fifth graders that I feel like reading in bed, not Goethe and a dictionary. The latter will bring rapid progress at first, then exhaustion and failure to resolve.

The main thing to be said for stiff challenges is that inevitably we will encounter them, so we had better learn to face them boldly. Putting them in the curriculum can help teach us to do so. But for teaching the skill or subject matter itself, they are overrated. [13, p. 86]

Prerequisite knowledge for this book is basic one-dimensional calculus and preferably some experience with computer programming in Python or MATLAB.

The material was initially written for self study and therefore features compre- hensive and easy-to-understand explanations. For some readers it may act as an overview and refresher of traditional mathematical topics and likely a first introduc- tion to many of the software topics. The text can also be used as a case-based and mathematically simple introduction to modern multi-disciplinary problem solving with computers, using the range of applications in Chap.4as motivation and then treating the details of the mathematical and computer science subjects from the other chapters. In particular, I have also had in mind the new groups of readers from bio- and geo-sciences who need to enter the world of computer-based differ- ential equation modeling, but lack experience with (and perhaps also interest in) mathematics and programming.

The choice of topics in this book is motivated from what is needed in more advanced courses on finite difference methods for partial differential equations

v

(7)

vi Preface

(PDEs). It turns out that a range of concepts and tools needed for PDEs can be introduced and illustrated by very simple ordinary differential equation (ODE) examples. The goal of the text is therefore to lay a foundation for understanding numerical methods for PDEs by first meeting the fundamental ideas in a simpler ODE setting. Compared to other books, the present one has a much stronger focus on how to turn mathematics into working code. It also explains the mathematics and programming in more detail than what is common in the literature.

There is a more advanced companion book in the works, “Finite Difference Computing with Partial Differential Equations”, which treats finite difference meth- ods for PDEs using the same writing style and having the same focus on turning mathematical algorithms into reliable software.

Although the main example in the present book isu0 D au, we also address the more general model problemu0D a.t /uCb.t /, and the completely general, nonlinear problemu0 D f .u; t /, both for scalar and vectoru.t /. The author be- lieves in the principle simplify, understand, and then generalize. That is why we start out with the simple modelu0 D auand try to understand how methods are constructed, how they work, how they are implemented, and how they may fail for this problem, before we generalize what we have learned fromu0 D auto more complicated models.

The following list of topics will be elaborated on.

How to think when constructing finite difference methods, with special focus on the Forward Euler, Backward Euler, and Crank–Nicolson (midpoint) schemes.

How to formulate a computational algorithm and translate it into Python code.

How to make curve plots of the solutions.

How to compute numerical errors.

How to compute convergence rates.

How to test that an implementation is correct (verification) and how to automate tests through test functions and unit testing.

How to work with Python concepts such as arrays, lists, dictionaries, lambda functions, and functions in functions (closures).

How to perform array computing and understand the difference from scalar com- puting.

How to uncover numerical artifacts in the computed solution.

How to analyze the numerical schemes mathematically to understand why arti- facts may occur.

How to derive mathematical expressions for various measures of the error in numerical methods, frequently by using thesympysoftware for symbolic com- putations.

How to understand concepts such as finite difference operators, mesh (grid), mesh functions, stability, truncation error, consistency, and convergence.

How to solve the general nonlinear ODEu0 Df .u; t /, which is either a scalar ODE or a system of ODEs (i.e.,uandf can either be a function or a vector of functions).

How to access professional packages for solving ODEs.

How the model equationu0 D au arises in a wide range of phenomena in physics, biology, chemistry, and finance.

How to structure a code in terms of functions.

(8)

Preface vii

How to make reusable modules.

How to read input data flexibly from the command line.

How to create graphical/web user interfaces.

How to use test frameworks for automatic unit testing.

How to refactor code in terms of classes (instead of functions).

How to conduct and automate large-scale numerical experiments.

How to write scientific reports in various formats (LATEX, HTML).

The exposition in a nutshell

Everything we cover is put into a practical, hands-on context. All mathematics is translated into working computing codes, and all the mathematical theory of finite difference methods presented here is motivated from a strong need to un- derstand why we occasionally obtain strange results from the programs. Two fundamental questions saturate the text:

How do we solve a differential equation problem and produce numbers?

How do we know that the numbers are correct?

Besides answering these two questions, one will learn a lot about mathematical modeling in general and the interplay between physics, mathematics, numerical methods, and computer science.

The book contains a set of exercises in most of the chapters. The exercises are divided into three categories: exercises refer to the text (usually variations or extensions of examples in the text), problems are stand-alone exercises without ref- erences to the text, and projects are larger problems. Exercises, problems, and projects share a common numbering to avoid confusion between, e.g., Exercise 4.3 and Problem 4.3 (it will be Exercise 4.3 and Problem 4.4 if they follow after each other).

All program and data files referred to in this book are available from the book’s primary web site:http://hplgit.github.io/decay-book/doc/web/.

Acknowledgments Professor Svein Linge provided very detailed and constructive feedback on this text, and all his efforts are highly appreciated. Many students have also pointed out weaknesses and found errors. A special thank goes to Yapi Dona- tien Achou’s proof reading. Many thanks also to Linda Falch-Koslung, Dr. Olav Dajani, and the rest of the OUS team for feeding me with FOLFIRINOX and thereby keeping me alive and in good enough shape to finish this book. As al- ways, the Springer team ensured a smooth and rapid review process and production phase. This time special thanks go to all the efforts by Martin Peters, Thanh-Ha Le Thi, and Yvonne Schlatter.

Oslo, August 2015 Hans Petter Langtangen

Referensi

Dokumen terkait

The Brazilian Entrepreneurial Ecosystem of Startups: An Analysis of Entrepreneurship Determinants in Brazil and the Perceptions Around the Brazilian Regulatory Framework,

Sudi Rahayu, S.E., MM ABSTRAK Penelitian ini bertujuan untuk mengetahui perkembangan Dana Pihak Ketiga DPK, Non Performing Loan NPL dan Return On Asset ROA serta untuk mengetahui