1;
global Vout = 15;
global Rtop = 1000;
global temp = [ -50, -25, 0, 25, 50, 75, 100, 125, 150];
global lm317Iadj = [ 4.2e-05, 4.6e-05, 5.1e-05, 5.3e-05, 5.6e-05, 5.7e-05, 5.7e-05, 5.7e-05, 5.7e-05];
global lm337Iadj = [ 6.9e-05, 6.7e-05, 6.6e-05, 6.5e-05, 6.6e-05, 6.7e-05, 6.9e-05, 7e-05, 7.2e-05];
global lm317Vref = [ 1.246, 1.248, 1.25, 1.25, 1.2495, 1.248, 1.2455, 1.243, 1.24];
global lm337Vref = [ 1.2525, 1.252, 1.252, 1.252, 1.252, 1.2515, 1.251, 1.2505, 1.249];

function Iadj = lm3x7Iadj(t)
  global Vout;
  global temp;
  global lm317Iadj;
  global lm337Iadj;

  if (Vout < 0)
    arr = lm337Iadj;
  else
   arr = lm317Iadj;
  endif

  Iadj = interp1(temp, arr, t, "*linear");
endfunction

function Vref = lm3x7Vref(t)
  global Vout;
  global temp;
  global lm317Vref;
  global lm337Vref;

  if (Vout < 0)
    arr = lm337Vref;
  else
   arr = lm317Vref;
  endif

  Vref = interp1(temp, arr, t, "*linear");
endfunction

function rbot = rbot(t)
  global Vout;
  global Rtop;

  vref = lm3x7Vref(t);
  iadj = lm3x7Iadj(t);

  rbot = (Vout - vref) ./ ( vref ./ Rtop + iadj);
endfunction

function vout = vout(t,rbot)
  global Vout;
  global Rtop;

  vref = lm3x7Vref(t);
  iadj = lm3x7Iadj(t);

  vout = vref .* ( 1 + rbot / Rtop ) + rbot * iadj;
endfunction
