changeset 11775:ab67284dba10 octave-forge

added subnet functions on resistor example
author dvd7587
date Tue, 11 Jun 2013 15:34:33 +0000
parents 7e13977d6b6f
children 6d6d2ae4c82f
files extra/secs1d/inst/demos/simple_resistor_tran_noscale_res.m
diffstat 1 files changed, 37 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/extra/secs1d/inst/demos/simple_resistor_tran_noscale_res.m	Tue Jun 11 11:10:43 2013 +0000
+++ b/extra/secs1d/inst/demos/simple_resistor_tran_noscale_res.m	Tue Jun 11 15:34:33 2013 +0000
@@ -45,10 +45,43 @@
 
 V = Fn + constants.Vth * log (n ./ device.ni);
 
-function [g, j, r] = vbcs (t, dt);
-  g =  [1; 1];
-  j =  [sin(3*t*pi)  0];
-  r =  [0  0];
+function [g, j, r] = vbcs (t, dt, x1)
+  persistent A1 B1 C1 %A2 B2 C2 
+  if (isempty (A1))
+    load ("circuit_matrices")
+  endif
+  C1(5) = -min(t,1);
+  [g(1) j(1) r(1)] = decomposematrixes (A1, B1, C1, dt, x1);
+  %[g(2) j(2) r(2)] = decomposematrixes (A2, B2, C2, dt, x2);
+  g(2) = 1;   j(2) = 0;   r(2) = 0;
+endfunction
+
+function x1 = update_states (t, dt, F1)
+   persistent A1 B1 C1 x1 %A2 B2 C2 x2
+   if (isempty (A1))
+     load ("circuit_matrices")
+   endif
+
+   C1(5) = -min(t,1);
+   freq = 1/dt;
+   
+   a{2,2} = A1(2:end,2:end);
+   b{2,1} = B1(2:end,1);
+   b{2,2} = B1(2:end,2:end);
+   e{2,2} = a{2,2}*freq+b{2,2};
+   f{2} = C1(2:end);
+
+   e22inv = inv(e{2,2});
+   x1 = e22inv * ( freq*a{2,2}*x1 - b{2,1}*F1 - f{2} )
+   
+   %% a{2,2} = A2(2:end,2:end);
+   %% b{2,1} = B2(2:end,1);
+   %% b{2,2} = B2(2:end,2:end);
+   %% e{2,2} = a{2,2}*freq+b{2,2};
+   %% f{2} = C2(2:end);
+
+   %% e22inv = inv(e{2,2});
+   %% x2 = e22inv * ( freq*a{2,2}*x2 - b{2,1}*F2 - f{2} )
 endfunction
 
 % tolerances for convergence checks