close all
clear all

V = 0:10:600;
I = 0:.5:20;

R = 10;  %Ohms

Pr = zeros(length(I),length(V));
Pd = zeros(length(I),length(V));
Pt = zeros(length(I),length(V));
V1 = zeros(length(I),length(V));

for i = 1:length(I)
 for j = 1:length(V)
 Pr(i,j) = R*I(i)^2;
 V1(i,j) = V(j)-I(i)*R;
 Pd(i,j) = V1(i,j)*I(i);
 end
end
Pt = Pr+Pd;

Pt_redact = Pt;
Pd_redact = Pd;
Pr_redact = Pr;
for i = 1:length(I)
    for j = 1:length(V)
        if((Pd(i,j) < 0) || Pd(i,j) > 6000)
           Pt_redact(i,j)=NaN;
           Pd_redact(i,j)=NaN;
           Pr_redact(i,j)=NaN;
        end
    end
end

figure
surfc(V,I,Pr);
xlabel('V (Volts)');
ylabel('I (Amps)');
zlabel('Resistor Power (W)');

fh = figure('Position',[163 403 1124 695],'PaperOrientation','landscape','PaperPosition',[0 0 11 8.5]);
surfc(V,I,Pd_redact);
set(gca,'FontSize',14);
set(gca,'View',[0.5 90]);
xlabel('V (Volts)');
ylabel('I (Amps)');
zlabel('Load Dump Power (W)');
title('Load dump power (W) with R = 10 Ohms');
colorbar
print('-dpdf','LoadDumpPower_R10');

fh = figure('Position',[163 403 1124 695],'PaperOrientation','landscape','PaperPosition',[0 0 11 8.5]);
surfc(V,I,Pt_redact);
set(gca,'FontSize',14);
set(gca,'View',[0.5 90]);
xlabel('V (Volts)');
ylabel('I (Amps)');
zlabel('Total Power (W)');
title('Achievable total power (W) with R = 10 Ohms');
colorbar
print('-dpdf','TotalPower_R10');

fh = figure('Position',[163 403 1124 695],'PaperOrientation','landscape','PaperPosition',[0 0 11 8.5]);
surfc(V,I,Pr_redact);
set(gca,'FontSize',14);
set(gca,'View',[0.5 90]);
xlabel('V (Volts)');
ylabel('I (Amps)');
zlabel('Total Power (W)');
title('Resistor power (W) with R = 10 Ohms');
colorbar
print('-dpdf','ResistorPower_R10');

figure
surfc(V,I,V1);
xlabel('V (Volts)');
ylabel('I (Amps)');
zlabel('Load Dump Voltage (Volts)');