r2 test

two resistors in series with voltage source

Contents

symbolic

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

  +-    -+
  |   0  |
  |      |
  |   0  |
  |      |
  |  V1  |
  +-    -+

  +-           -+
  |      V1     |
  |             |
  |    R2 V1    |
  |   -------   |
  |   R1 + R2   |
  |             |
  |       V1    |
  |  - -------  |
  |    R1 + R2  |
  +-           -+

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

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

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

latex(gmat)
latex(Is)
latex(V)
ans =

\left(\begin{array}{ccc} \frac{1}{\mathrm{R1}} & -\frac{1}{\mathrm{R1}} & 1\\ -\frac{1}{\mathrm{R1}} & \frac{1}{\mathrm{R1}} + \frac{1}{\mathrm{R2}} & 0\\ 1 & 0 & 0 \end{array}\right)


ans =

\left(\begin{array}{c} 0\\ 0\\ \mathrm{V1} \end{array}\right)


ans =

\left(\begin{array}{c} \mathrm{V1}\\ \frac{\mathrm{R2}\, \mathrm{V1}}{\mathrm{R1} + \mathrm{R2}}\\ -\frac{\mathrm{V1}}{\mathrm{R1} + \mathrm{R2}} \end{array}\right)

numeric

% resistors in series - voltage source
filename = 'r2.net';
fprintf('filename: %s\n',filename);
type(filename);
%parse file
parse
% build system
sysbuild
show_results
filename: r2.net

% Resistance in series
% voltage source
% alphanumeric node names
R R1 N_1 N_2  2
R R2 N_2 0 4
V V1 N_1 0 6

gmat =

    0.5000   -0.5000    1.0000
   -0.5000    0.7500         0
    1.0000         0         0


Is =

     0
     0
     6

V(N_1)  6
V(N_2)  4
I(V1)  -1