From: Nils Forssén Date: Thu, 22 Sep 2022 14:57:25 +0000 (+0200) Subject: update X-Git-Url: https://gitweb.forssennils.se/?a=commitdiff_plain;h=f888ce2a507a8d39bea1ce33008c8fc68a25d1c7;p=TSRT04.git update --- f888ce2a507a8d39bea1ce33008c8fc68a25d1c7 diff --git a/Ecology/TSRT04_ecology_script.m b/Ecology/TSRT04_ecology_script.m new file mode 100644 index 0000000..82c7b67 --- /dev/null +++ b/Ecology/TSRT04_ecology_script.m @@ -0,0 +1,69 @@ +%% Deluppgift 3 +clear; +close all; +load ecology.mat; + +yyaxis left; +plot(years, animals(1:end, 1), "b", LineStyle="-", LineWidth=2); +ylabel("# of Wolves"); + +yyaxis right; +plot(years, animals(1:end, 2), "r", LineStyle="--", LineWidth=2); +ylabel("# of Moose"); + +title("Animals"); +legend("Wolves", "Moose"); +xlabel("Year"); +xlim([1959, 2011]); + +%% Deluppgift 4, 5, 6, 7, 8 +clear; +close all; +load ecology.mat; + +% First subplot +subplot(2, 1, 1); +plot(years, animals(1:end, 1), "b", LineStyle="-", LineWidth=2); + +% MAXMIN +hold on; +[max_wolves, y_index1] = max(animals(1:end, 1)); +[min_wolves, y_index2] = min(animals(1:end, 1)); +plot(years(y_index1), max_wolves, "ko", 'MarkerSize', 10, LineWidth=2); +plot(years(y_index2), min_wolves, "ko", 'MarkerSize', 10, LineWidth=2); + +title("Wolves"); +xlabel("years"); +ylabel("# of Wolves"); +xlim([1959, 2011]); + +hold off; + +% Second subplot +subplot(2, 1, 2); +plot(years, animals(1:end, 2), "r", LineStyle="--", LineWidth=2); + +% MAXMIN +hold on; +[max_meese, y_index3] = max(animals(1:end, 2)); +[min_meese, y_index4] = min(animals(1:end, 2)); +plot(years(y_index3), max_meese, 'k*', 'MarkerSize', 10, LineWidth=2); +plot(years(y_index4), min_meese, 'k*', 'MarkerSize', 10, LineWidth=2); + +title("Moose"); +xlabel("years"); +ylabel("# of Moose"); +xlim([1959, 2011]); + +% save fig +saveas(gcf, "pngs/gunilla.svg"); +saveas(gcf, "pngs/gunilla.fig"); + +%% Deluppgift 5 +clear; +close all; +clc; +load ecology.mat; + + + diff --git a/Ecology/ecology.mat b/Ecology/ecology.mat new file mode 100644 index 0000000..cee6205 Binary files /dev/null and b/Ecology/ecology.mat differ diff --git a/Ecology/pngs/gunilla.fig b/Ecology/pngs/gunilla.fig new file mode 100644 index 0000000..ffe2494 Binary files /dev/null and b/Ecology/pngs/gunilla.fig differ diff --git a/Ecology/pngs/gunilla.png b/Ecology/pngs/gunilla.png new file mode 100644 index 0000000..9b61ea3 Binary files /dev/null and b/Ecology/pngs/gunilla.png differ diff --git a/Ecology/pngs/gunilla.svg b/Ecology/pngs/gunilla.svg new file mode 100644 index 0000000..7f26a2d --- /dev/null +++ b/Ecology/pngs/gunilla.svg @@ -0,0 +1,306 @@ + + +19601965197019751980198519901995200020052010years1020304050# of WolvesWolves19601965197019751980198519901995200020052010years0500100015002000# of MooseMoose diff --git a/Yatzee/dice_sim.m b/Yatzee/dice_sim.m new file mode 100644 index 0000000..65af3c6 --- /dev/null +++ b/Yatzee/dice_sim.m @@ -0,0 +1,4 @@ +function [dice_results] = dice_sim(num_of_dice) +%dice_sim Simulates ´num of dice´ many dice rolls and returns results vector +dice_results = randi(6, 1, num_of_dice); +end \ No newline at end of file diff --git a/Yatzee/hist_plot.m b/Yatzee/hist_plot.m new file mode 100644 index 0000000..aa9f5b0 --- /dev/null +++ b/Yatzee/hist_plot.m @@ -0,0 +1 @@ +histogram(dice_results, 6) \ No newline at end of file diff --git a/Yatzee/main.asv b/Yatzee/main.asv new file mode 100644 index 0000000..91b9529 --- /dev/null +++ b/Yatzee/main.asv @@ -0,0 +1,30 @@ +clear; +clc; + +% Roll x dice +count = 1; +results = dice_sim(5); +[main_n, main_most_common] = max(sum_vec(results)); +main_most_common +results +main_n +while count < 5 + results = dice_sim(5 - main_n); + % determine most common dice + + [n, most_common] = max(sum_vec(results)); + if n > main_n + main_most_common = most_common; + main_n = n; + else + if most_common + main_n = main + + end + main_most_common + results + main_n + % reroll other dice + % repeat until all dice are unified + count = count + 1; +end diff --git a/Yatzee/main.m b/Yatzee/main.m new file mode 100644 index 0000000..bd00a1a --- /dev/null +++ b/Yatzee/main.m @@ -0,0 +1,23 @@ +clear; +clc; +dice = 10; +% Roll x dice +count = 1; +results = dice_sim(dice); +[main_n, main_most_common] = max(sum_vec(results)); +while main_n < dice + results = dice_sim(dice - main_n); + % determine most common dice + sigma = sum_vec(results); + [n, most_common] = max(sigma); + if n > main_n + main_most_common = most_common; + main_n = n; + else + main_n = main_n + sigma(main_most_common); + end + % reroll other dice + % repeat until all dice are unified + count = count + 1; +end +count \ No newline at end of file diff --git a/Yatzee/sum_vec.m b/Yatzee/sum_vec.m new file mode 100644 index 0000000..af727f5 --- /dev/null +++ b/Yatzee/sum_vec.m @@ -0,0 +1,11 @@ +function [sum_vec] = sum_vec(dice_results) +%UNTITLED5 Summary of this function goes here +% Detailed explanation goes here +sum_vec = zeros(1, 6); +for num=1:6 + for i=1:length(dice_results) + if dice_results(i) == num + sum_vec(num) = sum_vec(num) + 1; + end + end +end \ No newline at end of file