Homework 4
Homework 4
INSTRUCCIONES. Elabora un vector de 500 nmeros aleatorios de una distribucin normal con
media 2 y desviacin estndar de 5. Verifica la desviacin estndar y la media utilizando
(mean,std).
Cdigo.
%Random numbers.
%1.-Random variables. Make a vector of 500 random numbers from a Normal
distribution with
%mean 2 and standard deviation 5 (randn). After you generate the vector,
verify that the sample
%mean and standard deviation of the vector are close to 2 and 5
respectively (mean, std).
%Generate the vector with 500 random numbers, mean of 2 and std deviation
%of 5.
r = 2 + 5.*randn(500,1)
dev = std(r)
med = mean(r)
PRCTICA 2.
INSTRUCCIONES. Elabora un script llamado coinTest.m que simule el modelo secuencial de una
moneda que es lanzada 5000 veces. Registra cada vez que se obtiene heads y grafica el
estimado de probabilidad de obtener dicho valor con esta moneda. Grafica esta estimacin
junto con una lnea horizontal en el valor esperado de 0.5.
Cdigo.
%
r = randi([0,1],1,n)
%Retain the data so that it doesn't get erased by the second plot.
hold on
%Add grid
grid on
axis([0 5000 0 1])
Resultado.
0.8
0.7
Probability of heads
0.6
0.5
0.4
0.3
0.2
0.1
0
0 500 1000 1500 2000 2500 3000 3500 4000 4500 5000
Trials
3.
INSTRUCCIONES. Elabora una distribucin de Poisson de 1000 nmeros distribuidos con
parmetro lamdba 5.
Cdigo.
%Declare lambda
value. lambda = 5;
%n
n = 1:1000;
%Keep the result along with the rest of the data from other plots.
hold on
Resultado.
Poisson distribution / mass function.
0.18
Distributed Poisson
0.16 Poisson mass function
0.14
0.1
0.08
0.06
0.04
0.02
0
1 2 3 4 5 6 7 8 9 10 11 12 13
Samples.
a. Elabora una celda de 3x3 donde la primera columna contenga los nombres Joe, Sarah
y Pat; la segunda columna Smith, Brown y Jackson y la tercera columna contenga
sus salaries $30,000.00, $150,000.00 y $120,000.00. Muestra los resultados utilizando
disp.
%Title.
disp('cellProblem'
)
%Change the values of element 2,2 of the cell from 'Brown' to 'Meyers'.
cell{2,2} = 'Meyers';
if(x ==
0) x
= 1;
y =
i;
end
%Get the number of bytes and filename.
b(i).name = a(i).name;
End
b(i).size = a(i).byte
PRCTICA 6.
%Create the x & y variables where x goes from 0 to 2*pi and y is the sin
of
%such function.
x = 0:0.1:2*pi;
y = sin(x);
%Set xlimit.
xlim([0 2*pi])
%Image processing
format longg;
format compact;
fontSize = 20;
% Read in a standard MATLAB color demo image.
folder = fullfile(matlabroot, '\toolbox\images\imdemos');
baseFileName = 'peppers.png';
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
if ~exist(fullFileName, 'file')
% Didn't find it there. Check the search path for it.
fullFileName = baseFileName; % No path this time.
if ~exist(fullFileName, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
rgbImage = imread(fullFileName);
% Get the dimensions of the image. numberOfColorBands should be = 3.
[rows columns numberOfColorBands] = size(rgbImage);
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
blackImage = uint8(zeros(rows, columns));
newRedChannel = [redChannel, redChannel; blackImage, blackImage];
newGreenChannel = [greenChannel, blackImage; greenChannel, blackImage];
newBlueChannel = [blueChannel, blackImage; blackImage, blueChannel];
newRGBImage = cat(3, newRedChannel, newGreenChannel, newBlueChannel);
% Display the original color image.
imshow(newRGBImage, []);
title('New Color Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);