matlab代写-CSC336S-Assignment 3
时间:2022-03-28
CSC336S Assignment 3 Due Thursday, April 7, 2022
Please write your family and given names and underline your family name on the front page of your paper.
1. Let f (x) = ex − 4x2.
(a) [3 points] Show that f has (at least) one root in [0, 1].
(b) [2 points] Let g(x) = 1
2
e
x
2
. Verify that g(x) = x, iff f (x) = 0.
(c) [15 points] Show that g has a unique fixed point in [0, 1], and, therefore, that f (x) has a unique root in [0, 1].
Show that the fixed-point iteration x(k+1) = g(x(k)), with g(x) = 1
2
e
x
2 , converges to the unique root of f (x) in [0, 1] for
any starting guess chosen in [0, 1].
(d) [5 points] What is the rate of convergence of the fixed-point iteration with g(x) = 1
2
e
x
2 ? Explain.
(e) [10 points] Find the largest interval you can, so that the fixed-point iteration scheme converges, if started within the
interval, and so that you justify your answer mathematically. (Note: the interval may expand [0, 1] from both sides.)
Help: First expand [0, 1] to the left, then to the right, as much as you can.
2. [25 points] Consider a robot arm with two joints (as in the notes). The first arm part starts at (0, 0), ends at (xm, ym),
and has length a. The second arm part starts at (xm, ym), ends at (x p, y p) (tip of the arm), and has length b. The angle
of the first arm part with the x-axis is θ, and that of the second arm part with the first is φ. As in the notes, we have the
equations
x p = a cos(θ ) + b cos(θ + φ ) (1)
y p = a sin(θ ) + b sin(θ + φ ) (2)
Given a, b, x p and y p, equations (1)-(2) form a 2 × 2 nonlinear system of equations, with respect to θ and φ .
Give (by hand) the Jacobian J(θ , φ ) for this system.
Write a MATLAB/other function that implements Newton’s method for the system of equations (1)-(2). (The code
only needs to be for the functions and equations in (1)-(2), and not for a general 2 × 2 system of equations. You can
hardcode the appropriate derivatives and other functions.) Use as stopping criterion the absolute (Euclidean) norm of
the residual. Write also a MATLAB/other script that, given values to a, b, xp and yp, uses the above function to
solve the above 2 × 2 system of nonlinear equations, then, using the values of θ and φ computed, plots the arm (draws a
picture of the arm) at the final location using solid line. In the same plot, plot the initial location of the arm using
dashed line.
Do four runs:
Tw o runs with a = 1.5; b = 1; xp = 1.2; yp = 1.6; once with initial guess [pi
4
, −
pi
2
]T , and once with
initial guess [pi
4
,
pi
2
]T ;
one more run with a = 1.5; b = 1; xp = 1.2; yp = sqrt((a+b)ˆ2 - 1.2ˆ2); and initial guess
[pi
4
, −
pi
2
]T ; and
one more run with a = 1.5; b = 1; xp = 1.2; yp = 2.2; and initial guess [pi
4
, −
pi
2
]T .
The script should output, in the format given below, the iteration index, the two angles calculated, the Euclidean norm
of the residual for each iteration, and the x and y positions corresponding to the two angles, on one line (six quantities
on one line), for each iteration. Use tolerance 10−8, and maxit = 20.
For formatting the output, use fprintf(’%2d %8.5f %9.5f %9.3e %12.9f %12.9f\n’, ... );
Leave a blank line between runs.
Thus, for each of the four runs, you will have a table of values calculated.
Comment on the results for each run.
Notes:
The MATLAB function that implements Newton’s method for (1)-(2) should start with
function [r, it, rall, res] = robotarm(a, b, p, r, tol, maxit)
and you adjust it for other coding language. The point where we want to position the robot arm is in the 2 × 1 vector p. On
input, r is the vector of the two initial angles, while on return, r is a vector of the two (final) angles calculated. Moreover, it
is the number of Newton’s iterations, rall an (it + 1) × 2 array of pairs of approximate angles calculated at each iteration,
CSC336 Assignment 3 C. Christara
- 2 -
including the initial pair of angles, and res a vector of the Euclidean norms of the residuals at each iteration. The x and y
positions can be calculated outside the robotarm function. If convergence is not reached within maxit iterations, the function
should output a relevant message, and still return all calculated quantities.
To compute the vector v = J−1(x(k)) f (x(k)), you need to solve the linear system J−1(x(k))v = f (x(k)), using backslash. Note
that f1(θ , φ ) = a cos(θ ) + b cos(θ + φ ) − x p, and f2(θ , φ ) = a sin(θ ) + b sin(θ + φ ) − y p.
Once you have the approximate solution (angles) calculated, you need to calculate xm and ym to plot the arms.
Use axis equal after you plot the robot arm, for uniformity and for more appropriate aspect ratio of the axes.
Present the four plots in one page (possibly in 2 × 2 presentation), each with a caption, indicating the respective target coordi-
nates and the initial position coordinates, and a legend indicating initial and final arm positions.
3. Consider the function f (x) = x ln x, and the data (e−1, −e−1), (1, 0) and (e, e) arising from f .
(Note: e = 2. 7183. . . and e−1 = 0. 3679. . ., but it is easier for you to maintain the symbolic values e and e−1.)
(a) [6 points] Using Newton’s Divided Differences (NDD), give the quadratic polynomial p2(x) interpolating f (x) at the
above data. The coefficients of the polynomial are to be given in terms of e and e−1.
You do not have to bring p2(x) into monomial form.
(b) [3 points] Giv e the error formula for this interpolation problem (i.e. for this f and these data points). The formula
should involve only an unknown point ξ , the values e−1 and e, as well as a few constants.
(c) [8 points] Assume we evaluate p2 at some x ∈[e−1, 3]. Indicate the interval where ξ belongs to. Find an upper bound
(as sharp as you can) of the error | f (x) − p2(x)| when x ∈[e−1, 3], and explain how your got it. The bound is to be
worked out in terms of e−2, e−1 and e. You may specify it as the maximum of a fixed number of quantities written in
terms of e−2, e−1 and e, and simplified as much as possible. If the quantity t = e−1 + 1 + e appears multiple times, you
may denote it by t, and work out some results in terms of t.
Then, find an approximate numerical value for the bound.
(d) [8 points] Assume we evaluate p2 at some x ∈[e−2, e]. Indicate the interval where ξ belongs to. Find an upper bound
(as sharp as you can) of the error | f (x) − p2(x)| when x ∈[e−2, e], and explain how your got it. The bound is to be
worked out in terms of e−4, e−2, e−1 and e. You may specify it as the maximum of a fixed number of quantities written
in terms of e−4, e−2, e−1 and e, and simplified as much as possible. If the quantity t = e−1 + 1 + e appears multiple
times, you may denote it by t, and work out some results in terms of t.
Then, find an approximate numerical value for the bound.
4. [15 points] Consider using three types of interpolation for the function f (x) = cos(pi x), namely, polynomial, linear
spline and cubic spline interpolation. The script http://www.cs.toronto.edu/˜ccc/Cour-
ses/336/scriptint.m uses the first two of them, for a certain function, in a certain interval, and for certain num-
bers of data.
After the given part of script, add extra lines to compute the clamped cubic spline interpolant on 16, 32, 64, . . . , 1024
subintervals (of equal length), for the same function and in the same [a, b] interval given. (Use spline(xi, yi2,
xe); where yi2 has two extra values.) Also include the linear spline interpolant on the same number of subintervals,
so that you can draw a comparison.
For each n and for the linear and cubic spline interpolants, compute the maximum in absolute value error on the evalua-
tion points given. For each pair (n, 2n), compute the orders of convergence of the linear and cubic spline interpolants.
For each value of n, the script should output on one line the number of subintervals n, the maximum in absolute value
errors on the evaluation points for the linear and cubic interpolants, and the respective orders of convergence. (For
n = 16, leave the orders of convergence blank.)
Run the script and collect the results from both the given part and the part you wrote. (When you run the script, if you
get a warning from polyfit, you are not necessarily doing anything wrong.)
Comment on the results, in particular, how the error of each interpolant behaves as the number of data points increases,
and whether this behaviour agrees with what expected from theory.
For the output of n, the errors of the two spline interpolants and respective orders of convergence, use
fprintf(’%4d %12.3e %12.3e %6.1f %6.1f\n’, ... );
CSC336 Assignment 3 C. Christara


essay、essay代写