• Complain

Hans Petter Langtangen - A Primer on Scientific Programming with Python

Here you can read online Hans Petter Langtangen - A Primer on Scientific Programming with Python full text of the book (entire story) in english for free. Download pdf and epub, get meaning, cover and reviews about this ebook. year: 0, publisher: Springer Berlin Heidelberg, Berlin, Heidelberg, genre: Home and family. Description of the work, (preface) as well as reviews are available. Best literature library LitArk.com created for fans of good reading and offers a wide selection of genres:

Romance novel Science fiction Adventure Detective Science History Home and family Prose Art Politics Computer Non-fiction Religion Business Children Humor

Choose a favorite category and find really read worthwhile books. Enjoy immersion in the world of imagination, feel the emotions of the characters or learn something new for yourself, make an fascinating discovery.

Hans Petter Langtangen A Primer on Scientific Programming with Python
  • Book:
    A Primer on Scientific Programming with Python
  • Author:
  • Publisher:
    Springer Berlin Heidelberg, Berlin, Heidelberg
  • Genre:
  • Year:
    0
  • Rating:
    5 / 5
  • Favourites:
    Add to favourites
  • Your mark:
    • 100
    • 1
    • 2
    • 3
    • 4
    • 5

A Primer on Scientific Programming with Python: summary, description and annotation

We offer to read an annotation, description, summary or preface (depends on what the author of the book "A Primer on Scientific Programming with Python" wrote himself). If you haven't found the necessary information about the book — write in the comments, we will try to find it.

Hans Petter Langtangen: author's other books


Who wrote A Primer on Scientific Programming with Python? Find out the surname, the name of the author of the book and a list of all author's works by series.

A Primer on Scientific Programming with Python — read online for free the complete book (whole text) full work

Below is the text of the book, divided by pages. System saving the place of the last page read, allows you to conveniently read the book "A Primer on Scientific Programming with Python" online for free, without having to search again every time where you left off. Put a bookmark, and you can go to the page where you finished reading at any time.

Light

Font size:

Reset

Interval:

Bookmark:

Make
Springer-Verlag Berlin Heidelberg 2016
Hans Petter Langtangen A Primer on Scientific Programming with Python Texts in Computational Science and Engineering 10.1007/978-3-662-49887-3_1
1. Computing with Formulas
Hans Petter Langtangen 1, 2
(1)
Simula Research Laboratory, Fornebu, Norway
(2)
Department of Informatics, University of Oslo, Oslo, Norway
Hans Petter Langtangen
Email:
Our first examples on computer programming involve programs that evaluate mathematical formulas. You will learn how to write and run a Python program, how to work with variables, how to compute with mathematical functions such as e x and Picture 1 , and how to use Python for interactive calculations.
We assume that you are somewhat familiar with computers so that you know what files and folders are (another frequent word for folder is directory), how you move between folders, how you change file and folder names, and how you write text and save it in a file.
All the program examples associated with this chapter can be downloaded as a tarfile or zipfile from the web page http://hplgit.github.com/scipro-primer . I strongly recommend you to visit this page, download and pack out the files. The examples are organized in a folder tree with src as root. Each subfolder corresponds to a particular chapter. For example, the subfolder formulas contains the program examples associated with this first chapter. The relevant subfolder name is listed at the beginning of every chapter.
The folder structure with example programs can also be directly accessed in a on the web. You can click on the formulas folder to see all the examples from the present chapter. Clicking on a filename shows a nicely typeset version of the file. The file can be downloaded by first clicking Raw to get the plain text version of the file, and then right-clicking in the web page and choosing Save As.
1.1 The First Programming Encounter: a Formula
The first formula we shall consider concerns the vertical motion of a ball thrown up in the air. From Newtons second law of motion one can set up a mathematical model for the motion of the ball and find that the vertical position of the ball, called y , varies with time t according to the following formula:
A Primer on Scientific Programming with Python - image 2
(1.1)
Here, v 0 is the initial velocity of the ball, g is the acceleration of gravity, and t is time. Observe that the y axis is chosen such that the ball starts at y = when t =. The above formula neglects air resistance, which is usually small unless v 0 is large, see Exercise .
To get an overview of the time it takes for the ball to move upwards and return to y = again, we can look for solutions to the equation y =:
A Primer on Scientific Programming with Python - image 3
That is, the ball returns after A Primer on Scientific Programming with Python - image 4 seconds, and it is therefore reasonable to restrict the interest of () to A Primer on Scientific Programming with Python - image 5 .
1.1.1 Using a Program as a Calculator
Our first program will evaluate () we have
12 This arithmetic expression can be evaluated and its value can be printed - photo 6
(1.2)
This arithmetic expression can be evaluated and its value can be printed by a very simple one-line Python program:
The four standard arithmetic operators are written as - and in - photo 7
The four standard arithmetic operators are written as + , - , * , and / in Python and most other computer languages. The exponentiation employs a double asterisk notation in Python, e.g., 0.62 is written as 0.6**2 .
Our task now is to create the program and run it, and this will be described next.
1.1.2 About Programs and Programming
A computer program is just a sequence of instructions to the computer, written in a computer language. Most computer languages look somewhat similar to English, but they are very much simpler. The number of words and associated instructions is very limited, so to perform a complicated operation we must combine a large number of different types of instructions. The program text, containing the sequence of instructions, is stored in one or more files. The computer can only do exactly what the program tells the computer to do.
Another perception of the word program is a file that can be run (double-clicked) to perform a task. Sometimes this is a file with textual instructions (which is the case with Python), and sometimes this file is a translation of all the program text to a more efficient and computer-friendly language that is quite difficult to read for a human. All the programs in this chapter consist of short text stored in a single file. Other programs that you have used frequently, for instance Firefox or Internet Explorer for reading web pages, consist of program text distributed over a large number of files, written by a large number of people over many years. One single file contains the machine-efficient translation of the whole program, and this is normally the file that you double-click on when starting the program. In general, the word program means either this single file or the collection of files with textual instructions.
Programming is obviously about writing programs, but this process is more than writing the correct instructions in a file. First, we must understand how a problem can be solved by giving a sequence of instructions to the computer. This is one of the most difficult things with programming. Second, we must express this sequence of instructions correctly in a computer language and store the corresponding text in a file (the program). This is normally the easiest part. Third, we must find out how to check the validity of the results. Usually, the results are not as expected, and we need to a fourth phase where we systematically track down the errors and correct them. Mastering these four steps requires a lot of training, which means making a large number of programs (exercises in this book, for instance!) and getting the programs to work.
1.1.3 Tools for Writing Programs
There are three alternative types of tools for writing Python programs:
  • a plain text editor
  • an integrated development environment (IDE) with a text editor
  • an IPython notebook
What you choose depends on how you access Python. Section H.1 contains information on the various possibilities to install Python on your own computer, access a pre-installed Python environment on a computer system at an institution, or access Python in cloud services through your web browser.
Based on teaching this and previous books to more than 3000 students, my recommendations go as follows.
  • If you use this book in a course, the instructor has probably made a choice for how you should access Python follow that advice.
  • If you are a student at a university where Linux is the dominating operating system, install a virtual machine with Ubuntu on your own laptop and do all your scientific work in Ubuntu. Write Python programs in a text editor like Gedit, Atom, Sublime Text, Emacs, or Vim, and run programs in a terminal window (the gnome-terminal is recommended).
Next page
Light

Font size:

Reset

Interval:

Bookmark:

Make

Similar books «A Primer on Scientific Programming with Python»

Look at similar books to A Primer on Scientific Programming with Python. We have selected literature similar in name and meaning in the hope of providing readers with more options to find new, interesting, not yet read works.


Reviews about «A Primer on Scientific Programming with Python»

Discussion, reviews of the book A Primer on Scientific Programming with Python and just readers' own opinions. Leave your comments, write what you think about the work, its meaning or the main characters. Specify what exactly you liked and what you didn't like, and why you think so.