SPRING 2016 MATH 152 LAB ASSIGNMENT #4 1. Chapter #6

advertisement
SPRING 2016 MATH 152 LAB ASSIGNMENT #4
DUE: APRIL 13, 2016
1. Chapter #6
#6. Use loops to create a 3×5 matrix in which the value of each element is its row number to the power of its column number divided by the sum of its row number and column
number. For example, the value of element (2, 3) is 23 /(2 + 3) = 1.6.
#7. A symmetric (5×5) Pascal matrix is displayed on the right. Write
a MATLAB program that creates an n × n sym metric Pascal matrix.
Use the program to create 4 × 4 and 7 × 7 Pascal matrices.
#29. The concentration of a drug in the body CP can be modeled by
the equation:
CP =
ka
DG
(e−ke t − e−ka t )
Vd (ka − ke )
where DG is the dosage administered (mg), Vd is the volume of distribution (L), ka is the absorption rate constant (h−1 ), ke is the elimination rate constant
(h−1 ), and t is the time (h) since the drug was administered. For a certain drug, the following quantities are given: DG = 150mg, Vd = 50L,ka = 1.6h−1 , and ke = 0.4h−1 .
(a) A single dose is administered at t = 0. Calculate and plot CP versus t for 10 hours.
(b) A first dose is administered at t = 0, and subsequently four more doses are administered at intervals of 4 hours (i.e., at t = 4, 8, 12, 16). Calculate and plot CP versus t
for 24 hours.
#34. Cam is a mechanical device that transforms rotary motion into
linear motion. The shape of the disc is designed to produce a specified displacement pro file. A displacement profile is a plot of the dis
placement of the follower as a function of the angle of rotation of the
cam. The motion of a certain cam is given by the following equations:
1
2
DUE: APRIL 13, 2016
y = 6[2θ − 0.5 sin θ]/π for 0 ≤ θ ≤ π/2
y = 6 for π/2 ≤ θ ≤ 2π/3
π
y = 6 − 3[1 − 0.5 cos(3(θ − 2 ))] for 2π/3 ≤ θ ≤ 4π/3
3
y = 3 for 4π/3 ≤ θ ≤ 3π/2
θ − 3(π/2) 2
for 3π/2 ≤ θ ≤ 7π/4
y = 3 − 1.5
π/4
θ − 7(π/4) 2
for 7π/4 ≤ θ ≤ 2π
y = 0.75 − 0.75 1 −
π/4
Write a MATLAB program that plots the displacement profile for one revolution. First
create a 100 element vector for θ, then by using a loop and conditional statements calculate the value of y for the corresponding values of θ. Once y and θ are known, plot y vs
θ.
#35. The overall grade in a course is determined from the grades of 6 quizzes, 3 midterms,
and a final exam, using the following scheme:
Quizzes: Quizzes are graded on a scale from 0 to 10. The grade of the lowest quiz is
dropped and the average of the 5 quizzes with the higher grades constitutes 30% of the
course grade.
Midterms and final exam: Midterms and final exams are graded on a scale from 0 to
100. If the average of the midterm scores is higher than the score on the final exam, the
average of the midterms constitutes 50% of the course grade and the grade of the final
exam constitutes 20% of the course grade. If the final grade is higher than the average of
the midterms, the average of the midterms constitutes 20% of the course grade and the
grade of the final exam constitutes 50% of the course grade.
Write a computer program in a script file that determines the course grade for a student. The program first asks the user to enter the six quiz grades (in a vector), the three
midterm grades (in a vector), and the grade of the final. Then the program calculates
a numerical course grade (a number between 0 and 100). Finally, the program assigns a
letter grade according to the following key: A for Grade ≥ 90, B for 80≤Grade < 90, C
for 70 ≤ Grade < 80, D for 60 ≤ Grade < 70, and E for a grade lower than 60. Execute
the program for the following cases:
(a) Quiz grades: 6, 10, 6, 8, 7, 8. Midterm grades: 82, 95, 89. Final exam: 81.
(b) Quiz grades: 9, 5, 8, 8, 7, 6. Midterm grades: 78, 82, 75. Final exam: 81.
SPRING 2016 MATH 152 LAB ASSIGNMENT #4
3
2. Chapter #7
#1. Write a user-defined MATLAB function for the following math function:
y(x) = (−0.2x3 + 7x2 )e−0.3x
The input to the function is x and the output is y. Write the function such that x can
be a vector (use element-by-element operations).
(a) Use the function to calculate y(−1.5) and y(5).
(b) Use the function to make a plot of the function y(x) for −2 ≤ x ≤ 6.
#12. Write a user-defined MATLAB function that determines
the angle that forms by the intersection of two lines. For the
function name and arguments, use th=anglines (A,B,C). The
input arguments to the function are vectors with the coordinates
of the points A, B, and C, as shown in the figure, which can
be two- or three-dimensional. The output th is the angle in degrees. Use the function anglines for determining the angle for
the following cases:
(a) A(−5, −1, 6), B(2.5, 1.5, −3.5), C(−2.3, 8, 1),
(b) A(−5.5, 0), B(3.5, −6.5), C(0, 7).
#15. The area of a triangle ABC can be calculated by:
1
A = |AB × AC|
2
where AB is the vector from point A to point B and AC is the vector from point A to
point C. Write a user-defined MATLAB function that determines the area of a triangle given its vertices’ coordinates. For the function name and arguments, use [Area] =
TriArea (A, B, C). The input arguments A, B, and C, are vectors, each with the coordinates of the corresponding vertex. Write the code of TriArea such that it has two
subfunctions—one that determines the vectors AB and AC and another that executes
the cross product. (If available, use the user-defined functions from Problem 14). The
function should work for a triangle in the x − y plane (each vertex is defined by two coordinates) or for a triangle in space (each vertex is defined by three coordinates). Use the
function to determine the areas of triangles with the following vertices:
(a) A = (1, 2), B = (10, 3), C = (6, 11),
(b) A = (−1.5, −4.2, −3), B = (−5.1, 6.3, 2), C = (12.1, 0, −0.5).
#17. Write a user-defined function that plots a circle given the coordinates of the center
and a point on the circle. For the function name and arguments, use circlePC(c , p).
The input argument c is a two-element vector with the x and y coordinates of the center and the input argument p is a two-element vector with the x and y coordinates of a
4
DUE: APRIL 13, 2016
point on the circle. This function has no output arguments. Use the function to plot the
following two circles (both in the same figure):
(a) Center at x = 7.2, y = −2.9, point on the circle at x = −1.8, y = 0.5,
(b) Center at x = −0.9, y = −3.3, point on the circle at x = 0, y = 10.
#21. In polar coordinates a two-dimensional vector is y given
by its radius and angle (r, θ). Write a user-defined MATLAB
function that adds two vectors that are given in polar coordinates. For the function name and arguments, use [r th] = AddVecPol(r1, th1, r2, th2), where the input arguments are
(r1 , θ1 ) and (r2 , θ2 ), and the output arguments are the radius
and angle of the result. Use the function to carry out the following additions:
(a) r1 = (5, 23◦ ), r2 = (12, 40◦ ),
(b) r1 = (6, 80◦ ), r2 = (15, 125◦ ).
Download