Page - 207 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python
Image of the Page - 207 -
Text of the Page - 207 -
6.7 Exercises 207
Exercise6.2: See if the secantmethod fails
Does the secant method behave better thanNewton’smethod in the problem de-
scribed inExercise6.1?Try the initial guesses
1. x0 D1:08andx1 D1:09
2. x0 D1:09andx1 D1:1
3. x0 D1andx1 D2:3
4. x0 D1andx1 D2:4
Filename:secant_failure.*.
Exercise6.3:Understandwhythebisectionmethodcannot fail
Solve the sameproblemas inExercise 6.1, using the bisectionmethod, but let the
initial interval be Œ 5;3 . Report how the interval containing the solution evolves
during the iterations.
Filename:bisection_nonfailure.*.
Exercise6.4:Combine thebisectionmethodwithNewton’smethod
An attractive idea is to combine the reliability of the bisection method with the
speed of Newton’s method. Such a combination is implemented by running the
bisection method until we have a narrow interval, and then switch to Newton’s
methodfor speed.
Write a function that implements this idea. Start with an interval Œa;b and
switch to Newton’s method when the current interval in the bisection method is
a fraction s of the initial interval (i.e., when the interval has length s.b a/). Po-
tential divergenceofNewton’smethod is still an issue, so if the approximate root
jumps out of the narrowed interval (where the solution is known to lie), one can
switch back to thebisectionmethod. Thevalueof smust begivenas an argument
to the function,but itmayhaveadefault valueof0.1.
Try thenewmethodon tanh.x/D0with an initial interval Œ 10;15 .
Filename:bisection_Newton.py.
Exercise6.5:Writea test function forNewton’smethod
Thepurposeof this functionis toverify the implementationofNewton’smethod in
theNewton function in the filenonlinear_solvers.py. Construct an algebraic
equationandperformtwoiterationsofNewton’smethodbyhandorwith theaidof
SymPy. Find the corresponding size of jf.x/j anduse this as value forepswhen
callingNewton. Thefunctionshouldthenalsoperformtwoiterationsandreturnthe
sameapproximationto therootasyoucalculatedmanually. Implement this ideafor
aunit test asa test functiontest_Newton().
Filename:test_Newton.py.
Exercise6.6: Solvenonlinearequation foravibratingbeam
An important engineering problem that arises in a lot of applications is the vibra-
tionsofaclampedbeamwhere theotherend is free. Thisproblemcanbeanalyzed
analytically,but thecalculationsboildowntosolving the followingnonlinearalge-
braicequation:
coshˇcosˇD 1;
back to the
book Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python"
Programming for Computations – Python
A Gentle Introduction to Numerical Simulations with Python
- Title
- Programming for Computations – Python
- Subtitle
- A Gentle Introduction to Numerical Simulations with Python
- Authors
- Svein Linge
- Hans Petter Langtangen
- Publisher
- Springer Open
- Date
- 2016
- Language
- English
- License
- CC BY-NC 4.0
- ISBN
- 978-3-319-32428-9
- Size
- 17.8 x 25.4 cm
- Pages
- 248
- Keywords
- Programmiersprache, Informatik, programming language, functional, imperative, object-oriented, reflective
- Category
- Informatik