function [ MaxCurr ] = ComputeMaxBattCurrent(RectifiedVoltage,TargetCurrent)

persistent pp;

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 155 156  500];
III = [0 0  0 14  14   0  0   45  45   0   0];


if(~isstruct(pp)) 
    pp = interp1(VVV,III,'linear','pp');
    
figure
plot([0:500],ppval(pp,[0:500]),VVV,III,'x');
end


MaxCurrVI = 0.85*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

