%------------------------------------------------------------
% Tony Hyun Kim
% 6.012, PS#6, Problem 1
%------------------------------------------------------------

% Part a
v_below_th = linspace(0,1);
v_above_th = linspace(1,6,500);
i_above_th = 0.08*(v_above_th-1).^2;
subplot(311);
plot(v_below_th,zeros(1,100));
hold on;
plot(v_above_th,i_above_th);
xlabel('V_{AB} in volts');
ylabel('I_D in mA');
grid on;
title('Problem 1, part a');

% Part b
v = linspace(0,6,600);
i = 28*(1/2*v.^2+9*v)/1000;
subplot(312);
plot(v,i);
xlabel('V_{AB} in volts');
ylabel('I_D in mA');
grid on;
title('Problem 1, part b');

% Part c
v_lower = linspace(0,2,200);
v_upper = linspace(2,6,400);
i_lower = (2-v_lower/2).*v_lower;
i_upper = 2*ones(1,400);
subplot(313);
plot(v_lower, i_lower);
hold on;
plot(v_upper, i_upper);
xlabel('V_{AB} in volts');
ylabel('I_D in mA');
grid on;
title('Problem 1, part c');

