r1 test

two resistors in series with current source

Contents

symbolic

% two resistors in series with current source
gmat = sym(zeros(2,2));
R1 = sym('R1');
R2 = sym('R2');
I1 = sym('I1');
gmat = nmAcc(1,2,1/R1,gmat);
gmat = nmAcc(2,0,1/R2,gmat);
pretty(gmat);
Is = sym(zeros(2,1));
Is = srcAcc(0,1,I1,Is);
pretty(Is);
V = gmat\Is;
pretty(V);
  +-               -+
  |    1        1   |
  |   --,    - --   |
  |   R1       R1   |
  |                 |
  |     1   1    1  |
  |  - --, -- + --  |
  |    R1  R1   R2  |
  +-               -+

  +-    -+
  |  I1  |
  |      |
  |   0  |
  +-    -+

  +-              -+
  |  I1 (R1 + R2)  |
  |                |
  |      I1 R2     |
  +-              -+

$${\bf G_m} = \left(\begin{array}{cc} \frac{1}{\mathrm{R1}} & -\frac{1}{\mathrm{R1}}\\ -\frac{1}{\mathrm{R1}} & \frac{1}{\mathrm{R1}} + \frac{1}{\mathrm{R2}} \end{array}\right)$$

$${\bf I_s} = \left(\begin{array}{c} \mathrm{I1}\\ 0 \end{array}\right)$$

$${\bf V} = \left(\begin{array}{c} \mathrm{I1}\, \left(\mathrm{R1} + \mathrm{R2}\right)\\ \mathrm{I1}\, \mathrm{R2} \end{array}\right)$$

numeric

% resistors in seris - current source
filename = 'r1.net';
fprintf('filename: %s\n',filename);
type(filename);
%parse file
parse
% display variables
Type
nodenames
fprintf('Contents of comp structure\n\n');
for k=1:length(comp)
    disp(comp(k))
end
% build system
sysbuild
show_results
filename: r1.net

% Resistance in series
% alphanumeric node names
R R1 N_1 N_2  2
R R2 N_2 0 4
I I1 0 N_1 1

Type = 

    'R'
    'R'
    'I'


nodenames = 

    'N_1'
    'N_2'

Contents of comp structure

         type: 'R'
         name: 'R1'
        value: 2
    nodenames: {2x1 cell}
         node: [1 2]

         type: 'R'
         name: 'R2'
        value: 4
    nodenames: {2x1 cell}
         node: [2 0]

         type: 'I'
         name: 'I1'
        value: 1
    nodenames: {2x1 cell}
         node: [0 1]


gmat =

    0.5000   -0.5000
   -0.5000    0.7500


Is =

     1
     0

V(N_1)  6
V(N_2)  4