function [ MaxCurr ] = ComputeMaxBattCurrent(RectifiedVoltage,TargetCurrent)

persistent pp;

if(~isstruct(pp)) 
VVV = [0 155 156 500];
III = [14 14  45  45];

VVV = [0 35 40 120 140 150 165 250 400 425 500];
III = [0 0  0 14  14   0  0   45  45   0   0];

VVV = [0 40 120 140 160 170 250 400 425 500];
III = [0 0   14  14   0   0   45  45   0   0];



    pp = interp1(VVV,III,'linear','pp');
    
figure
plot([0:500],ppval(pp,[0:500]),VVV,III,'x');
end


MaxCurrVI = 0.8*RectifiedVoltage*TargetCurrent/27;
           %MaxCurrVC = (RectifiedVoltage.*(RectifiedVoltage-34)/6.5)/27;
%MaxCurrVC = (RectifiedVoltage.*(RectifiedVoltage-34)/4)/27;
%MaxCurr1 = min(MaxCurrVI,MaxCurrVC);
     


MaxCurr = min(ppval(pp,RectifiedVoltage),MaxCurrVI);
           
disp(['MaxCurr = ' num2str(MaxCurr) ' MaxCurrVI =  ' num2str(MaxCurrVI)]);

            

end

