%
%   RESISTIVE_NETWORKS0.M    Find the current in a particular resistive network
%
%   A particular resistive network is given along with the applied voltages.  The  
%   goal here is simply to determine the currents in each path within the circuit.
%
%   File prepared by J. R. White, UMass-Lowell  (last update:  Nov. 2017)
%

      clear all,   close all
%
%   define model parameters (note that resistance is given in kohms and voltage
%   in volts, so the current will be in milliamps -- I = V/R)
      R1 = 1;  R2 = 3.5;  R3 = 4;  R4 = 1.75;  R5 = 1 ;  
      R6 = 1;  R7 = 2;  R8 = 1.5;  R9 = 5;
      V1 = 5;  V2 = 5;  V3 = 2.5;  V4 = 2;  V5 = 5;
%
%   set up coefficient matrices (see development in Notes)
      A = [ (R1+R2)    -R2    0    0
             -R2   (R2+R3+R4+R5)   0   -R5;
              0          0      (R6+R7+R8)   -R8;
              0         -R5        -R8     (R5+R8+R9)];
      b = [V3-V1; -V2; -V3-V4; V4-V5];
%
      I = A\b;   %   solve linear system
%
%   edit results
      fprintf('\n  Results for Resistive Networks #0 \n ');
      for i = 1:length(I)
        fprintf('  --> Current  I%1i =  %8.5f ma  \n ',i,I(i));
      end
%
%  end of problem
