Exercise 1: Working with MATLAB Variables
The Fibonacci Sequence and the Golden Ratio
a. Execute the following commands to create a vector F containing the first 10 values of the Fibonacci sequence.
>> F = zeros(1,10);
>> F(1) = 1;
>> F(2) = 1;
>> for I = 3:10;
F(I) = F(I-1) + F(I-2);
b. Use a single vector PHI, to compute the ratio PHI(J) = F(J+1)/F(J) for J = 1:9. The limiting value of PHI as J increases without bound is called the golden ratio, Φ.
c. Plot PHI. What is the approximate value of the golden ratio?
d. In a new figure, plot 1/PHI (blue open circles) and PHI–1 (red stars) on the same axes.
e. In a new figure, plot PHI.^3 + PHI.^4 and PHI.^5 on the same axes.
Exercise 2: Basic Statistics and Data Analysis
Load the data in
snowfall.txt into the
MATLAB workspace. (Hint: >> doc textread)
distribution of the data in a histogram.
Experiment with different numbers of bins and
observe the effect on the shape of the distribution. (Hint: >> doc hist). Plot the histograms for 5, 10, 15, and 20 bins in the same figure using subplots. (Hint: >> doc subplot)
c. Compute the mean μ and standard deviation σ of the data. (Hint: >> doc std)
d. Make a function (normhist) that give you the normalize histogram (histogram divided by the area under the curve of the histogram).
e. Plot the normal density given by
using the μ and σ from c. on top of the normalized histogram from d. Note that the density curve has an area of 1, so to “fit” the normalized histogram.
Exercise 3: Working with MATLAB Fitting Functions
Dictyostelium cells, when placed in an external gradient, localize a key signaling protein (CRAC) to their leading edge. By fluorescently tagging CRAC with GFP, we can visualize the leading edge of a cell. I have measured the intensity of (CRAC-GFP) vs. angle for a single dictyostelium cell and saved the data in dicty.xls file. For this particular cell, the maximum GFP intensity does not align with the direction of the external gradient.
a. Load the intensity vs. angle data (dicty.xls) into the MATLAB Workspace. Plot the data on a linear scale using solid blue circular markers.
The plot resembles a cosine function with the form L+P*cos(q- f), where L is the average localization of GFP in the membrane, P is the amplitude of the cosine function and f is the angular offset.
b. Write an M-file function that takes your initial guess for (L, P and f) as input, calculates the function L+P*cos(q- f) and plots the function. How good was your initial guess?
c. Fit the data to the function in b, by minimizing the least-squares. what are the fitting parameters? (Hint: >> doc fminsearch)
Exercise 4: ODE Solver (Hint:>>doc ode23)
Simple harmonic oscillator (Ball on a spring)
Consider a simple harmonic oscillator (such as a block on a spring) with no driving force, and no friction so the net force is just. Using Newton’s second law . The acceleration, a is equal to the second derivative of x, which is given by and therefore equations of motion simplify to: , where .
a. Create a Matlab function, (function dydt = bouncingball(t,y)), which return a two dimensional vector dydt=[dxdt,dvdt], where dxdt=v; and dvdt = -(k/m)*x;
b. Integrate the equation of motion to get the position and velocity as a function of time, by calling the built in Matlab ODE solver ode23 or ode45 (Hint:>>doc ode23)
c. What kind of motion do you expect from such a system?
d. Now imagine that there is a damping term proportional to the velocity, how do the equations of motion change?