CSS 455 Scientific Programming C. Jackels
Winter 2012 January 4, 2012
Homework Assignment #1
Written Homework Assignment. These are to be worked individually. Each student is to hand in her/his own assignment at the Catalyst Drop Box for HW1. However, you are expected to communicate with your partner, discuss strategies for solving the problems, etc. In the end, you are to solve it yourself, and your solution should not be identical to your partner’s. What is not allowed is for you to jointly solve the set and turn in your collaborative solution.
The following are to be completed and handed in electronically in final form by Saturday, January 14, 2012, at 11:59 PM. The assignment will be accepted up to 24 hours late for 75% credit and up to 48 hrs late for 50% credit. For each problem hand in whatever is needed for me to understand your work. This should certainly include a program listing (m-file), the relevant output, and any notes needed to understand your approach. The notes should all be gathered in one Word document. The m-files and outputs can either be cut into the Word document or submitted separately as part of the *zip archive. The m-files and outputs, if submitted separately, need to have informative file names that identify them as a particular homework problem. Your name should be on the Word document and in the comments of any code.
Problem 1.1 (use of the Matlab plot function. Multiple plots can be placed on the same figure using either the argument list for Plot or using the hold on/hold off functions.)
Write a matlab script file that plots y(x) = sin(x) and y(x) = cos(x) on the same plot for x in the range (-p, p). Use vectors for x and y. Efficiency counts. Hand in a copy of the script file and the plot it generated.
Problem 1.2 (the subplot function is used to
divide a figure into plotting panes and to select the one to be active. Plot
is then used within that pane just as in the previous problem.)
Consider the function: f(x)
= 2sin(x) + 4sin(2x) + 6sin(3x).
Write a Matlab script that plots f(x), its first derivative, and its second derivative in the interval [-3p, 3p]. You are to use the subplot function in order to place f(x) in the top pane, its first derivative in the middle pane and its second derivative in the lower one. There is to be one graph on each of three panes, all of which appear in one figure. Efficiency counts. You will notice that some of the same sin(x) evaluations are used in the function as in the 2nd derivative; in most situations it is more efficient to reuse these values rather than recalculating them. Hand in a copy of the script file and the plot generated.
Problem 1.3. What is the nearest floating point number to 64 on a base-2 computer with 5-bit mantissas? Show your work. Assume an implicit bit, so that all places are beyond the binary point. This is equivalent to a 6-bit normalized representation: 1.xxxxx.
Problem 1.4. Problem #2 on page 11 of Turner (Just decide how
many terms you will need for (a) or (b) and then run your program.)
Problem 1.5. Problem #4 on page 11 of Turner. (This is just
like Example 4; do the derivation exactly the same way. Once you have the
expression for the error bound in the given truncation (in terms of x), just
run a Matlab program to evaluate it for a range of x values. The answer is
given in the book.
Problem 1.6. Problem #4 of page 15 of Turner. (First, plot the two functions to be sure you know what they look like. You can then evaluate L¥ by inspection and evaluate L1 by hand evaluation of the definite integral. L2 involves an integral you can do by hand (integration by parts) or by using the symbolic math component of Matlab (see below). Note that the book answer is wrong for L2.
Note about symbolic math in Matlab. Matlab has much
of the Maple symbolic math engine buried within it. The function syms
is used with Matlab to create symbolic variables, rather than numeric ones..
Functions can be defined in terms of them. Finally, the function int
can be used to integrate such functions analytically. For example the
following series of commands integrates cos(x) analytically:
syms x; A = cos(x); int (A)} A definite integral between u,v is obtained
by int(A,u,v)
Problem 1.7. Problem #1, part(b) only, on page 19 of Turner. Answers
are in book for part (a).
Problem 1.9. Problem #4 on page 19 of Turner. Follow Example 9 very closely for the n=5 instead of the n=3 term, as done in the example.