Homeworks for ENGR 165

Fall 2009





Homeworks and Projects:

Homework submissions: All homeworks are submitted via email. Please make sure that any file you submit has your name, student number, and assignment number and homework description at the top of the file.

Your emails should always have the following format:

For the subject line: homework # where # represents whichever number that homework project is.

In the body of the email, you should have your name and student ID number.

You should attach your matlab driver script(s) implementing the homework as .m files, and the main driver program should have the name: hwk#fml.m where again, # represents the homework number, and fml represents your first, middle, and last initials.

For example, in submitting homework 1, I would use: "homework 1" in the subject line of the email. In the body of the email I might say something like: Hi grader, here is homework 1, thanks, Ken Bosworth 12345678. I would have hwk1kwb.m as an attachment to the email.

The email link for all homework submissions is: engr165@progeny.isu.edu

All homeworks count equally toward your course grade, unless otherwise noted. Grades will be posted as they become available, on the Moodle page for this course.

Homework 1: Due Friday, 4 Sept. by 5 PM.

Implement in a matlab script file the following simple set of computations.

Create an array of x values running from -2 to 2, in steps of size .01.

Evaluate the expression y = ( 2 x 2 + 1)/( x2 + 1) on this array, storing the values in y.

Create a plot of x vs. y with a dashed red curve representing the values of y = ( 2 x 2 + 1)/( x2 + 1).


Homework 2: Due Monday, 21 September, by noontime.

Implement in a matlab script file the following array manipulations:

  1. Create an array (row vector) of ones of length 21, call it myones. Then create another array (row vector) of x values evenly spaced from -1 to 1 in using step-size .1, call this array x. Now create an array whose first row is myones, the second row is x, the third row is x's values element-wise squared, and fourth row is x's values element-wise cubed. Call this array y, and display this array. Lastly, create an array whose columns are every other column taken from y, starting at the first column, ending with the last. Call this array half_y , and display this array.

  2. Create the following array Z using the built in matlab functions which are appropriate for the job, and block-wise array manipulations, and which has the following form:

    Z is a 10 by 10 square array. In its upper left hand side, it consists of a 5 x 5 block with ones down its diagonal, and zeros elsewhere. In the upper right hand side, it consists of a 5 x 5 block of zeros, in its lower left hand block, it consists of another 5 x 5 block with ones down its diagonal, and zeros elsewhere. Finally, in the lower right hand side, it consists of a 5 x 5 block of normally distributed random values. Display the matrix Z.

Homework 3: Due Monday, 28 Sept. by noontime.

Implement in a matlab script your solution to exercise 2.16 (Energy stored in a spring), p. 83. Be sure to use nicely formatted output to answer the questions in the exercise (that is, use fprintf(...) ). In addition to answering the questions in exercise 2.16, have your program then prompt the user for a new value of a spring constant, and a new force being applied to it, and then output the resulting compression of the spring, and its stored energy.

Homework Rules in place for the remainder of the course:

For all projects submitted henceforth, your solution to the problem should be housed within a while loop, which allows the grader to test your solution repeatedly without having to re-execute the script, as shown in class. You should first display the purpose of the program, and then you should prompt the user if he/she wishes to run the code. If the user responses 'y' or 'Y', you should then run the actual problem solution (whatever that entails). After running your solution, you should prompt the user if he/she wishes to run it again, and if so, do so. Otherwise, exit the program with a closing goodbye statement.

Homework 4: Due Monday, 19 Oct. by noontime.

Implement in a matlab script your solution to exercise 3.11 (Australian Income Tax), p. 145. Be sure to use nicely formatted output to answer the questions in the exercise (that is, use fprintf(...) ). In addition to answering the questions in exercise 3.11, have your program then prompt the user if he/she wishes to see a graph of the total (medicare + income) taxes owed on incomes (in the range A$ 0 to A$ 100,000). If the user wishes to see such a graph,plotting the total taxes owed in a solid red line, and display it with proper titles and axis labels.

Homework 5: Due Monday 26 Oct. by noontime.

Implement in a matlab script your solution to exercise 4.20, (Current through a Diode), p. 199.

Homework 6: Due Wednesday 28 Oct. by noontime.

Implement in a matlab script your solution to exercises 4.24, 4.25,& 4.26, (Geometric Mean which user input terminated by a negative input value, RMS average, with user input prompted by how many data values to enter, and Harmonic mean, with user input terminated by empty input), p. 201. Have your script prompt the user for which of these 3 options he/she wishes to run, and run that problem in the manner specified. You do not have to include the "test your program ... using the four numbers 10,5,2, and 5" as part of your script. Be sure to display the results you compute using nicely formatted output statements ( that is, fprintf statements ).

Homework 7: Due Friday 4 Dec. by noontime.

Implement in a matlab .m file a function whose prototype is:

function [xroot,count] = secant( f, x0, tol, maxit)

This function should have a help section similar to newtn. Your function should be implemented so that the user can either provide just f and x0, using the default value of tol = 1.0e-8 and maxit = 20, or provide f, x0, and tol, using the default value of maxit = 20, or provide f, x0, tol, and maxit. The parameter f is a function handle to some function whose root is desired, and x0 is an initial guess. The optional parameters are tol: stopping tolerance for the iteration, and maxit: the maximum number of iterations allowed. The function secant will attempt to find a root of f, xroot, using the secant method as explained in class. Write up a test driver script as well, and use the test function f_test2 given in class. Compare your secant root finding technique to newtn, showing how many steps it took to find an approximate root, with starting guess x0 = 1.0, and tol = 1.0e-10 . Repeat with x0 = 2.0 and tol = 1.0e-10, with x0 = 0.65 and tol = 1.0e-10, and with x0 = .58 and tol = 1.0e-10 . Plot the function f_test2 on the interval x = 0 to 2.5 . In your comparisons, compute f_test2 at the answeres returned by both newtn and secant. Use nicely formated output statements displaying the comparisons. Submit your driver program, and the function implementation files secant.m, newtn.m, f_test2.m, and f_test2_prime.m as separate email attachments.