summaryrefslogtreecommitdiff
path: root/Year_3/MMS/lecture_20211221.m
diff options
context:
space:
mode:
authorSanto Cariotti <santo@dcariotti.me>2022-01-04 20:31:57 +0100
committerSanto Cariotti <santo@dcariotti.me>2022-01-04 20:31:57 +0100
commit0643ef2c028a7fb004c7b87845f4610297dd08c4 (patch)
treefa01c305b69c3eb3a57cf058098596b766dddeae /Year_3/MMS/lecture_20211221.m
parent84cdf5bfb41b31e07afcb7d8b1c36cd2e3d3a5b4 (diff)
mms: add lecture
Diffstat (limited to 'Year_3/MMS/lecture_20211221.m')
-rw-r--r--Year_3/MMS/lecture_20211221.m43
1 files changed, 43 insertions, 0 deletions
diff --git a/Year_3/MMS/lecture_20211221.m b/Year_3/MMS/lecture_20211221.m
new file mode 100644
index 0000000..8fa807a
--- /dev/null
+++ b/Year_3/MMS/lecture_20211221.m
@@ -0,0 +1,43 @@
+% First, import `regressione_lineare/brakes.txt` as Column vectors
+
+% plot(Speedmph, StoppingDistance, 'o');
+
+p = polyfit(Speedmph, StoppingDistance, 1);
+f = @(x) p(1)*x + p(2);
+
+x = min(Speedmph)-1:0.1:max(Speedmph)+2;
+y = f(x);
+
+% plot(Speedmph, StoppingDistance, 'o', x, y);
+
+% ---
+% Import `regressione_lineare/boyle.txt` as Column vectors
+x = Height;
+y = Pressure;
+
+xbar = mean(x);
+ybar = mean(y);
+n = length(x);
+
+Sxx = 0.0;
+Syy = 0.0;
+Sxy = 0.0;
+
+for i = 1:1:length(x)
+ Sxx = Sxx + (x(i)-xbar)^2;
+ Syy = Syy + (y(i)-ybar)^2;
+ Sxy = Sxy + (x(i)-xbar) * (y(i)-ybar);
+end
+
+R2 = Sxy^2 / (Sxx*Syy);
+SSRes = (Sxx*Syy - Sxy^2) / Sxx;
+R2Corr = 1 - SSRes/Syy*(n-1)/(n-2);
+
+% Import `regressione_lineare/all-the-efficiency.txt` as Column vectors
+p = polyfit(EfficiencyhiwayMpg, MSRP, 1);
+
+f = @(x) p(1)*x + p(2);
+x = min(EfficiencyhiwayMpg)-1:0.1:max(EfficiencyhiwayMpg)+2;
+y = f(x);
+
+% plot(EfficiencyhiwayMpg, MSRP, 'o', x, y);