a)

function plotFish(spot, name)
plot([1 : length(spot.salmon)], cumulative(spot.salmon));
hold on
plot([1 : length(spot.trout)], cumulative(spot.trout));
xlabel('Timer');
ylabel('Fisk fanget');
title(name);
legend('Laks', 'Ørret')
end
 
function cList = cumulative(list)
cList = list;
for i = 2:length(list)
    cList(i) = cList(i) + cList(i-1);
end
end

b)

function fish = simulateFishing(salmonMax, troutMax)
for i = 1:8
   fish.salmon(i) = randi(salmonMax + 1) - 1;
   fish.trout(i) = randi(troutMax + 1) - 1;
end

c)

function recommendFishingSpot(salmonPrice, troutPrice)
salmonCash = 0;
troutCash = 0;
for i = 1:1000
    fish = simulateFishing(1,4); % Nidelva
    salmonCash = salmonCash + salmonPrice * sum(fish.salmon);
    troutCash = troutCash + troutPrice * sum(fish.trout);
end
nidelvaCash = (salmonCash + troutCash) / 1000;
salmonCash = 0;
troutCash = 0;
for i = 1:1000
    fish = simulateFishing(3,1); % Haukvatnet
    salmonCash = salmonCash + salmonPrice * sum(fish.salmon);
    troutCash = troutCash + troutPrice * sum(fish.trout);
end
haukvatnetCash = (salmonCash + troutCash) / 1000;
fprintf('Forventet gevinst for Nidelva: %2.0f kr\n', nidelvaCash);
fprintf('Forventet gevinst for Haukvatnet: %2.0f kr\n', haukvatnetCash);
if nidelvaCash > haukvatnetCash 
    fprintf('Fisk i Nidelva!\n');
else
    fprintf('Fisk i Haukvatnet!\n');
end
end
  • No labels