<html>
<head><title>question5.m</title></head>
<body>
<pre>
% uses bisection method to estimate maximum power input that can be supported
% by 4cm x 4cm fins of various thermal conductivities while remaining below 80C
% WARNING: takes several minutes to run - to speed up, consider reducing iterations
% (line 17) or grid size (lines 11-12).
kvals = 1 + 4 * (0:32) / 32;
maxpow = zeros(33,1);
for i = 1:33
    min = 5;
    max = 9.096;
    % bisection method
    minheat = coolingfin(0, 4, 0, 4, 1, 3, min, kvals(i), 0.005, 80, 80);
    maxheat = coolingfin(0, 4, 0, 4, 1, 3, max, kvals(i), 0.005, 80, 80);
    if (minheat > 80 || maxheat < 80)
        disp('Uh oh')
        continue;
    end
    for iter = 1:11
        mid = (min + max) / 2;
        midheat = coolingfin(0, 4, 0, 4, 1, 3, mid, kvals(i), 0.005, 80, 80, 0, 200);
        if midheat < 80
            min = mid;
            minheat = midheat;
        else
            max = mid;
            maxheat = midheat;
        end
    end
    maxpow(i) = (min + max) / 2;
end
scatter(kvals, maxpow);
title({'Power Input Capacity of a 4cm x 4cm Cooling Fin', 'While Remaining Below 80 Celcius'});
xlabel({'Thermal Conductivity', '(W/cm/^{o}C)'});
ylabel('Maximum Power Input (W)')
kvals'
maxpow
</pre>
</body>
</html>