Python for Engineering and Scientific Computing 1st Edition Veit Steinkamp download
Python for Engineering and Scientific Computing 1st Edition Veit Steinkamp download
https://ebookname.com/product/python-for-engineering-and-
scientific-computing-1st-edition-veit-steinkamp/
https://ebookname.com/product/techniques-of-scientific-computing-
for-the-energy-and-environment-frederic-magoules/
https://ebookname.com/product/mathematics-for-electrical-
engineering-and-computing-1st-edition-mary-patricia-attenborough/
https://ebookname.com/product/stochastic-methods-in-scientific-
computing-1st-edition-massimo-delia/
https://ebookname.com/product/the-languages-of-global-hip-
hop-1st-edition-marina-terkourafi/
Statics 1st Edition N. P. Bali
https://ebookname.com/product/statics-1st-edition-n-p-bali/
https://ebookname.com/product/audience-research-methodologies-
between-innovation-and-consolidation-1st-edition-geoffroy-
patriarche/
https://ebookname.com/product/medicynical-cartoons-from-the-
daily-routine-in-medicine-1st-edition-prof-dr-med-volker-lange-
auth/
https://ebookname.com/product/spooky-texas-tales-of-hauntings-
strange-happenings-and-other-local-lore-1st-edition-s-e-
schlosser/
https://ebookname.com/product/the-arabs-a-history-1st-
ed-2009-first-edition-eugene-rogan/
An Introduction to the Non Perturbative Foundations of
Quantum Field Theory 1st Edition Franco Strocchi
https://ebookname.com/product/an-introduction-to-the-non-
perturbative-foundations-of-quantum-field-theory-1st-edition-
franco-strocchi/
Rheinwerk Computing
The Rheinwerk Computing series offers new and established professionals comprehen-
sive guidance to enrich their skillsets and enhance their career prospects. Our publica-
tions are written by the leading experts in their fields. Each book is detailed and hands-on
to help readers develop essential, practical skills that they can apply to their daily work.
Philip Ackermann
JavaScript: The Comprehensive Guide
2022, 1292 pages, paperback and e-book
www.rheinwerk-computing.com/5554
Sebastian Springer
Node.js: The Comprehensive Guide
2022, 834 pages, paperback and e-book
www.rheinwerk-computing.com/5556
Sebastian Springer
React: The Comprehensive Guide
2024, 676 pages, paperback and e-book
www.rheinwerk-computing.com/5705
www.rheinwerk-computing.com
Veit Steinkamp
Python for
Engineering and
Scientific Computing
Imprint
We hope that you liked this e-book. Please share your feedback with us and read the
Service Pages to find out how to contact us.
This e-book is protected by copyright. By purchasing this e-book, you have agreed to
accept and adhere to the copyrights. You are entitled to use this e-book for personal pur-
poses. You may print and copy it, too, but also only for personal use. Sharing an electronic
or printed copy with others, however, is not permitted, neither as a whole nor in parts. Of
course, making them available on the Internet or in a company network is illegal as well.
For detailed and legally binding usage conditions, please refer to the section
Legal Notes.
This e-book copy contains a digital watermark, a signature that indicates which person
may use this copy:
Contents
1 Introduction 17
2 Program Structures 29
7
Contents
8
Contents
9
Contents
10
Contents
5.14 Project Task: Bending a Beam That Is Fixed at One End ...................................... 265
5.14.1 Second Moment of Area ...................................................................................... 265
5.14.2 Equation of the Bending Line ............................................................................. 267
5.15 Project Task: Reaction Kinetics ........................................................................................ 270
11
Contents
12
Contents
7.7 Project Task: Animation of Two Coupled Simple Pendulums ........................... 395
13
Contents
11.1 Interactions with Command Buttons, Textboxes, and Labels .......................... 466
11.1.1 Labels .......................................................................................................................... 467
11.1.2 Textboxes and Command Buttons ................................................................... 468
11.2 The Layout Manager of Tkinter ....................................................................................... 468
11.2.1 The pack Method .................................................................................................... 470
14
Contents
Appendices 497
15
Chapter 1
Introduction
This chapter provides a brief overview of the extensibility, application
areas, and functionality of the Python programming language.
If you need to perform extensive calculations for your scientific work and also want to
present the results in a graphically appealing way, then you should seriously consider
using Python. Python is a programming language whose functionality is similar to that
of MATLAB when extended with appropriate modules. In addition, Python and all its
extension modules are provided free of charge. Using Python, you can, for example,
solve systems of equations, create function plots, differentiate, integrate, and also
solve differential equations. You can also create graphical user interfaces (GUIs). For
almost every problem in engineering and natural sciences, solutions exist that not
only cover a wide range of applications, but also excel in their user-friendliness and
performance.
The Python programming language was developed in the early 1990s by Dutchman
Guido van Rossum at Centrum voor Wiskunde & Informatica (CWI) in Amsterdam. Its
name has nothing to do with the snake but refers instead to the British comedy group
Monty Python.
The particular advantages and features of this programming language include the fol-
lowing:
쐍 Python is an easy-to-learn and powerful programming language.
쐍 It provides efficient data structures.
쐍 It also allows object-oriented programming (OOP).
쐍 It has a clear syntax and dynamic typing.
쐍 Python programs are compiled using an interpreter and are therefore suitable for
the rapid development of prototypes.
쐍 Python is available for Linux, macOS, and Windows.
쐍 Python can be extended by modules.
The module concept is the cornerstone and one of Python’s outstanding strengths.
A module is a component of a software system and represents a functionally self-
contained unit that provides a specific service. For a definable scientific problem, a
module that is tailored precisely to this problem is provided in each case. In this book,
I will introduce you to the NumPy, Matplotlib, SymPy, SciPy, and VPython modules.
17
1 Introduction
1.1.1 IDLE
The abbreviation IDLE stands for “Integrated Development and Learning Environ-
ment.” Figure 1.1 shows the user interface for IDLE.
IDLE is part of the standard Python download. During the installation of Python, IDLE
is installed at the same time as the Pip package manager. You can download the latest
version of Python for the Linux, macOS, and Windows operating systems at https://
www.python.org/downloads/. Then, you’ll need to install the NumPy, Matplotlib,
SymPy, SciPy, and VPython modules individually using the Pip package manager (Sec-
tion 1.1.4). This step may cause problems if you install a new Python version: The mod-
ules can no longer be imported with the new IDLE version, and the programs will no
longer run. I will show you a way to fix this problem in Section 1.1.4. If the installation
of the Python modules fails, I recommend you use the Thonny development environ-
ment.
18
1.1 Development Environments
When you click Run • Python Shell, the Python shell will open. Next to the >>> input
prompt, you can directly enter Python commands or mathematical expressions, such
as 2+3, 3*5, or 7/5. Note that you must complete each entry by pressing the (Return) key.
1.1.2 Thonny
Compared to the professional solutions, Thonny is a rather simply designed develop-
ment environment with a comparatively small range of functions. However, it is par-
ticularly suitable for programming beginners due to its ease of use. Using Thonny, you
can run and test all the sample programs discussed in this book. Figure 1.2 shows the
user interface.
Thonny is available for Linux, macOS, and Windows and can be downloaded at https://
thonny.org.
The source code of the program must be entered into the text editor (upper left area).
Once the program has been started via the (F5) function key or by clicking the Start
button, a window opens where you’ll need to enter the file name of the program. The
19
1 Introduction
result of numerical calculations is then output in the Command Line window at the bot-
tom left of the Python shell. Each function plot of Matplotlib programs will be output
in a separate window. In the shell, also referred to as the Python console, you can also
enter Python commands directly. The Assistant in the main window, on the right, sup-
ports you in terms of troubleshooting, although you should temper your expectations
about its capabilities.
A particularly important feature of Thonny is that you can easily install and update the
NumPy, Matplotlib, SymPy, SciPy, and VPython modules. For these tasks, all you need
to do is open the Tools • Manage Packages dialog box, as shown in Figure 1.3. Then, in
the text box in the top-left corner, enter the name of the module you want to install
and click Install or Update.
To remove a module, you must select the corresponding module in the pane on the
left. Then, the Uninstall command button appears to the right of the Install command
button. One notable advantage of the package manager in Thonny is that you can also
test older versions of all available modules. For this task, simply click the ... command
icon to the right of the Install button, which will open a window where you can select
the desired version of the module.
1.1.3 Spyder
Spyder is the development environment of the Anaconda distribution of Python.
Except for VPython, the modules covered in this book—NumPy, Matplotlib, SymPy,
and SciPy—are already built in.
20
1.1 Development Environments
Spyder is available as a free download for Linux, macOS, and Windows at https://
www.spyder-ide.org.
To run an animation using a Matplotlib program, you must select Automatic as the
backend in the settings under IPython Console • Graphics. After starting the program, a
separate window will open where the animation will run. Matplotlib programs contain-
ing slider controls can also be executed interactively only with this option.
Spyder is an immensely powerful development environment. However, one disadvan-
tage is that the subsequent installation of modules that are not installed by default,
such as VPython, can be difficult for beginners. For more information on installing
Python modules, see the documentation for Spyder at https://www.spyder-ide.org.
1.1.4 Pip
To use development environments other than Thonny or Spyder, you can install
Python modules using Pip. Pip is not a development environment but the package
manager for Python that installs modules from the Python Package Index (PyPI) (https://
pypi.org/). Pip allows you to download and update modules easily—when you use
Python, Pip is a particularly important tool.
If you have installed Python and want to add only the NumPy module, for example,
you can enter the following command in a terminal on Windows, Linux, or macOS:
21
1 Introduction
If you use IDLE (e.g., version 3.9) and install a new version of Python (e.g., 3.11), then the
previously installed Python modules will no longer be imported into the updated ver-
sion. In this case, you should try installing via pip3.11 install numpy.
For more information about using Pip, see https://pypi.org/project/pip. If the installa-
tion or update of the Python modules fails, I recommend using the Thonny develop-
ment environment instead.
1.2.1 NumPy
The NumPy module (numerical Python) enables you to perform extensive numerical
calculations. For example, you can solve linear systems of equations, even with com-
plex numbers. Listing 1.1 shows a simple vector calculus program.
01 import numpy as np
02 A=np.array([1, 2, 3])
03 B=np.array([4, 5, 6])
04 print("Vector A:",A)
05 print("Vector B:",B)
06 print("Total A+B:",A+B)
07 print("Product A*B:",A*B)
08 print("Cross product :",np.cross(A,B))
09 print("Scalar product:",np.dot(A,B))
Output
Vector A: [1 2 3]
Vector B: [4 5 6]
22
1.2 The Modules of Python
Total A+B: [5 7 9]
Product A*B: [ 4 10 18]
Cross product : [-3 6 -3]
Scalar product: 32
1.2.2 Matplotlib
The Matplotlib module allows you to display mathematical functions, histograms, and
many other diagram types as well as to simulate and animate physical processes. The
graphical design options are remarkably diverse and rich in detail. Listing 1.2 shows a
simple example of the function plot of a polynomial.
01 import numpy as np
02 import matplotlib.pyplot as plt
03 x=np.arange(-2,6,0.01)
04 y=x**3-7*x**2+7*x+15
05 plt.plot(x,y)
06 plt.show()
Output
Figure 1.5 shows the output of the function plot.
23
1 Introduction
1.2.3 SymPy
Using SymPy (symbolic Python), you can calculate integrals or derivatives symboli-
cally or solve differential equations symbolically. A simplification of mathematical
terms is also possible (and much more). Listing 1.3 shows a simple example of symbolic
differentiation and integration.
Output
1.2.4 SciPy
SciPy (scientific Python) allows you to numerically differentiate, integrate, and numer-
ically solve systems of differential equations. SciPy is as comprehensive as it is versa-
tile. The capabilities of SciPy can only be partially described in this book. Listing 1.4
shows a simple example of a numerical integration program.
24
1.2 The Modules of Python
Output
Area A= 41.66666666666666
1.2.5 VPython
Using VPython, you can display fields in a 3D view or even animate their movements
in 3D space. As of version 7, the animations are displayed in the standard browser after
the program starts. Listing 1.5 shows an example of how you can program the anima-
tion of a bouncing ball.
Output
Figure 1.6 shows a snapshot of the animation. The VPython module is described in
Chapter 7. Of course, not all the capabilities of the Python modules we’ve mentioned
can be treated exhaustively in this book. If you miss a particular topic, I recommend
referring to the online documentation as a supplemental source of information. A
module’s maintainers should have a website where you’ll find tutorials for each mod-
ule to get you started, including complete module descriptions.
25
Exploring the Variety of Random
Documents with Different Content
damaged disk or other medium, a computer virus, or computer
codes that damage or cannot be read by your equipment.
1.F.4. Except for the limited right of replacement or refund set forth
in paragraph 1.F.3, this work is provided to you ‘AS-IS’, WITH NO
OTHER WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO WARRANTIES OF
MERCHANTABILITY OR FITNESS FOR ANY PURPOSE.
Please check the Project Gutenberg web pages for current donation
methods and addresses. Donations are accepted in a number of
other ways including checks, online payments and credit card
donations. To donate, please visit: www.gutenberg.org/donate.
Most people start at our website which has the main PG search
facility: www.gutenberg.org.
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebookname.com