Submit your files on-line in CMS before the project deadline. See the CMS link on the course webpage for instructions on using CMS. Both correctness and good programming style contribute to your project score.
You must work either on your own or with one partner. You may discuss background issues and general solution strategies with others, but the project you submit must be the work of just you (and your partner). If you work with a partner, you and your partner must register as a group in CMS and submit your work as a group.
Read the following web pages to learn about ASCII (and also about writing your resume!). You don't have to read the entire documents--just the first page is sufficient. You may search the Internet for different articles on ASCII if you like.
Next, download the plain text file p1q1.txt from the course website. Answer the questions by editing the file with any text editor (e.g., Notepad, Wordpad, even MATLAB's editor) or word processor. Be careful to keep it as a plain text file, or save the file specifically as a plain text file if you use a word processor such as Microsoft Word.
Answer the questions by writing your responses after each question. Be neat! Keep line lengths to at most 70 characters. Again, be sure to save your work as a plain text file.
Given a function f(x), one can analytically evaluate the derivative of the function at a specific value of x:
f'(x) ~ (f(x+h)-f(x))/h
where h is a small change in x. Write a MATLAB script (program) diffApprox.m to evaluate the derivative of the function
f(x) = 0.25x4 - 0.5x3 + x2 - 1
using the analytical and numerical approaches described above. Compute and display the derivative values for x = -2. Use two step sizes: h=0.5 and h=0.01. Display the derivative values to three decimal places.
Thought question: Your program will show that the step size affects the accuracy of the approximation. In general, when do you use "small" steps and when can you use "big" ones?
Aside: Why use divided difference approximation? Because taking the derivative analytically can be quite difficult for some functions! However, the accuracy of the approximation depends on the step size h and divided difference does not work well for some functions. These intricacies are among the issues studied in the area of Numerical Analysis (in Computer Science, Mathematics).
Heron's formula for calculating the area, A, of a triangle is
A = [k(k-a)(k-b)(k-c)]1/2
where a, b, c, are the lengths of the three sides of a triangle and k is half the perimeter.
The given script file triangle.m draws a triangle in a figure window and displays in that window the area of the triangle. Download and run the program to see its graphical output. Modify the script to randomly generate the x- and y-coordinates of the vertices and calculate the area of the triangle. The coordinates should be random real numbers in the range of 1 to 10. Make changes to the script only in the clearly marked "modification zone." Use additional variables as necessary.
The statement v= rand(1) assigns to variable v a random number in the range of 0 to 1. Note that the 1 in the parentheses indicates that one number is to be generated--it has nothing to do with the range. So how do you get a random number within a different range? First, the statement v= rand(1) gets you a real number in the range of 0 to 1. Next, scale (think multiply) and shift (think add) the value v to get the range you want.
You will learn more about MATLAB graphics and functions later. For now, just note the plot and sprintf functions in the given code. The command
plot([x1 x2], [y1 y2])
draws a line between the points (x1,y1) and (x2,y2). The function sprintf builds a message as fprintf does using substitution sequences, but instead of printing the message (to the Command Window) it allows you to store the built message in a variable.
Solve Problem 1.13 on page 27 of Chapter File 1. Name your program rays.m.
Note: In the Cartesian coordinate system, a ray is a straight line that extends from the origin (0,0). A ray is specified by the positive angle that it makes with the positive x-axis. For example, a ray with angle 135 degrees is the straight line that goes from (0,0) to (-1,1), (-2,2), (-3,3), etc. Your program must be able deal with user-entered values that are greater than 360. For example, 368 degrees = 8 degrees. Hint: the built-in function mod may be useful.