From 0643ef2c028a7fb004c7b87845f4610297dd08c4 Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Tue, 4 Jan 2022 20:31:57 +0100 Subject: mms: add lecture --- Year_3/MMS/lecture_20211221.m | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 Year_3/MMS/lecture_20211221.m (limited to 'Year_3/MMS/lecture_20211221.m') 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); -- cgit v1.2.3-18-g5258