5DV005 Lab2 Solved

30.00 $ 15.00 $

Category:
Click Category Button to View Your Next Assignment | Homework

You'll get a download link with a: . zip solution files instantly, after Payment

Description

Rate this product

Problem 1

  1. Copy the function lab2/scripts/l2p1.m into /lab2/work/my sum and identify the differences between this function and my simple sum. In particular:
    • How is the correct value of the unit roundoff identified?
    • What is the effect of the reshape command?
    • How is user stupidity handled?
  2. Extend the function my sum to include the a priori error bound given by [?], Theorem

4.3. The appropriate call sequence is

[y, aeb, reb]=my_sum(a) where

  • y is the computed sum
  • aeb is the a priori error bound
  • reb is the running error bound
  • Remember to update the documentation.
  • Remember to include comments related to the calculation of the error bounds.
  • Remember to update the revision history.
  • Remember to update the list of programmers.
  1. Copy scripts/l2p1 mwe1.m into work/my sum m and complete the script so that it computes the two sums

,                                 (1)

using both single and double precision as well as the error, an a priori error bound and a running error bound. You can obtain a very accurate value of the true sums using Kahan’s method kahan sum and double precision arithmetic.

  1. Verify that the errors are bounded by the a priori error bounds.
  2. Verify that the errors are bounded by the running error bounds.
  3. Which technique gives the best error bounds?
  4. Why is it reasonable that the running error bounds are smaller than the a priori error bounds? Hint: Which technique draws on the largest body of relevant information?

Problem 2

  1. Copy /lab2/scripts/l2p2.m into /lab2/work/my recursive sum.m and complete the function according to its specification.
  2. Extend my recursive sum to return a running error bound.
  3. Develop a minimal working example my recursive sum mwe1 which computes the same sums as the previous problem using recursion threshold m = 210.
  4. Verify that that the absolute value of each error is less than corresponding running error bound.
  5. What are the consequences of reducing the recursion threshold m from m = 210 to m = 1?
    • What happens to the error?
    • What happens to the run-time? Use tic, toc to measure the run-time.

Problem 3 You will find the command close all very useful for this problem.

  1. Copy lab2/scripts/l2p3.m in the function lab2/work/my horner.m and complete the function according to the specification.
  2. Develop a minimal working example my horner mwe1 which plots the two polynomials

p = @(x)(x-2)^3 q = @(x)x.^3 – 6 x.^2 + 12 x – 8

for x ∈ 2 + [2−15,215] using 101 equidistant points. Let MATLAB evaluate p as stated, but use my horner to evaluate q. Be careful and specify the coefficients in the right order!

  1. Prove mathematically that p(x) = q(x) for all x ∈R, i.e., the two polynomials are in fact identical, although the computed values are quite different.
  2. Extend my horner to include the calculation of the a priori error bound given by

[?], Theorem 4.10. The appropriate call sequence is

[y, aeb] = my_horner(a,x)

  1. Extend my horner further to include the calculation of a running error bound. The appropriate call sequence is

[y, aeb, reb] = my_horner(a,x)

  1. Extend the minimal working example my horner mwe1 to create a second plot which plots the absolute value of q, the a priori error bound and the running error bound all in a single figure.
  2. Use the running error bound to identify the region where the sign of the computed values of q can be trusted. A command such as find(array1>array2) will prove useful.

Problem 4 In this problem you will apply the bisection algorithm to compute a firing solution for a target located at a distance d from the gun.

  1. Read through the documentation of the function bisection and execute the minimal working example to verify that the code makes sense.

In order to automatically hit a target at coordinates (d,0) we have to set up a function which can be passed to the bisection algorithm along with pertinant information. The following steps takes you through this process. Rename the script lab2/script/l2p4.m to lab2/work/l2s4.m and completed it as suggested.

  1. Use the minimal working example of range m to initialize a gun and define a range function using those values, i.e.

[email protected](theta)range_rkx(param,v0,theta,method,dt,maxit)

  1. Similarly, define a function which measures the distance from the point of impact to the target, i.e

[email protected](theta)range(theta)-d

Here res is an abbreviation of the word “residual”, i.e. “that which remains”. Hitting the target precisely is equivalent to solving res = 0. In practice, we can settle for a residual which has a small absolute value, because the shell destroys anything with a certain radius ρ. This so-called “kill-radius” depends among other things on the amount and type of explosive and the type of target.

In order to use the bisection method, we need to find a bracket, i.e. a pair of angles θ1 and θ2 such that the two residuals have different signs. In terms of physics, this corresponds to firing a pair of shells such that one passes over the target and the other falls short of the target. Suitable brackets can be found if a ballistic table has already been computed.

  1. Compute a suitable ballistic table using the function compute range.
  2. Explain to your friends, why the command find(table(2,:)>d) can be used to rapidly determine a bracket!
  3. Compute the elevation necessary to hit a xenomorph at d = 12345 using the bisection algorithm, see Figure 1. Xenomorphs are very sturdy, so we want a residual which is less than 1 meter. Moreover, we want both the high and the low angle. Use the function range rkx to generate the trajectories and plot them in the same figure. You should end up with a figure which looks like Figure 2.
  4. A UAV (Unmanned Aerial Vehicle, i.e. a drone) has spotted a group of xenomorphs hiding behind a large hill. Your friend has analyzed the telemetry and gives you the new range. Compute the high and the low trajectory. Explain why the high trajectory is the probably the only viable option.

Figure 1: A typical xenomorph worker/warrior

Figure 2: A plot of the high and the low trajectories for hitting a target at d = 12345.

1             Concluding remarks

  1. Programs without proper description of the call sequence, input/output specification are useless to the user and the next programmer. Programs without meaningful comments are impossible to maintain. Good programmers are not afraid of writing their name on their products. Without contact information it is impossible to report bugs or ask for clarification.

Programs which do not follow these principles will not be accepted.

  1. Recursion is an elegant solution to many problems, but be wary of the overhead incurred by the function calls. Recursion is appropriate when the overhead is insignificant compared with the actual computation. This is not case if the computation consists of a single addition. Your recursive summation function uses a threshold m which sacrifies some accuracy for the sake of speed. It is possible to do tree-wise summation without recursion, but the code is a tad more complicated as demonstrated by tree sum.
  2. There is a lesson to be learned from question about the UAV. You should never blindly rely on the numbers generated by a computer. Always ask yourself what the numbers mean in the real world. In this case the low trajectory is likely to intersect the hill and it is useless for the practical purpose of destroying the xenomorphs. The hill is not part of the simulation, but it is part of the real world. The low trajectory is a valid firing solution, but only within the confines of the simulation.
  • lab2-foxxcq.zip