• Keine Ergebnisse gefunden

Worksheet 3: LU Decomposition and Taylor Polynomials

N/A
N/A
Protected

Academic year: 2021

Aktie "Worksheet 3: LU Decomposition and Taylor Polynomials"

Copied!
2
0
0

Wird geladen.... (Jetzt Volltext ansehen)

Volltext

(1)

Physik auf dem Computer SS 2017

Worksheet 3: LU Decomposition and Taylor Polynomials

May 8, 2017

General Remarks

• The deadline for handing in the worksheets is Monday, May 15th, 2017, 12:00 noon.

• For this worksheet, you can achieve a maximum of 10 points.

• To hand in your solutions, send an email to your tutor:

– Johannes Zeman zeman@icp.uni-stuttgart.de (Tue 15:45–17:15) – Michael Kuron mkuron@icp.uni-stuttgart.de (Wed 15:45–17:15) – Kai Szuttor kai@icp.uni-stuttgart.de (Thu 14:00–15:30)

• Attach all required files to the e-mail. If asked to write a program, attach the source code of the program.

• Please try to only hand in a single file that contains your program code for all tasks. If you are asked to answer questions, you can do so in a comment in your code file. If you are asked for graphs or figures, it is sufficient if your code generates them. You may as well hand in a separate PDF document with all your answers, graphs and equations.

• The worksheets are to be solved in groups of two or three people.

Task 3.1: LU-Decomposition (5 points)

As you will learn later in the lecture, when you are able to solve linear equation systems (e.g. via Gauss eliminiation), this can be used to approximate numerical solutions of differential equations. A prominent example is the Poisson equation ∆Φ(r) = −ρ(r), where Φ(r) is the electrostatic potential and ρ(r) is the charge distribution.

In this task, you will approximate the solution of the Poisson equation in the two-dimensional case by solving A Φ = ¯ ¯ ρ where ¯ Φ and ¯ ρ are the discretized electrostatic potential and charge distribution, respectively, and A is a correctly constructed matrix.

The Python script ws3.py from the website demonstrates how to use Gauss elimination to compute the solution of the Poisson equation for 2d-systems of randomly distributed charges and how to measure the runtime of a Python function. To be able to run it, you will have to put the file poisson2d.py from the website into the same directory as ws3.py .

3.1.1 (1 point) When executing the code, one notices that solving the equation for a 50 × 50 system is already relatively costly.

Extend the Python program such that it measures the runtime t for computing the Gauss elimination of a single N × N -system for N ∈ {10, 20, 30, 40, 50, 60, 70, 80, 90, 100} using the function timeit.timeit . Create a plot that shows the runtime t against N in double-logarithmic scale. Estimate the time that it would take to solve the Poisson equation for a 1000 × 1000- system.

1

(2)

3.1.2 (2 points) Extend the Python code such that it uses LU-factorization to solve the equation via scipy.linalg.lu_factor and scipy.linalg.lu_solve . Measure the runtime of both func- tions separately for the different values of N . Create a plot that allows to compare the runtimes of the Gauss eliminiation, the LU factorization, and LU solving against N in double-logarithmic scale.

3.1.3 (2 points) Using LU-factorization, speed up the computation of the potential for 25 different charge distributions. Show your success by computing the potential for 25 100 × 100 charge distributions.

Task 3.2: Taylor Polynomials (5 points)

In this task, you are asked to plot the Taylor polynomials of the following functions on the specified domains:

Name Definition Domain

Sine Function f (x) = sin x [0, 2π]

Runge Function g(x) =

1+x1 2

[−5, 5]

Lennard-Jones Function h(x) = x

−12

x

−6

[1, 5]

3.2.1 (3 points) Calculate the coefficients of the truncated Taylor series of the sine function f (x) at x

0

= 0, the Runge function g(x) at x

0

= 0 and the Lennard-Jones function at x

0

= 1 up to 10th degree. Use the Python class numpy.poly1d to define the k-th order Taylor polynomials of f (x), g(x) and h(x) for k ∈ {3, 5, 10} at arbitrary x.

3.2.2 (2 points) For each of the functions f (x), g(x) and h(x), create a plot that shows the function and their respective k-th degree Taylor polynomials (k ∈ {3, 5, 10}) on the specifed domain.

Hints

• You may use software such as Maple, Mathematica or WolframAlpha to compute the Taylor series.

• The Python class numpy.poly1d is used as follows:

# f i s t h e p o l y n o m i a l f ( x ) = 3 ∗ x ∗ ∗ 2 + 2∗ x + 1

# Note t h e o r d e r o f t h e c o e f f i c i e n t s ! f = n u m p y . p o l y 1 d ([3 ,2 ,1])

# Compute t h e v a l u e o f t h e p o l y n o m i a l a t x=42 p r i n t f ( 4 2 )

• Take care to handle the argument of the Taylor polynomial of h(x) correctly!

2

Referenzen

ÄHNLICHE DOKUMENTE

Using only the average number of moves and number of solved instances we can clearly separate MMAS and extended run time 2D-LPFH as the overall best performing test cases. Using

Third, in our model specification we consider two outcome variables, represented by subjective well-being (life satisfaction) and incomes, since we consider that resources and

Universit¨ at Regensburg, Institut f¨ ur Theoretische Physik Summer 2020 Prof.. In this case the fidelity will depend on |Ψi such that it is useful

L¨ osung: Wir verwenden das Gaußsche Gesetz und das in der vorigen Aufgabe gefundene E-Feld um die L¨ angenladungsdichte des inneren Drahtes zu bestimmen.. Wir legen einen

Bei der Abbildung 2c kommen zwei gleich große Teilfiguren vor (blau). Sie sind aber unterschiedlich entstanden. 2b), das andere der Major des Minors der ersten Zerlegung.. In

Hans Walser: Kreise im Goldenen Schnitt 5 / 7 Auch dies ist nicht trivial und muss verifiziert werden.. Die insgesamt neun lila Kreise liegen in einem

Proof of Theorem 0.3.. Now Theorem 0.3 follows. Suppose that G acts freely outside the origin on L. Hence by the checkerboard pattern of the E 2 -term the only non-trivial

Therefore the energy difference between a kink with a single excitation and the kink ground state, a quantity which we call the excitation energy, is at one loop simply equal to