Engineering 6 Spring 2016
Homework 4
Due Monday, April 25th, 11:55 PM
For this assignment,
Complete the required preparation (Reading assignment chapter 7.1, 7.3, 7.5, 8.1-8.6).
Submit a solution for each of the assigned problems. Unless otherwise noted, all problem
solutions should be submitted on the same MATLAB file (.m), separated by a %%, into
different publishable sections.
You will also submit a published pdf version of your solutions using the MATLAB
publishing utility. The published output should be divided into a section for each problem.
All solutions must then be submitted via SmartSite.
Problem 1 (25%)
A plant scientist has developed a model to predict the growth rate of a tree with the
following using:
G = ln(a
1
𝑚2
+ b
1
𝑚
+ c),
where m is the age of the tree (in months) and g is the corresponding monthly growth (in
cm). The scientist then used this model to study its growth, and got the data shown below:
m (months) G (cm)
2 5.7
5 4.1
10 3.3
15 2.5
20 2.1
25 2.2
30 1.7
35 1.6
40 1.3
1) Apply the model to this dataset and calculate the coefficients a, b, c using non-
linear regression.
2) Use the estimated coefficients to evaluate the tree’s growth from month 1 to 60,
and plot the curve of growth vs month and the original data using round dots.
3) Use the estimated coefficients to estimate the growth at the 100th month.
Problem 2 (25%)
“Noise-reducing” headphones work by identifying and curve fitting the sinusoidal waves
of the ambient sounds in your environment. They then generate an additional signal,
where the wave is a phase shifted copy of the ambient noise. The end result is the addition
of the ambient noise and its shifted copy, which creates destructive interference and thus
the noise “reducing” aspect of the headphones. The data below is from an ambient noise
signal:
t = [0.04 0.08 0.12 0.17 0.43 0.48 0.53 0.58 0.64 0.67 0.75 0.92];
y = [0.59 0.95 0.96 0.25 0.16 0.95 0.89 0.31 -0.59 -0.89 -0.71 0.95];
Destructive interference occurs when the signals are out of phase by ½ Period
𝑅1 − 𝑅2 =
𝑇
2
where T is the period.
1) Fit the ambient noise data with a spline interpolation (R1) from 0 to 1 with 1000
points. Make a plot that shows the original data points and the interpolated curve.
2) Use the Matlab built-in function max()/min() or findpeaks() and array indexing to
find the period of the waveform, which would be the duration between two peaks.
If there are more than two peaks found in the sampled signal, you can calculate all
durations between adjacent peaks, and average them.
3) Create a vector that is a copy of the interpolated curve (R2), phase shift it, and
produce destructive interference. Use spline interpolation again to fill in any
missing data, you can truncate values for t>1. Graph the ambient noise, phase-
shifted signal, and final waveform on one plot.
Problem 3 (25%)
The Yolo Federal Credit Union is offering loans at a special interest rate. Eligible
recipients include individuals that have graduated from college within 2 years and are
currently employed. If a loan applicant is not employed, this person is automatically
ineligible for the special interest rate. Write a program which determines if someone is
eligible to receive the special interest rate based on their answers to the following
questions:
1. Are you employed?
2. Have you graduated from college in the past two years?
Your program should run and appear as follows:
Note: if you use inputdlg function to help publish this problem, since your input is a string
type, you don’t need to use str2num function. Instead you simply need to extract the first
element from the cell array that has been recognized as input. The format is as follows:
Problem 4 (25%)
Brownian motion is the random motion of particles suspended in a fluid (a liquid or a gas)
resulting from their collision with the quick atoms or molecules in the gas or liquid. In this
problem you will create a program to simulate Brownian motion.
Imagine a bead travels in a limited space defined by 0≤x≤100, 0≤y≤100. Every 0.01
second, the bead travels to its next position, which could randomly be 1 among 9
possibilities (it could stay where it is).
If the bead is at the boundary and its next position is predicted to be out of the boundary,
it will actually be bounced back according to normal physical model. For example, if a
bead is at (100, 50), and its next position is predicted be (101, 51), then its actual next
position will be (99, 51).
1) Write a program to calculate the coordinates of the bead in 1 sec (which means it
travels 100 times), starting from (x, y) = (50, 50). And use plot(x, y, ‘^’) with hold
on to display all the spots it traveled through on a same figure.
2) On another figure, plot all the spots it traveled through in 10 sec (1000 times).
3) On another figure, plot all the spots it traveled through in 100 sec (10000 times).
4) Use pause function in the loop so that the spots are generated one after another,
to monitor the “movement” of the bead.
Note: when you run the loops too many times, it may take a certain time for the program
to finish. If you find out something wrong while the program is running, you can press
Ctrl+C to force terminate.