Survey
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project
BL5229: Data Analysis with Matlab
Lab: Graphing and Programming
With this lab, you will practice more how to generate graphs as well as do some programming
Exercise 1: Finding the day of the week corresponding to a specific date.
Have you ever wondered which day of the week was a specific date? For example, was July 14th,
1789 a Monday or not? Well, people have thought of this problem and came up with ways to
compute this information. The simplest solution is probably Zeller's congruence equation, which
defines:
h = ( q + (13*(m+1))/5 + K + K/4 + J/4 + 5*J)
where:
J is the number of the century [i.e. the year / 100],
K the year within the century [i.e. the year % 100],
m the month,
q the day of the month,
Note that in this formula:
- The month indices are: March: 3, April: 4,...but with January being 13 and February being 14.
- January and February are counted as part of the previous year.
- h is a representation of the date as number of days since a starting time. It can then be
converted into a day of the week using:
N = rem(h,7)
i.e. the remainder of the division of h by 7. N is the day of the week, with 0 being Saturday, 1
being Sunday,...
Write a Matlab script that:
• Reads a date (day, month, and year)
• Computes the corresponding day of the week N using the formula described above.
Outputs the result (please write the day of the week as a word, not a number, for example
'Saturday', and not 0)
% Ask user to input date:
%
date=input(‘Enter the date : ‘,’s’)
%
% Get numerical values for year, month, and day, and convert to integer
%
[year,month,day]=datevec(date);
year=int32(year);
month=int32(month);
day=int32(day);
i4=int32(4);
i5 = int32(5);
i100=int32(100);
%
% Get modified month and year
%
if month >=3
m = month;
y = year;
else
m = month+12;
y = year-1;
end
%
% Define K, J, and q
%
J = idivide(y,i100);
K = rem(y,100);
q = day;
%
% Compute h:
%
h = ( q + idivide(13*(m+1)),i5) + K + idivide(K,i4) + idivide(J,i4) + 5*J)
%
% Compute N
%
N = rem(h,7)
%
% Print day:
%
Days={‘Saturday’ ‘Sunday’ ‘Monday’ ‘Tuesday’ ‘Wednesday’ ‘Thursday’ ‘Friday’};
%
Days(N+1)
Exercise 2: Compute the number of days between two days
For this exercise, the function datenum does the work!
% Ask user to input both dates
%
d1=input(‘Enter date 1: ‘,’s’);
d2=input(‘Enter date 2: ‘,’s’);
%
% Convert both dates into absolute # of days:
%
n1 = datenum(d1);
n2 = datenum(d2);
%
% The difference… with absolute values as the dates may have been inverted
%
diff = abs(n1-n2);
%
% Print result:
%
disp([‘The number of days between the two dates is ‘ num2str(diff)]);
%
Exercise 3: Analyzing biological data
A simple experiment was designed to analyze the effects of noise on gene expression within a
cell: a cell has been engineered to contain two genes (which we will label as C and Y) that are
supposed to be expressed identically. In the presence of noise however, the expression levels
will differ. There are two possible source of noise:
extrinsic noise: noise related to all external factors that may affect gene expression
intrinsic noise: noise related to the gene expression machinery itself.
Two different experiments were conducted, each with a different type of cell. In experiment 1,
data (i.e. expression levels for C and Y) were collected for 30 cells, while in experiment 2, data
were available for 37 cells. The raw data are in the two files available on the web site.
Write a Matlab script for analyzing these data:
1) Generate a plot (scattered plot) of Y as a function of C for each experiment
2) Compute the levels of intrinsic, hint2, extrinsic, hext2, and total htot2 noise in each experiment.
You will use the formula:
h =
2
int
(c - y )
2c y
2
; h
% Load data
%
load Data_exp1.dat
load Data_exp2.dat
%
% get columns:
%
C1 = Data_exp1(:,1);
Y1 = Data_exp1(:,2);
C2 = Data_exp2(:,1);
2
ext
c2 + y2 - c y
cy - c y
2
=
; htot =
c y
2c y
Y2 = Data_exp2(:,2);
%
% Plot both curves on the same page
%
figure
subplot(2,2,1)
plot(C1,Y1,’or’)
xlabel(‘C’)
ylabel(‘Y’)
title(‘Experiment 1’)
subplot(2,2,2)
plot(C2,Y2,’or’)
xlabel(‘C’)
ylabel(‘Y’)
title(‘Experiment 2’)
%
% Compute noise levels for each experiment
%
cy_mean1 = mean(C1)*mean(Y1);
num1=mean((C1-Y1).^2);
den1 = 2*cy_mean1;
noise_int1 = num1/den1;
num1 = mean(C1.*Y1)-cy_mean1;
den1 = cy_mean1;
noise_ext1 = num1/den1;
num1=mean(C1.^2 + Y1.^2)-cy_mean1;
den1 = 2*cy_mean1;
noise_tot1 = num1/den1;
%
cy_mean2 = mean(C2)*mean(Y2);
num1=mean((C2-Y2).^2);
den1 = 2*cy_mean2;
noise_int2 = num1/den1;
num1 = mean(C2.*Y2)-cy_mean2;
den1 = cy_mean2;
noise_ext2 = num1/den1;
num1=mean(C2.^2 + Y2.^2)-cy_mean2;
den1 = 2*cy_mean2;
noise_tot2 = num1/den1;