Spring 2012 MATLAB Assignment 6

advertisement
Spring 2012 MATLAB Assignment 6
Work the following problems (NOTE: these are RELATED TO the corresponding page and problem
number from Gilat. Do NOT work the problems from the actual Lab Manual, or you will receive NO
CREDIT!)
1. g249x05:
(a) Enter the function y(x) = 0.9x4 e−0.1x − 15x2 − 5x as an anonymous function.
(b) Use the function to calculate y(−2) and y(4).
(c) Use the function to make a plot from −3 ≤ x ≤ 3.
2. g250x09: The monthly payment M of a loan of amount P for N years and an annual interest
rate r (in %) can be calculated by the formula
r
1200
M =P
1− 1+
r −N
1200
Write a MATLAB user-defined function that calculates the monthly payment of a loan. For the
function name and arguments use M = amort(P, r, N). The inputs arguments are P the loan
amount, r the annual interest rate in percent, and N the length of the loan in years. The output
M is the amount of the monthly payment. Use the function to calculate the monthly payment
of a 15-year mortgage of $260,000 with annual interest rate of 6.75%.
3. g251x14: Write a user-defined MATLAB function that determines the unit vector in the direction of the line that connects two points (A and B). For the function name and arguments
use u=unitvec(A, B). The input argments to the function are vectors A and B, each with the
Cartesian coordinates of points A and B. The output u is the unit vector in the direction of
the vector that starts at A and ends at B. If points A and B have two coordinates each (they
are in the x-y plane), then u is a two-element vector. If points A and B have three coordinates
each (they are in 3-dimensional space), then u is a three-element vector. Use the function to
determine the following unit vectors:
(a) In the direction from the point (1.5, 2.1, 4) to the point (11, 15, 9).
(b) In the direction from the point (1, 0) to the point (0, 1).
(c) In the direction from the point (−11, 3, −2) to the point (−13, −4, −5).
4. g253x22: Write a user-defined function that plots a circle given the coordinates of its center
and length of the radius. For the function name and arguments, use circleplot(xc, yc, r). The
input argments xc and yc are the coordinates of the center and r is the radius of the circle. This
function has no output argments. Use the function to plot the following circles:
(a) xc = −2.5, yc = 7, r = 1.
(b) xc = −3, yc = −2.6, r = 5.
5. Also work s585x46 from the Stewart text.
1
Download