Last active
September 24, 2015 12:22
-
-
Save tOverney/0fd9a1836feef084c72f to your computer and use it in GitHub Desktop.
PCML's first assignment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% Exercice 1.1 | |
ident33 = eye(3,3) | |
diag_inc = diag([1 2 3]) | |
zeros33 = zeros(3,3) | |
M = rand(4,3) | |
T = reshape(M,6,2) % it takes them column by column | |
a = [1; 2; 3] | |
% Exercice 1.2 | |
b = M*a % 4x1 it's correct because we did a 4x3 * 3x1 => 4x1 | |
e = transpose(b) * b % 1x1, value is a scalar | |
% Exercice 1.3 | |
A = rand(3,3) | |
c = A * a | |
d = inv(A)*c %size is 3x1 | |
% d == a because we did d = A^(-1)*A*a wich is equals to a! | |
% Exercice 1.4 | |
top_left_inv = inv(M(1:3,1:3)) | |
% Exercice 1.5 | |
A = [1, 2; 3, 4] | |
k = 3.1 | |
B = A + k - k | |
C = A - B % YOu can add a threshold for the approximation | |
% Exercice 1.6 | |
c = 5; | |
A = rand(3,3); | |
B = rand(3,3); | |
C = A * B; | |
equ1 = mat_equ(inv(inv(A)), A) | |
equ2 = mat_equ(inv(c * A), inv(c) * inv(A)) | |
equ3 = mat_equ(inv(transpose(A)), transpose(inv(A))) | |
equ4a = mat_equ(B, inv(A)*A*B) | |
equ4b = mat_equ(inv(A)*A*B, inv(A)*C) | |
equ5a = mat_equ(C, A*B) | |
equ5b = mat_equ(A*B, (C*inv(B))*(inv(A)*C)) | |
equ5c = mat_equ((C*inv(B))*(inv(A)*C), C*inv(B)*inv(A)*C) | |
equ6 = mat_equ(C*inv(B)*inv(A), eye(3)) | |
equ7a = mat_equ(inv(C), inv(B)*inv(A)) | |
equ7b = mat_equ(inv(B)*inv(A), inv(A*B)) | |
% Exercice 1.7 | |
x = [-10:10]; | |
%%uncomment to display because plot are annoying! | |
%plot(x, 100*cos(x).^2 + x.^3,'r') | |
%%uncomment to display because plot are annoying! | |
%plot(x, 100*cos(x).^2 + x.^3,'.') % we only see discrete dots | |
% Exercice 1.8 | |
data = rand(100,1); | |
%%uncomment to display because plot are annoying! | |
%hist(data,6) | |
% it looks mess with the default number of bins, it should be | |
% a uniform distribution | |
% the less bin the more equals they are. | |
% Exercice 1.9 | |
data = 10 + 2*randn(100,1); | |
%%uncomment to display because plot are annoying! | |
%hist(data, 8) | |
% Intro EDA | |
clearvars; | |
load('height_weight_gender.mat') | |
whos | |
amnt_male = sum(gender) | |
amnt_female = length(gender) - amnt_male | |
height = height * 0.025; | |
weight = weight * 0.454; | |
% Exercice 1.10 | |
height_male = mean(height(gender)); | |
height_female = mean(height(~gender)); | |
weight_male = mean(weight(gender)); | |
weight_female = mean(weight(~gender)); | |
% They do make sense to me! Males are bigger and taller than women! | |
avg_w_fem = mean(weight(~gender & height < 1.7 & height > 1.6)); | |
% Exercice 1.11 | |
x_dim = 3; | |
y_dim = 2; | |
figure | |
subplot(x_dim,y_dim,1) | |
hist(weight) | |
axis([0 150 0 2200]) | |
subplot(x_dim,y_dim,2) | |
hist(males_w) | |
axis([0 150 0 2200]) | |
subplot(x_dim,y_dim,3) | |
hist(females_w) | |
axis([0 150 0 2200]) | |
subplot(x_dim,y_dim,4) | |
hist(height) | |
axis([1.2 2.1 0 2500]) | |
subplot(x_dim,y_dim,5) | |
hist(males_h) | |
axis([1.2 2.1 0 2500]) | |
subplot(x_dim,y_dim,6) | |
hist(females_h) | |
axis([1.2 2.1 0 2500]) | |
% Yes, they do look as expected! | |
% Exercice 1.12 | |
figure | |
plot(height, weight, '.') | |
% 1. Quite well, We can see that most point form a line | |
% which shows correlation between the two data even | |
% if that doesn't mean relation. | |
% 2. Not very well, there's a lot of overlap between the two genders. | |
% 3. Task 2 is a lot harder in my opinion. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You'll need this function in a file named
mat_equ.m
to run my code