close all
clear all

C = 80;  %A-Hr;

Current = 0:2:40;

Voltage = NaN(length(Current),13);

Voltage(1:4,1) = [12.7 12.95 13.05 14.6];
Voltage(1:4,2) = [12.7 12.95 13.05 14.6];
ColorOrder(1,:) = [0     0   1.0000];
ColorOrder(2,:) = [0     0   1.0000];

Voltage(1:13,3) = [12.5 12.53 12.60 12.67 12.73 12.80 12.94 13.07 13.20 13.35 13.46 13.60 13.71];
Voltage(1:13,4) = [13.0 13.18 13.24 13.30 13.36 13.41 13.48 13.53 13.6 13.65 13.70 13.72 13.73];
ColorOrder(3,:) = [0     .5   0];
ColorOrder(4,:) = [0     .5   0];

Voltage(:,5) = [12.35 12.37 12.42 12.48 12.56 12.62 12.73 12.82 12.94 13.01 13.11 13.20 13.26 13.33 13.40 13.45 13.5 13.56 13.62 13.68 13.74]; 
Voltage(:,6) = [12.82 12.87 12.91 12.95 13.01 13.05 13.09 13.14 13.18 13.23 13.27 13.32 13.36 13.41 13.46 13.50 13.56 13.61 13.65 13.71 13.74];
ColorOrder(5,:) = [1     0   0];
ColorOrder(6,:) = [1     0   0];

Voltage(:,7) = [11.96 11.99 12.04 12.09 12.15 12.20 12.30 12.37 12.45 12.55 12.69 12.72 12.78 12.85 12.92 12.97 13.01 13.07 13.10 13.15 13.19];
Voltage(:,8) = [12.37 12.43 12.47 12.51 12.57 12.61 12.65 12.69 12.74 12.78 12.82 12.87 12.89 12.94 12.98 13.01 13.06 13.08 13.14 13.16 13.19];
ColorOrder(7,:) = [0   0.7500    0.7500];
ColorOrder(8,:) = [0   0.7500    0.7500];


Voltage(:,9) = [11.66 11.71 11.77 11.83 11.89 11.98 12.08 12.19 12.29 12.41 12.50 12.63 12.74 12.86 12.97 13.07 13.16 13.25 13.33 13.40 13.47]; 
Voltage(:,10) = [11.99 12.05 12.11 12.12 12.23 12.30 12.37 12.43 12.51 12.60 12.69 12.76 12.86 12.93 13.01 13.10 13.17 13.25 13.33 13.41 13.47];    
ColorOrder(9,:) = [0.7500  0  0.7500];
ColorOrder(10,:) = [0.7500  0  0.7500];

Voltage(:,11) = [11.22 11.34 11.45 11.57 11.70 11.85 12.02 12.17 12.34 12.52 12.69 12.82 12.95 13.06 13.17 13.25 13.33 13.40 13.49 13.55 13.61];
Voltage(:,12) = [11.65 11.72 11.79 11.88 11.97 12.06 12.16 12.27 12.37 12.47 12.57 12.68 12.78 12.88 12.98 13.07 13.18 13.28 13.40 13.52 13.61];
ColorOrder(11,:) = [0.7500   0.7500  0];
ColorOrder(12,:) = [0.7500  0.7500  0];

Voltage(1:16,13) = [10.66 10.93 11.22 11.48 11.89 12.22 12.54 12.79 13.05 13.24 13.43 13.55 13.66 13.80 13.94 14.05];

figure
plot(Voltage,Current/C); 
%set(gca,'ColorOrder',ColorOrder);
xlabel('Voltage');
ylabel('Charge Rate (A/C)');
title('80 A-Hr 6-cell AGM Charge Behavior');
hold all

N = 6;
C = 80;

V = 10.5:.05:14;

T = .5;
S = 0.5;

m = 2.5*T+0.5;
I = (V/N-(10.5/6+S*(14-10.5)/6))*C*m;
idx = find(I<0);
I(idx) = 0;

plot(V,I/C,'r.');
foo = axis;
foo(4) = 0.5;
axis(foo);


