Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

CSIS

Computer Simulation in Science

Introduction to Computer Simulation


WS 23/24
Prof. Dr. F. Knechtli
M.Sc. T. Asmussen, Dr. J. A. Urrea-Niño

Homework 3
due 13.11.23 before 8 AM
Solutions must be delivered as specified by the instructions shown in Moodle.

Exercise 3.1:

Given a real number a ̸= 0, we are interested in calculating x = a1 . By setting


1
f (x) = a −
x
use the Newton-Raphson method to find an iteration which allows to calculate
1
a
. This derivation must be handed in physically. Write a Matlab script which
implements this iteration and tests it for 10 different values of a between 1 and
10. Be careful when choosing the initial guess. For each value of a print the
number of iterations required to have a relative error below 10−15 .
(5 points)

Exercise 3.2:
Consider the function f (x) = xn for a fixed n. For an initial guess x0 = 1, calcu-
late the value of n such that after m iterations of the Newton-Raphson method the
resulting estimate of the root is 10−15 . This calculation must be handed in phys-
ically. Confirm this calculation by writing a Matlab script which implements the
Newton-Raphson iteration for f (x). Perform m = 1000 iterations with n given
by the prediction of the previous calculation and plot the estimates of the root on
a semi-logarithmic scale. Do you observe what you expected? What does this
mean for large values of n, for example n = 100? Is the Newton-Raphson a good
method for such cases?
(5 points)

Exercise 3.3:

Write a MATLAB program that implements the secant method. You can mod-
ify the existing bisect.m program from Moodle.
Write also a modified variant, which (like the bisection) is guaranteed to converge.
This is achieved by always keeping the pair of points (generated by the iteration)
which encloses the solution.

1
• Solve the equation

tanh(6βm) − m = 0 , β = 0.17 ,

with both variants of the secant method.

• The exact solution for this case can be found in the previous exercise sheet.
Generate a log-log plot of δn+1 versus δn for both variants and calculate the
corresponding convergence exponents α [hint: |δn+1 | ∝ |δn |α ] . What can
you say about their values?

(15 points)
Note: For each exercise we should be able to see, from what you handed in, what
you did and what came out of it. Print out/write down everything we need for
this. If you don’t manage to write a working program, then write down a kind of
pseudo code. That is, explain step by step, what your program should be doing.

You might also like