ENME 337 - Assignment 4 To be submitted on

advertisement
ENME 337 - Assignment 4
To be submitted on-line before the beginning of the next lab.
The following questions are to be solved by creating and running a single MATLAB script (.m) file using
the concepts covered in Chapters 5 and 6 of the course textbook.
Please explain the solutions using a reasonable amount of comments within your script file.
Problems Chapter # 5 (Two-Dimensional Plots) – 4 Problems
Problem #1
Plot the function f(x) =
(x+5)2
4+3x2
for -3  x  5. Show the “plot title” and “axis labels”.
Problem #3
Make, on the same page, two separate plots of the function f(x) = (x + 1)(x – 2)(2x – 0.25) – ex, one plot
for 0 ≤ x ≤ 3 and one for –3 ≤ x ≤ 6. Show the “plot title” and “axis labels”.
Problem #7
Plot, on the same page, the function 𝑓(𝑥) =
𝑥 2 +3𝑥+3
0.8(𝑥+1)
for –4 ≤ x ≤ 3. Using MATLAB commands “plot”
and “fplot”. Notice that the function has a vertical asymptote at x = -1. When using the “ plot “ command,
create two vectors for the domain of x. The first vector (name it x1) includes elements from –4 to –1.1,
and the second vector (name it x2) includes elements from –0.9 to 3. For each x vector create a y vector
(name them y1 and y2) with the corresponding values of y according to the function. To plot the function
make two curves in the same plot (y1 vs. x1, and y2 vs. x2). Show the “plot title” and “axis labels”.
Problem #16
The position as a function of time of a squirrel running on a grass field is given in polar coordinates by:
r(t) = 20 + 30(1 – e –0.1t) m
θ(t) = π(1 – e–0.2t)
(a) Plot the trajectory (position) of the squirrel for 0 ≤ t ≤ 20 s.
(b) Create on the same page a (second) plot for the speed of the squirrel, given by v(t) = r(t)*(dθ(t)/dt), as
a function of time for 0 ≤ t ≤ 20 s.
Show the “plot title” and “axis labels”.
y
r(t)
θ(t)
x
Continued ...
ENME 337 - Assignment 4
Problems Chapter # 6 (Programming in MATLAB) – 4 Problems
Problem #6
The maximum daily temperature (in F) for Chicago and San Francisco during the month of August 2009
are given in the vectors below (data from the U.S. National Oceanic and Atmospheric Administration).
TCH = [75 79 86 86 79 81 73 89 91 86 81 82 86 88 89 90 82 84 81 79 73 69 73 79 82 72 66 71 69 66 66]
TSF = [69 68 70 73 72 71 69 76 85 87 74 84 76 68 79 75 68 68 73 72 79 68 68 69 71 70 89 95 90 66 69]
Write a program in a script file to answer the following:
(a) Calculate the average temperature for the month in each city.
(b) How many days was the temperature above the average in each city?
(c) How many days (valid. variable: n_6c1), and on which dates (valid. variable: d_6c2) in the month,
was the temperature in San Francisco lower than the temperature in Chicago?
(d) How many days, and on which dates in the month (valid. variable: d_6d2), was the temperature the
same in both cities?
Problem #7
Fibonacci numbers are the numbers in a sequence in which the first two elements are 0 and 1, and the
value of each subsequent element is the sum of the previous two elements:
0, 1, 1, 2, 3, 5, 8, 13, ...
Write a MATLAB program in a script file that determines and displays the first 20 Fibonacci numbers
(valid. variable: num20_7).
Problem #11
Write a program in a script file that determines the real roots of a quadratic equation a x2 + b x + c = 0.
When the file runs, it asks the user to enter the values of the constants a, b, and c. To calculate the roots of
the equation the program calculates the discriminant D, given by D = b2 - 4 a c. Furthermore:
if D > 0, the program displays message “The equation has two roots,” and the roots are displayed in the
next line.
if D = 0, the program displays message “The equation has one root,” and the root is displayed in the
next line.
if D < 0, the program displays message “The equation has no real roots.”
Run the script file in the Command Window three times to obtain solutions to the following three
equations:
a) 2x2 + 8x + 8 = 0
b) 5x2 + 3x – 4 = 0
c) 2x2 + 7x + 4 = 0
Problem #14
Write a program (using the “ for “ loop) that determines the approximate expression for π:
𝑚
2∏
𝑛=1
(2𝑛)2
4 16 36
= 2( ∗
∗
∗ ….)
2
(2𝑛) − 1
3 15 35
Run the program with m = 100, m = 100,000, and m = 1,000,000. Compare the result with π. (Use format
long.)
Download