Docsity

AMSC/CMSC 460 Problem Set 4: Solving Equations using MATLAB, Assignments of Computer Science

Toggle sidebar
bg1
AMSC/CMSC 460 Problem set 4
1. Write a MATLAB programs to implement the bisection method. Input
parameters should be the tolerance ǫ, call it tol, and the pair of points a, b
which bracket the desired root x∗. Your code should take the function fas
input. The output of your code should be (1) an estimate of the root, (2) an
error estimate, and (3) the number of iterations.
Use your code to find the roots of the equation ex= 1/(.1 + x2).
2. Write a MATLAB program to implement Newton’s method. Input pa-
rameters should be the tolerance ǫ, and the starting point x0. Your code
should take the functions fand f′as input. You must put in a safe guard
to prevent the code from doing more than 50 iterations. The output of your
code should be (1) an estimate of the root, (2) an error estimate, and (3) the
number of iterations.
Use your Newton code to find the positive root of the equation x/2 =
sin x. What happens we if take 0 < x0<1 ?
3. Apply your Newton code to find the zeros of f(x) = x3−x2−x+ 1.
Modify your code to print out the iterates. What is the order of convergence
in each case? Why are the orders of convergence different?
4. A standard problem in quantum mechanics is to find the energy levels
of a single particle in a square well potential. This leads to the problem of
finding the roots of the equations:
tan(s) = √Q−s2
s≡p(s),
and
tan(s) = −s
√Q−s2≡q(s).
Set Q= 64. Use MATLAB to graph the curves tan s, p(s), q(s) on the
interval [0,8]. From the graphs, make guesses as to the location of the roots
you can see. Then write the appropriate mfiles, and use the MATLAB root
finder fzero to find the roots with a tolerance of ǫ= 10−6. To see how to
use fzero, enter help fzero.
5. Consider the system of equations
f(x, y) = xey−y−x2= 0
1
pf2

Partial preview of the text

Download AMSC/CMSC 460 Problem Set 4: Solving Equations using MATLAB and more Assignments Computer Science in PDF only on Docsity!

AMSC/CMSC 460 Problem set 4

  1. Write a MATLAB programs to implement the bisection method. Input parameters should be the tolerance ǫ, call it tol, and the pair of points a, b which bracket the desired root x∗. Your code should take the function f as input. The output of your code should be (1) an estimate of the root, (2) an error estimate, and (3) the number of iterations. Use your code to find the roots of the equation ex^ = 1/(.1 + x^2 ).
  2. Write a MATLAB program to implement Newton’s method. Input pa- rameters should be the tolerance ǫ, and the starting point x 0. Your code should take the functions f and f ′^ as input. You must put in a safe guard to prevent the code from doing more than 50 iterations. The output of your code should be (1) an estimate of the root, (2) an error estimate, and (3) the number of iterations. Use your Newton code to find the positive root of the equation x/2 = sin x. What happens we if take 0 < x 0 < 1?
  3. Apply your Newton code to find the zeros of f (x) = x^3 − x^2 − x + 1. Modify your code to print out the iterates. What is the order of convergence in each case? Why are the orders of convergence different?
  4. A standard problem in quantum mechanics is to find the energy levels of a single particle in a square well potential. This leads to the problem of finding the roots of the equations:

tan(s) =

Q − s^2 s

≡ p(s),

and tan(s) = −

s √ Q − s^2

≡ q(s).

Set Q = 64. Use MATLAB to graph the curves tan s, p(s), q(s) on the interval [0, 8]. From the graphs, make guesses as to the location of the roots you can see. Then write the appropriate mfiles, and use the MATLAB root finder fzero to find the roots with a tolerance of ǫ = 10−^6. To see how to use fzero, enter help fzero.

  1. Consider the system of equations

f (x, y) = xey^ − y − x^2 = 0

g(x, y) = exy^ − 2 x − y = 0.

This system has two roots in the square [0, 3] × [0, 3]. To get an idea of where the roots are, plot the contour curves of both functions on the square, and look where the zero level curves intersect. Write a MATLAB program using Newton’s method to find the roots with an ab- solute error of no more than 10−^6. In addition to the script mfile, you will need function mfiles for f and the Jacobian matrix

J(x, y) =

[ fx fy gx gy

] .

To solve the linear system at each iteration you can use the MATLAB com- mand x = A\b which solves the system Ax = b.

  1. Let f (x) = ex^ − 1 /(.1 + x^2 ). Use the MATLAB code fminbnd to find the point x∗ where f attains its minimum, and evaluate f (x∗).