function response = equations(var,inp,f)
% Expresses the variables and constraints of a linear circuit model.
% Input frequency parameter f is in Hz.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This file was automatically generated by mpp.pl
% based on equations.mpp so do not make changes here!
% Edit equations.mpp to make changes, and regenerate
% this file using the mpp.pl tool.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

  w = 2*pi*f;

% resistor values (Ohms) - named after the v2 schematics
  R1 = 200;
  R18 = 100; %100e3;
  R19 = 270;
  R2 = 3.3e3; %787;
  R3 = 1.1e3; %261;
  R4 = 1.5e3; %365;
  R20 = 220;
  R22 = 365;
  R5 = 560;
  RBi = 5.6e3;
  R6 = 1000;
  RBi1 = 5.6e3;
  R7 = 120;
  R8 = 1000;
  R9 = 200;
% control the gain switch here
  R10 = 82e0; 
  R11 = 1500;
  R12 = 100;
  R13 = 560;
  R14 = 180;
  R15 = 2000;
  R16 = 392;
  RC = 2.49e3;
  RD = 2.0e3;
  R17 = 698;
  RF = 1000; 

% external termination resistors
  Rs = 50;
  Rt = 50;

% parasitic capacitances of resistors (F)
  CR1 = 0;
  CR18 = 0;
  CR19 = 0;
  CR2 = 0;
  CR3 = 0;
  CR4 = 0;
  CR20 = 0;
  CR22 = 0;
  CR5 = 0;
  CRBi = 0;
  CR6 = 0;
  CRBi1 = 0;
  CR7 = 0;
  CR8 = 0;
  CR9 = 0;
  CR10 = 0;
  CR11 = 0;
  CR12 = 0;
  CR13 = 0;
  CR14 = 0;
  CR15 = 0;
  CR16 = 0;
  CRC = 0;
  CRD = 0;
  CR17 = 0;
  CRF = 0; 
  CRs = 0;
  CRt = 0;

% parasitic capacitances of transitor terminals (F)
  Q0CCE = 1e-13; % collector-emittor capacitor for transistor Q0
  Q0CBE = 1e-13; % base-emitter capacitor for transistor Q0
  Q1CCE = 1e-13; % collector-emittier capacitor for transistor Q1
  Q1CBE = 1e-13; % base-emitter capacitor for transistor Q1

% parasitic inductances of resistors and leads (H)
  LR1 = 0;
  LR18 = 0;
  LR19 = 0;
  LR2 = 0;
  LR3 = 0;
  LR4 = 0;
  LR20 = 0;
  LR22 = 0;
  LR5 = 0;
  LRBi = 0;
  LR6 = 0;
  LRBi1 = 0;
  LR7 = 0;
  LR8 = 0;
  LR9 = 0;
  LR10 = 0;
  LR11 = 0;
  LR12 = 0;
  LR13 = 0;
  LR14 = 0;
  LR15 = 0;
  LR16 = 0;
  LRC = 0;
  LRD = 0;
  LR17 = 0;
  LRF = 0; 
  LRs = 0;
  LRt = 0;
  
  % frequency-dependent impedence of resistors (Ohms)
  ZR1 = 1/((1/R1)+i*w*CR1)+i*w*LR1;
  ZR18 = 1/((1/R18)+i*w*CR18)+i*w*LR18;
  ZR19 = 1/((1/R19)+i*w*CR19)+i*w*LR19;
  ZR2 = 1/((1/R2)+i*w*CR2)+i*w*LR2;
  ZR3 = 1/((1/R3)+i*w*CR3)+i*w*LR3;
  ZR4 = 1/((1/R4)+i*w*CR4)+i*w*LR4;
  ZR20 = 1/((1/R20)+i*w*CR20)+i*w*LR20;
  ZR22 = 1/((1/R22)+i*w*CR22)+i*w*LR22;
  ZR5 = 1/((1/R5)+i*w*CR5)+i*w*LR5;
  ZRBi = 1/((1/RBi)+i*w*CRBi)+i*w*LRBi;
  ZR6 = 1/((1/R6)+i*w*CR6)+i*w*LR6;
  ZRBi1 = 1/((1/RBi1)+i*w*CRBi1)+i*w*LRBi1;
  ZR7 = 1/((1/R7)+i*w*CR7)+i*w*LR7;
  ZR8 = 1/((1/R8)+i*w*CR8)+i*w*LR8;
  ZR9 = 1/((1/R9)+i*w*CR9)+i*w*LR9;
  ZR10 = 1/((1/R10)+i*w*CR10)+i*w*LR10;
  ZR11 = 1/((1/R11)+i*w*CR11)+i*w*LR11;
  ZR12 = 1/((1/R12)+i*w*CR12)+i*w*LR12;
  ZR13 = 1/((1/R13)+i*w*CR13)+i*w*LR13;
  ZR14 = 1/((1/R14)+i*w*CR14)+i*w*LR14;
  ZR15 = 1/((1/R15)+i*w*CR15)+i*w*LR15;
  ZR16 = 1/((1/R16)+i*w*CR16)+i*w*LR16;
  ZRC = 1/((1/RC)+i*w*CRC)+i*w*LRC;
  ZRD = 1/((1/RD)+i*w*CRD)+i*w*LRD;
  ZR17 = 1/((1/R17)+i*w*CR17)+i*w*LR17;
  ZRF = 1/((1/RF)+i*w*CRF)+i*w*LRF;
  ZRs = 1/((1/Rs)+i*w*CRs)+i*w*LRs;
  ZRt = 1/((1/Rt)+i*w*CRt)+i*w*LRt;

  % Capacitor values (F)
  C1 = 10e-9;
  C2 = 10e-9;
  C3 = 47e-9;
  C4 = 10e-9;
  C5 = 47e-9;
  C22 = 10e-9;
  CBi = 10e-9;
  C6 = 47e-9;
  CBi1 = 10e-9;
  C7 = 47e-9;
  C8 = 23e-9;  % this is C8 and CG in series, and includes the switch
  C9 = 47e-9;
  C10 = 10e-9;
  CE = 10e-9;
  CS = 8*320e-12; % capacitance of the MPPC

  % parasitic inductances in series with capacitors (H)
  LC1 = 0;
  LC2 = 0;
  LC3 = 0;
  LC4 = 0;
  LC5 = 0;
  LC22 = 0;
  LCBi = 0;
  LC6 = 0;
  LCBi1 = 0;
  LC7 = 0;
  LC8 = 0;  % this is C8 and CG in series, and includes the switch
  LC9 = 0;
  LC10 = 0;
  LCE = 0;
  LCS = 0;
  
  % frequency-dependent impedence of capacitors (Ohms)
  ZC1 = i*(w*LC1-1/(w*C1));
  ZC2 = i*(w*LC2-1/(w*C2));
  ZC3 = i*(w*LC3-1/(w*C3));
  ZC4 = i*(w*LC4-1/(w*C4));
  ZC5 = i*(w*LC5-1/(w*C5));
  ZC22 = i*(w*LC22-1/(w*C22));
  ZCBi = i*(w*LCBi-1/(w*CBi));
  ZC6 = i*(w*LC6-1/(w*C6));
  ZCBi1 = i*(w*LCBi1-1/(w*CBi1));
  ZC7 = i*(w*LC7-1/(w*C7));
  ZC8 = i*(w*LC8-1/(w*C8));
  ZC9 = i*(w*LC9-1/(w*C9));
  ZC10 = i*(w*LC10-1/(w*C10));
  ZCE = i*(w*LCE-1/(w*CE));
  ZCS = i*(w*LCS-1/(w*CS));

  % dc bias levels (V)
  VBias = 70 + 0;
  Vpower = 5.74 + 0;
%  VAmpref = 3.64 + 0;
  VAmpref = 2.74 + 0;
  VSumref = 4.02 + 0;
  Iin = 50e-6 + 0;

  % physical constant kT/e
  VT = 25.6e-3;

  % set the initial operating points for transistors
  % currents are in Amperes
  % junction potentials are in V
  % junction conductances 1/Ohms
  global Q0Vbe0 Q0Ie0 B0 Q0;
  global Q1Vbe0 Q1Ie0 B1 Q1;
  global Q2Vbe0 Q2Ie0 B2 Q2;
  global Q3Vbe0 Q3Ie0 B3 Q3;
  global Q4Vbe0 Q4Ie0 B4 Q4;
  global Q8Vbe0 Q8Ie0 B8 Q8;
  global Q5Vbe0 Q5Ie0 B5 Q5;
  global Q6Vbe0 Q6Ie0 B6 Q6;
  global Q7Vbe0 Q7Ie0 B7 Q7;
  if isempty(Q0Vbe0)
    Q0Vbe0 = 0.66;
    Q0Ie0 = 2.1e-3;
    Q1Vbe0 = 0.74;
    Q1Ie0 = 2.1e-3;
    Q2Vbe0 = 0.64;
    Q2Ie0 = 1.0e-3;
    Q3Vbe0 = 0.64;
    Q3Ie0 = 1.0e-3;
    Q4Vbe0 = 0.64;
    Q4Ie0 = 1.0e-3;
    Q8Vbe0 = 0.73;
    Q8Ie0 = 1.5e-3;
    Q5Vbe0 = 0.73;
    Q5Ie0 = 1.8e-3;
    Q6Vbe0 = 0.63;
    Q6Ie0 = 1.0e-3;
    Q7Vbe0 = 0.68;
    Q7Ie0 = 3.6e-3;
    B0 = 100;
    B1 = 100;
    B2 = 100;
    B3 = 100;
    B4 = 100;
    B8 = 100;
    B5 = 100;
    B6 = 100;
    B7 = 100;
    Q0 = Q0Ie0/VT;
    Q1 = Q1Ie0/VT;
    Q2 = Q2Ie0/VT;
    Q3 = Q3Ie0/VT;
    Q4 = Q4Ie0/VT;
    Q8 = Q8Ie0/VT;
    Q5 = Q5Ie0/VT;
    Q6 = Q6Ie0/VT;
    Q7 = Q7Ie0/VT;
    warning('calling calibrate');
    calibrate;
  end

% these aux components mock up the behavior of the power coupling
  R27 = 30; % Ohms
  LR27 = 0.5e-9; % H
  C21 = 47e-9; % F
  LC21 = 0.5e-9; % F
  ZR27 = R27+i*w*LR27;
  ZC21 = i*w*LC21-i/(w*C21);

% equations
% Internal voltages are named according to the following rules:
%  1) if connected to the base/emitter/collector of transitor Qn,
%	call it VQnb/VQne/VQnc.
%  2) if located on a junction between resistors Ra and Rb,
%	call it VRaRb.
%  3) if located on a junction between resistor Ra and capacitor Cb,
%	call it VRaCb.
%  4) if located on a junction between two capacitors Ca and Cb,
%	call it VCaCb.
%  5) if part of the power distribution, give it a unique name,
%	for example, VPa, VPs, etc.
% Internal currents are named according to the following rules:
%  1) if flowing on the base/emitter/collector of transistor Qn,
%	call it Jbn/Jen/Jcn.
%  2) if flowing on a resistor or capacitor Ra/Cb,
%	call it Ia/Hb.
%  3) sign convention is + for current flowing down or right on the
%	Altium circuit schematic for the preamp.

%resistors

%capacitors

%transistors

%current junctions

% power decoupling section
  Nvariables = 116;
% these are the constraints
  Nconstraints = 110;
  constraint = zeros(Nconstraints,Nvariables);
%   0 = VBias-VR18C1-I18*ZR18
  constraint(1,10) = -1; % VR18C1
  constraint(1,41) = -ZR18; % I18
  constraint(1,111) = +VBias; % constant
  constraint(1,112) = +1; % VBias
%   0 = VR19C2-I19*ZR19
  constraint(2,11) = +1; % VR19C2
  constraint(2,44) = -ZR19; % I19
%   0 = VR1R20-VQ0e-I1*ZR1
  constraint(3,12) = +1; % VR1R20
  constraint(3,21) = -1; % VQ0e
  constraint(3,53) = -ZR1; % I1
%   0 = VAmpref-VQ0b-IBi*ZRBi
  constraint(4,22) = -1; % VQ0b
  constraint(4,47) = -ZRBi; % IBi
  constraint(4,111) = +VAmpref; % constant
  constraint(4,114) = +1; % VAmpref
%   0 = VQ0c-I6*ZR6
  constraint(5,13) = +1; % VQ0c
  constraint(5,50) = -ZR6; % I6
%   0 = VR1R20-VPa-I20*ZR20
  constraint(6,12) = +1; % VR1R20
  constraint(6,94) = -1; % VPa
  constraint(6,95) = -ZR20; % I20
%   0 = VQ1b-I3*ZR3
  constraint(7,23) = +1; % VQ1b
  constraint(7,55) = -ZR3; % I3
%   0 = VQ1b-VQ1c-I2*ZR2
  constraint(8,23) = +1; % VQ1b
  constraint(8,28) = -1; % VQ1c
  constraint(8,57) = -ZR2; % I2
%   0 = VR22C22-VQ1c-I22*ZR22 
  constraint(9,14) = +1; % VR22C22
  constraint(9,28) = -1; % VQ1c
  constraint(9,61) = -ZR22; % I22
%   0 = VPa-VQ1c-I4*ZR4
  constraint(10,28) = -1; % VQ1c
  constraint(10,94) = +1; % VPa
  constraint(10,96) = -ZR4; % I4
%   0 = VQ1e
  constraint(11,1) = +1; % VQ1e
%   0 = VPa-VQ2e-I5*ZR5
  constraint(12,26) = -1; % VQ2e
  constraint(12,94) = +1; % VPa
  constraint(12,97) = -ZR5; % I5
%   0 = VQ2b-VQ1c
  constraint(13,2) = +1; % VQ2b
  constraint(13,28) = -1; % VQ1c
%   0 = VQ2c
  constraint(14,3) = +1; % VQ2c
%   0 = Vt-It*ZRt
  constraint(15,15) = +1; % Vt
  constraint(15,64) = -ZRt; % It
%   0 = VPa-VR7C6-I7*ZR7
  constraint(16,16) = -1; % VR7C6
  constraint(16,94) = +1; % VPa
  constraint(16,99) = -ZR7; % I7
%   0 = VPa-VQ3e-I8*ZR8
  constraint(17,27) = -1; % VQ3e
  constraint(17,94) = +1; % VPa
  constraint(17,98) = -ZR8; % I8
%   0 = VQ3c-I9*ZR9
  constraint(18,17) = +1; % VQ3c
  constraint(18,68) = -ZR9; % I9
%   0 = VQ3b-VQ1c
  constraint(19,4) = +1; % VQ3b
  constraint(19,28) = -1; % VQ1c
%   0 = VPs-VQ4e+I12*ZR12
  constraint(20,29) = -1; % VQ4e
  constraint(20,102) = +1; % VPs
  constraint(20,103) = +ZR12; % I12
%   0 = VSumref-VQ4b-IBi1*ZRBi1
  constraint(21,30) = -1; % VQ4b
  constraint(21,71) = -ZRBi1; % IBi1
  constraint(21,111) = +VSumref; % constant
  constraint(21,115) = +1; % VSumref
%   0 = VQ4c-VR10C8-I10*ZR10
  constraint(22,18) = -1; % VR10C8
  constraint(22,32) = +1; % VQ4c
  constraint(22,77) = -ZR10; % I10
%   0 = VQ4c-I11*ZR11
  constraint(23,32) = +1; % VQ4c
  constraint(23,75) = -ZR11; % I11
%   0 = VQ8e-VQ5b-IF*ZRF
  constraint(24,33) = +1; % VQ8e
  constraint(24,34) = -1; % VQ5b
  constraint(24,81) = -ZRF; % IF
%   0 = VQ8c-VPa
  constraint(25,5) = +1; % VQ8c
  constraint(25,94) = -1; % VPa
%   0 = VQ8b-VQ4c
  constraint(26,6) = +1; % VQ8b
  constraint(26,32) = -1; % VQ4c
%   0 = VQ5b-I17*ZR17
  constraint(27,34) = +1; % VQ5b
  constraint(27,82) = -ZR17; % I17
%   0 = VQ5e-I14*ZR14
  constraint(28,35) = +1; % VQ5e
  constraint(28,84) = -ZR14; % I14
%   0 = VPs-VQ5c-I13*ZR13
  constraint(29,19) = -1; % VQ5c
  constraint(29,102) = +1; % VPs
  constraint(29,105) = -ZR13; % I13
%   0 = VPs-VQ6b-IC*ZRC
  constraint(30,37) = -1; % VQ6b
  constraint(30,102) = +1; % VPs
  constraint(30,106) = -ZRC; % IC
%   0 = VQ6b-ID*ZRD
  constraint(31,37) = +1; % VQ6b
  constraint(31,87) = -ZRD; % ID
%   0 = VPs-VQ6e-I15*ZR15
  constraint(32,40) = -1; % VQ6e
  constraint(32,102) = +1; % VPs
  constraint(32,107) = -ZR15; % I15
%   0 = VQ6c
  constraint(33,7) = +1; % VQ6c
%   0 = VPs-VQ7e-I16*ZR16
  constraint(34,39) = -1; % VQ7e
  constraint(34,102) = +1; % VPs
  constraint(34,108) = -ZR16; % I16
%   0 = VQ7b-VQ6e
  constraint(35,8) = +1; % VQ7b
  constraint(35,40) = -1; % VQ6e
%   0 = VQ7c
  constraint(36,9) = +1; % VQ7c
%   0 = Vs-Is*ZRs
  constraint(37,20) = +1; % Vs
  constraint(37,93) = -ZRs; % Is
%   0 = VR18C1-H1*ZC1
  constraint(38,10) = +1; % VR18C1
  constraint(38,42) = -ZC1; % H1
%   0 = VR18C1-VR19C2-HS*ZCS
  constraint(39,10) = +1; % VR18C1
  constraint(39,11) = -1; % VR19C2
  constraint(39,43) = -ZCS; % HS
%   0 = VR19C2-VQ0e-H2*ZC2
  constraint(40,11) = +1; % VR19C2
  constraint(40,21) = -1; % VQ0e
  constraint(40,45) = -ZC2; % H2
%   0 = VR1R20+H3*ZC3
  constraint(41,12) = +1; % VR1R20
  constraint(41,52) = +ZC3; % H3
%   0 = VQ0b-HBi*ZCBi
  constraint(42,22) = +1; % VQ0b
  constraint(42,48) = -ZCBi; % HBi
%   0 = VQ1b-VQ0c-H4*ZC4
  constraint(43,13) = -1; % VQ0c
  constraint(43,23) = +1; % VQ1b
  constraint(43,54) = -ZC4; % H4
%   0 = VQ1b-VR22C22-I22*ZC22
  constraint(44,14) = -1; % VR22C22
  constraint(44,23) = +1; % VQ1b
  constraint(44,61) = -ZC22; % I22
%   0 = VQ2e-Vt-H5*ZC5
  constraint(45,15) = -1; % Vt
  constraint(45,26) = +1; % VQ2e
  constraint(45,63) = -ZC5; % H5
%   0 = VQ3e-VR7C6-H6*ZC6
  constraint(46,16) = -1; % VR7C6
  constraint(46,27) = +1; % VQ3e
  constraint(46,66) = -ZC6; % H6
%   0 = VQ4e-VQ3c-H7*ZC7
  constraint(47,17) = -1; % VQ3c
  constraint(47,29) = +1; % VQ4e
  constraint(47,69) = -ZC7; % H7
%   0 = VQ4b+HBi1*ZCBi1
  constraint(48,30) = +1; % VQ4b
  constraint(48,72) = +ZCBi1; % HBi1
%   0 = VR10C8-H8*ZC8
  constraint(49,18) = +1; % VR10C8
  constraint(49,76) = -ZC8; % H8
%   0 = VQ8e-VQ5b-HE*ZCE
  constraint(50,33) = +1; % VQ8e
  constraint(50,34) = -1; % VQ5b
  constraint(50,79) = -ZCE; % HE
%   0 = VQ5c-VQ6b-H10*ZC10
  constraint(51,19) = +1; % VQ5c
  constraint(51,37) = -1; % VQ6b
  constraint(51,86) = -ZC10; % H10
%   0 = VQ7e-Vs-H9*ZC9
  constraint(52,20) = -1; % Vs
  constraint(52,39) = +1; % VQ7e
  constraint(52,92) = -ZC9; % H9
%   0 = Jb0-Jc0+Je0
  constraint(53,46) = +1; % Je0
  constraint(53,49) = +1; % Jb0
  constraint(53,51) = -1; % Jc0
%   0 = Jc0+B0*Jb0
  constraint(54,49) = +B0; % Jb0
  constraint(54,51) = +1; % Jc0
%   0 = VQ0e*Q0-VQ0b*Q0-Q0Vbe0*Q0+Q0Ie0-Je0
  constraint(55,21) = +Q0; % VQ0e
  constraint(55,22) = -Q0; % VQ0b
  constraint(55,46) = -1; % Je0
  constraint(55,111) = -Q0Vbe0*Q0+Q0Ie0; % constant
%   0 = Jb1+Jc1-Je1
  constraint(56,24) = -1; % Je1
  constraint(56,56) = +1; % Jb1
  constraint(56,58) = +1; % Jc1
%   0 = Jc1-B1*Jb1
  constraint(57,56) = -B1; % Jb1
  constraint(57,58) = +1; % Jc1
%   0 = VQ1b*Q1-Q1Vbe0*Q1+Q1Ie0-Je1
  constraint(58,23) = +Q1; % VQ1b
  constraint(58,24) = -1; % Je1
  constraint(58,111) = -Q1Vbe0*Q1+Q1Ie0; % constant
%   0 = Jb2+Je2-Jc2
  constraint(59,25) = -1; % Jc2
  constraint(59,60) = +1; % Jb2
  constraint(59,62) = +1; % Je2
%   0 = Jc2+B2*Jb2
  constraint(60,25) = +1; % Jc2
  constraint(60,60) = +B2; % Jb2
%   0 = VQ2e*Q2-VQ1c*Q2-Q2Vbe0*Q2+Q2Ie0-Je2
  constraint(61,26) = +Q2; % VQ2e
  constraint(61,28) = -Q2; % VQ1c
  constraint(61,62) = -1; % Je2
  constraint(61,111) = -Q2Vbe0*Q2+Q2Ie0; % constant
%   0 = Jb3+Je3-Jc3
  constraint(62,59) = +1; % Jb3
  constraint(62,65) = +1; % Je3
  constraint(62,67) = -1; % Jc3
%   0 = Jc3+B3*Jb3
  constraint(63,59) = +B3; % Jb3
  constraint(63,67) = +1; % Jc3
%   0 = VQ3e*Q3-VQ1c*Q3-Q3Vbe0*Q3+Q3Ie0-Je3
  constraint(64,27) = +Q3; % VQ3e
  constraint(64,28) = -Q3; % VQ1c
  constraint(64,65) = -1; % Je3
  constraint(64,111) = -Q3Vbe0*Q3+Q3Ie0; % constant
%   0 = Jb4-Jc4+Je4
  constraint(65,70) = +1; % Je4
  constraint(65,73) = +1; % Jb4
  constraint(65,74) = -1; % Jc4
%   0 = Jc4+B4*Jb4
  constraint(66,73) = +B4; % Jb4
  constraint(66,74) = +1; % Jc4
%   0 = VQ4e*Q4-VQ4b*Q4-Q4Vbe0*Q4+Q4Ie0-Je4
  constraint(67,29) = +Q4; % VQ4e
  constraint(67,30) = -Q4; % VQ4b
  constraint(67,70) = -1; % Je4
  constraint(67,111) = -Q4Vbe0*Q4+Q4Ie0; % constant
%   0 = Jb8+Jc8-Je8
  constraint(68,31) = +1; % Jb8
  constraint(68,78) = -1; % Je8
  constraint(68,104) = +1; % Jc8
%   0 = Jc8-B8*Jb8
  constraint(69,31) = -B8; % Jb8
  constraint(69,104) = +1; % Jc8
%   0 = VQ4c*Q8-VQ8e*Q8-Q8Vbe0*Q8+Q8Ie0-Je8
  constraint(70,32) = +Q8; % VQ4c
  constraint(70,33) = -Q8; % VQ8e
  constraint(70,78) = -1; % Je8
  constraint(70,111) = -Q8Vbe0*Q8+Q8Ie0; % constant
%   0 = Jb5+Jc5-Je5
  constraint(71,80) = +1; % Jb5
  constraint(71,83) = -1; % Je5
  constraint(71,85) = +1; % Jc5
%   0 = Jc5-B5*Jb5
  constraint(72,80) = -B5; % Jb5
  constraint(72,85) = +1; % Jc5
%   0 = VQ5b*Q5-VQ5e*Q5-Q5Vbe0*Q5+Q5Ie0-Je5
  constraint(73,34) = +Q5; % VQ5b
  constraint(73,35) = -Q5; % VQ5e
  constraint(73,83) = -1; % Je5
  constraint(73,111) = -Q5Vbe0*Q5+Q5Ie0; % constant
%   0 = Jb6+Je6-Jc6
  constraint(74,36) = -1; % Jc6
  constraint(74,88) = +1; % Jb6
  constraint(74,90) = +1; % Je6
%   0 = Jc6+B6*Jb6
  constraint(75,36) = +1; % Jc6
  constraint(75,88) = +B6; % Jb6
%   0 = VQ6e*Q6-VQ6b*Q6-Q6Vbe0*Q6+Q6Ie0-Je6
  constraint(76,37) = -Q6; % VQ6b
  constraint(76,40) = +Q6; % VQ6e
  constraint(76,90) = -1; % Je6
  constraint(76,111) = -Q6Vbe0*Q6+Q6Ie0; % constant
%   0 = Jb7+Je7-Jc7
  constraint(77,38) = -1; % Jc7
  constraint(77,89) = +1; % Jb7
  constraint(77,91) = +1; % Je7
%   0 = Jc7+B7*Jb7
  constraint(78,38) = +1; % Jc7
  constraint(78,89) = +B7; % Jb7
%   0 = VQ7e*Q7-VQ6e*Q7-Q7Vbe0*Q7+Q7Ie0-Je7
  constraint(79,39) = +Q7; % VQ7e
  constraint(79,40) = -Q7; % VQ6e
  constraint(79,91) = -1; % Je7
  constraint(79,111) = -Q7Vbe0*Q7+Q7Ie0; % constant
%   0 = I18-H1-HS-Iin
  constraint(80,41) = +1; % I18
  constraint(80,42) = -1; % H1
  constraint(80,43) = -1; % HS
  constraint(80,111) = -Iin; % constant
  constraint(80,116) = -1; % Iin
%   0 = HS+Iin-I19-H2
  constraint(81,43) = +1; % HS
  constraint(81,44) = -1; % I19
  constraint(81,45) = -1; % H2
  constraint(81,111) = +Iin; % constant
  constraint(81,116) = +1; % Iin
%   0 = H2+I1-Je0
  constraint(82,45) = +1; % H2
  constraint(82,46) = -1; % Je0
  constraint(82,53) = +1; % I1
%   0 = IBi-HBi-Jb0
  constraint(83,47) = +1; % IBi
  constraint(83,48) = -1; % HBi
  constraint(83,49) = -1; % Jb0
%   0 = I6+H4-Jc0
  constraint(84,50) = +1; % I6
  constraint(84,51) = -1; % Jc0
  constraint(84,54) = +1; % H4
%   0 = H3-I1-I20
  constraint(85,52) = +1; % H3
  constraint(85,53) = -1; % I1
  constraint(85,95) = -1; % I20
%   0 = H4-I3-I2-Jb1-I22
  constraint(86,54) = +1; % H4
  constraint(86,55) = -1; % I3
  constraint(86,56) = -1; % Jb1
  constraint(86,57) = -1; % I2
  constraint(86,61) = -1; % I22
%   0 = I2+I4-Jc1-Jb3-Jb2+I22
  constraint(87,57) = +1; % I2
  constraint(87,58) = -1; % Jc1
  constraint(87,59) = -1; % Jb3
  constraint(87,60) = -1; % Jb2
  constraint(87,61) = +1; % I22
  constraint(87,96) = +1; % I4
%   0 = I5-H5-Je2
  constraint(88,62) = -1; % Je2
  constraint(88,63) = -1; % H5
  constraint(88,97) = +1; % I5
%   0 = H5-It
  constraint(89,63) = +1; % H5
  constraint(89,64) = -1; % It
%   0 = I8-H6-Je3
  constraint(90,65) = -1; % Je3
  constraint(90,66) = -1; % H6
  constraint(90,98) = +1; % I8
%   0 = H6+I7
  constraint(91,66) = +1; % H6
  constraint(91,99) = +1; % I7
%   0 = Jc3-I9+H7
  constraint(92,67) = +1; % Jc3
  constraint(92,68) = -1; % I9
  constraint(92,69) = +1; % H7
%   0 = H7+I12+Je4
  constraint(93,69) = +1; % H7
  constraint(93,70) = +1; % Je4
  constraint(93,103) = +1; % I12
%   0 = IBi1+HBi1-Jb4
  constraint(94,71) = +1; % IBi1
  constraint(94,72) = +1; % HBi1
  constraint(94,73) = -1; % Jb4
%   0 = Jc4-I10-I11-Jb5
  constraint(95,74) = +1; % Jc4
  constraint(95,75) = -1; % I11
  constraint(95,77) = -1; % I10
  constraint(95,80) = -1; % Jb5
%   0 = H8-I10
  constraint(96,76) = +1; % H8
  constraint(96,77) = -1; % I10
%   0 = Je8-IF-HE
  constraint(97,78) = +1; % Je8
  constraint(97,79) = -1; % HE
  constraint(97,81) = -1; % IF
%   0 = HE-Jb5+IF-I17
  constraint(98,79) = +1; % HE
  constraint(98,80) = -1; % Jb5
  constraint(98,81) = +1; % IF
  constraint(98,82) = -1; % I17
%   0 = Je5-I14
  constraint(99,83) = +1; % Je5
  constraint(99,84) = -1; % I14
%   0 = I13-H10-Jc5
  constraint(100,85) = -1; % Jc5
  constraint(100,86) = -1; % H10
  constraint(100,105) = +1; % I13
%   0 = H10+IC-ID-Jb6
  constraint(101,86) = +1; % H10
  constraint(101,87) = -1; % ID
  constraint(101,88) = -1; % Jb6
  constraint(101,106) = +1; % IC
%   0 = I15-Jb7-Je6
  constraint(102,89) = -1; % Jb7
  constraint(102,90) = -1; % Je6
  constraint(102,107) = +1; % I15
%   0 = I16-H9-Je7
  constraint(103,91) = -1; % Je7
  constraint(103,92) = -1; % H9
  constraint(103,108) = +1; % I16
%   0 = H9-Is
  constraint(104,92) = +1; % H9
  constraint(104,93) = -1; % Is
%   0 = VPa-Vpower+IPa*ZR27;
  constraint(105,94) = +1; % VPa
  constraint(105,101) = +ZR27; % IPa
  constraint(105,111) = -Vpower; % constant
  constraint(105,113) = -1; % Vpower
%   0 = VPa+HPa*ZC21;
  constraint(106,94) = +1; % VPa
  constraint(106,100) = +ZC21; % HPa
%   0 = I20-I4-I5-I8-I7+HPa+IPa;
  constraint(107,95) = +1; % I20
  constraint(107,96) = -1; % I4
  constraint(107,97) = -1; % I5
  constraint(107,98) = -1; % I8
  constraint(107,99) = -1; % I7
  constraint(107,100) = +1; % HPa
  constraint(107,101) = +1; % IPa
%   0 = VPs-Vpower+IPs*ZR27;
  constraint(108,102) = +1; % VPs
  constraint(108,110) = +ZR27; % IPs
  constraint(108,111) = -Vpower; % constant
  constraint(108,113) = -1; % Vpower
%   0 = VPs+HPs*ZC21;
  constraint(109,102) = +1; % VPs
  constraint(109,109) = +ZC21; % HPs
%   0 = I12-Jc8-I13-IC-I15-I16+HPs+IPs;
  constraint(110,103) = +1; % I12
  constraint(110,104) = -1; % Jc8
  constraint(110,105) = -1; % I13
  constraint(110,106) = -1; % IC
  constraint(110,107) = -1; % I15
  constraint(110,108) = -1; % I16
  constraint(110,109) = +1; % HPs
  constraint(110,110) = +1; % IPs

% now solve for the desired variable
% in response to the designated input signal
  ivar = index_lookup(var);
  iinp = index_lookup(inp);
  solution = constraint(:,1:Nconstraints)\constraint(:,iinp);
  if ivar == 0
    response = -solution;
  else
    response = -solution(ivar);
  end

  function ivar = index_lookup(var)
    if isnumeric(var)
      ivar = var;
    elseif strcmp(var,'VQ1e')
      ivar = 1;
    elseif strcmp(var,'VQ2b')
      ivar = 2;
    elseif strcmp(var,'VQ2c')
      ivar = 3;
    elseif strcmp(var,'VQ3b')
      ivar = 4;
    elseif strcmp(var,'VQ8c')
      ivar = 5;
    elseif strcmp(var,'VQ8b')
      ivar = 6;
    elseif strcmp(var,'VQ6c')
      ivar = 7;
    elseif strcmp(var,'VQ7b')
      ivar = 8;
    elseif strcmp(var,'VQ7c')
      ivar = 9;
    elseif strcmp(var,'VR18C1')
      ivar = 10;
    elseif strcmp(var,'VR19C2')
      ivar = 11;
    elseif strcmp(var,'VR1R20')
      ivar = 12;
    elseif strcmp(var,'VQ0c')
      ivar = 13;
    elseif strcmp(var,'VR22C22')
      ivar = 14;
    elseif strcmp(var,'Vt')
      ivar = 15;
    elseif strcmp(var,'VR7C6')
      ivar = 16;
    elseif strcmp(var,'VQ3c')
      ivar = 17;
    elseif strcmp(var,'VR10C8')
      ivar = 18;
    elseif strcmp(var,'VQ5c')
      ivar = 19;
    elseif strcmp(var,'Vs')
      ivar = 20;
    elseif strcmp(var,'VQ0e')
      ivar = 21;
    elseif strcmp(var,'VQ0b')
      ivar = 22;
    elseif strcmp(var,'VQ1b')
      ivar = 23;
    elseif strcmp(var,'Je1')
      ivar = 24;
    elseif strcmp(var,'Jc2')
      ivar = 25;
    elseif strcmp(var,'VQ2e')
      ivar = 26;
    elseif strcmp(var,'VQ3e')
      ivar = 27;
    elseif strcmp(var,'VQ1c')
      ivar = 28;
    elseif strcmp(var,'VQ4e')
      ivar = 29;
    elseif strcmp(var,'VQ4b')
      ivar = 30;
    elseif strcmp(var,'Jb8')
      ivar = 31;
    elseif strcmp(var,'VQ4c')
      ivar = 32;
    elseif strcmp(var,'VQ8e')
      ivar = 33;
    elseif strcmp(var,'VQ5b')
      ivar = 34;
    elseif strcmp(var,'VQ5e')
      ivar = 35;
    elseif strcmp(var,'Jc6')
      ivar = 36;
    elseif strcmp(var,'VQ6b')
      ivar = 37;
    elseif strcmp(var,'Jc7')
      ivar = 38;
    elseif strcmp(var,'VQ7e')
      ivar = 39;
    elseif strcmp(var,'VQ6e')
      ivar = 40;
    elseif strcmp(var,'I18')
      ivar = 41;
    elseif strcmp(var,'H1')
      ivar = 42;
    elseif strcmp(var,'HS')
      ivar = 43;
    elseif strcmp(var,'I19')
      ivar = 44;
    elseif strcmp(var,'H2')
      ivar = 45;
    elseif strcmp(var,'Je0')
      ivar = 46;
    elseif strcmp(var,'IBi')
      ivar = 47;
    elseif strcmp(var,'HBi')
      ivar = 48;
    elseif strcmp(var,'Jb0')
      ivar = 49;
    elseif strcmp(var,'I6')
      ivar = 50;
    elseif strcmp(var,'Jc0')
      ivar = 51;
    elseif strcmp(var,'H3')
      ivar = 52;
    elseif strcmp(var,'I1')
      ivar = 53;
    elseif strcmp(var,'H4')
      ivar = 54;
    elseif strcmp(var,'I3')
      ivar = 55;
    elseif strcmp(var,'Jb1')
      ivar = 56;
    elseif strcmp(var,'I2')
      ivar = 57;
    elseif strcmp(var,'Jc1')
      ivar = 58;
    elseif strcmp(var,'Jb3')
      ivar = 59;
    elseif strcmp(var,'Jb2')
      ivar = 60;
    elseif strcmp(var,'I22')
      ivar = 61;
    elseif strcmp(var,'Je2')
      ivar = 62;
    elseif strcmp(var,'H5')
      ivar = 63;
    elseif strcmp(var,'It')
      ivar = 64;
    elseif strcmp(var,'Je3')
      ivar = 65;
    elseif strcmp(var,'H6')
      ivar = 66;
    elseif strcmp(var,'Jc3')
      ivar = 67;
    elseif strcmp(var,'I9')
      ivar = 68;
    elseif strcmp(var,'H7')
      ivar = 69;
    elseif strcmp(var,'Je4')
      ivar = 70;
    elseif strcmp(var,'IBi1')
      ivar = 71;
    elseif strcmp(var,'HBi1')
      ivar = 72;
    elseif strcmp(var,'Jb4')
      ivar = 73;
    elseif strcmp(var,'Jc4')
      ivar = 74;
    elseif strcmp(var,'I11')
      ivar = 75;
    elseif strcmp(var,'H8')
      ivar = 76;
    elseif strcmp(var,'I10')
      ivar = 77;
    elseif strcmp(var,'Je8')
      ivar = 78;
    elseif strcmp(var,'HE')
      ivar = 79;
    elseif strcmp(var,'Jb5')
      ivar = 80;
    elseif strcmp(var,'IF')
      ivar = 81;
    elseif strcmp(var,'I17')
      ivar = 82;
    elseif strcmp(var,'Je5')
      ivar = 83;
    elseif strcmp(var,'I14')
      ivar = 84;
    elseif strcmp(var,'Jc5')
      ivar = 85;
    elseif strcmp(var,'H10')
      ivar = 86;
    elseif strcmp(var,'ID')
      ivar = 87;
    elseif strcmp(var,'Jb6')
      ivar = 88;
    elseif strcmp(var,'Jb7')
      ivar = 89;
    elseif strcmp(var,'Je6')
      ivar = 90;
    elseif strcmp(var,'Je7')
      ivar = 91;
    elseif strcmp(var,'H9')
      ivar = 92;
    elseif strcmp(var,'Is')
      ivar = 93;
    elseif strcmp(var,'VPa')
      ivar = 94;
    elseif strcmp(var,'I20')
      ivar = 95;
    elseif strcmp(var,'I4')
      ivar = 96;
    elseif strcmp(var,'I5')
      ivar = 97;
    elseif strcmp(var,'I8')
      ivar = 98;
    elseif strcmp(var,'I7')
      ivar = 99;
    elseif strcmp(var,'HPa')
      ivar = 100;
    elseif strcmp(var,'IPa')
      ivar = 101;
    elseif strcmp(var,'VPs')
      ivar = 102;
    elseif strcmp(var,'I12')
      ivar = 103;
    elseif strcmp(var,'Jc8')
      ivar = 104;
    elseif strcmp(var,'I13')
      ivar = 105;
    elseif strcmp(var,'IC')
      ivar = 106;
    elseif strcmp(var,'I15')
      ivar = 107;
    elseif strcmp(var,'I16')
      ivar = 108;
    elseif strcmp(var,'HPs')
      ivar = 109;
    elseif strcmp(var,'IPs')
      ivar = 110;
    elseif strcmp(var,'constant')
      ivar = 111;
    elseif strcmp(var,'VBias')
      ivar = 112;
    elseif strcmp(var,'Vpower')
      ivar = 113;
    elseif strcmp(var,'VAmpref')
      ivar = 114;
    elseif strcmp(var,'VSumref')
      ivar = 115;
    elseif strcmp(var,'Iin')
      ivar = 116;
    end
  end
end
