Saint Louis University |
Computer Science 145
|
Dept. of Math & Computer Science |
Topic: Vectorized Operations
Related Reading: Ch. 3 (especially 3.3) as well as coverage of vectors from
lecture as well as the practice problems that we
did in class.
Due:
Wednesday, 28 January 2009, 11:59pm
Please make sure you adhere to the policies on academic integrity.
For this assignment, you should be submitting four separate files: approxPi.m, limits.m, baseball.m, floatingError.m. Submit those m-files in accordance with cs.slu.edu/~goldwasser/145/submit.
The value of can be estimated by evaluating a partial sum of the form
Write a script named approxPi.m which computes the first million terms of this series. Then use cumsum to compute the partial sums (as was done in the sample solutions from lecture). As a final result, display the relative error between MATLAB's pi and our approximate pi for the values .
For this problem, we want you to gather empirical evidence for that limit by evaluating the expression for progressively smaller values. Specifically
Write a script named limits.m that creates a vector data by evaluating the expression for values of in the series . Display your results by executing the following commands:
format long; disp(data');
For this problem, we consider the motion of a ball under the force of
gravity (we will ignore other factors such as air resistance). Let is the acceleration due to gravity, measured in . If a
ball is thrown vertically with an initial velocity of , measured
in meters/second), it will remain in the air for
seconds. Its height at time measured in meters will be
Write a script baseball.m that creates a vector named times with 25 evenly spaced values from to . Then compute another vector named heights that tracks the corresponding height for each time, using the above formula.
Test your program using an initial velocity of 43.81 meters/second (the equivalent of a 98 m.p.h. fastball). To produce a two-column display of your results, use the command disp( [times', heights'] );
For any non-zero real number, we have the identity that . However, computers do not perform arithmetic with arbitrary precision. Instead, they use a convention known as floating-point representation for storing and manipulating numbers with fixed precision. We can find evidence of this by trying to verify the above mathematical identity. If you perform the test 3 * (1 / 3) == 1, you will likely see that the equivalence is true (with the logical true value displayed as ``1'' in matlab). Yet if you perform the similar test 49 * (1 / 49) == 1, the condition is false (with the logical false value displayed as ``0'' in matlab).
Write a script named floatingError.m that performs the following experiment. Determine what percentage of the first 100000 integers successfully satisfy the identity when computed in MATLAB.
Write a script named extra.m which repeats the exercise from Problem A using each of the new approaches. Compare the relative errors of the three approximations for varying values of .