function u = InvInputTransf(v,x,d,p)
% static calculation block to solve for u = f(v,x,d)

T1 = d(1);                   % [degC], disturbance inlet flow 1 temperature
T2 = d(2);                   % [degC], disturbance inlet flow 1 temperature

T  = x;                                    % diff state. temperature [degC]
V  = p(1);                                               % tank holdup [m3]

A  = p(2);                                               % tuning parameter
B  = p(3);                                               % tuning parameter

transf = p(4); % static for linear for T

switch transf
     case 0 % static transformation for both q and T
          q1 = v(1)*(v(2)-T2)/(T1-T2);                % [m3/s] inlet flow 1
          q2 = v(1)*(T1-v(2))/(T1-T2);                % [m3/s] inlet flow 2
          
          u  = [q1;q2];
     case 1 % linear transformation for T
          R  = [1 1; T1-T T2-T];
          S  = [v(1); V*(A*T+B*v(2))];
          u  = R\S;    % solve linear system of eqn to find physical inputs
     otherwise
          disp('Error calculation block')
end