diode/twodiode.m: hspice/diode.sp
id1 + ir - ii
id2 - ir
The first example that was worked on was from Figure 1. It consists of two diodes and a resistor. The main program was called "5.1_diode/twodiode.m" and at the time everything except the evaluation of the black box currents was done in this file. The program ran exactly as it was supposed to. The results were identical to that in Fig 12.1.2 of the text "Computer Methods for Circuit Analysis and Design" and are recorded in Table 1.
Rinit is the number of initalization
h is the number of init to op point itterations
i is the initialization point itterations
j is transient itterations(includes op itter h)
k is number of transient points
*******diode/twodiode.m:****************
analysis time # points tot. iter conv.ite
op point 0.01 1 6
readin 0.01
errchk 0.01
setup 0.00
output 0.00
total cpu time 0.02 seconds
node =voltage node =voltage
+0:1 = 17.1178m 0:2 = 414.1113u
v_init =
0 0 0 0 0 0
v_op =
1.7119e-02 4.1418e-04
h =
8
op_time =
0.0493
optrans_time =
0.0493
j =
8
k =
1
v0 =
1.7119e-02 4.1418e-04
tic
format short
diff=1;
h=0;
v(1)=0.1;
v(2)=0.1;
while abs(diff)>0.000001
vd1=v(1);%we know
vd2=v(2);
vr=v(1)-v(2);
%we can setup.
%f1 and f2 should be made seperate funtions in terms of v1 and v2
f=[-(diode(vd1)+resistor(vr,1)-1),-(diode(vd2)-resistor(vr,1))];
%we can derive
v1e=v(1)+eps;
v2e=v(2)+eps;
%we alter
vd1=v1e;
vd2=v(2);
vr=v1e-v(2);
m=[(diode(vd1)+resistor(vr,1)-1+f(1))/eps; (diode(vd2)-resistor(vr,1)+f(2))/eps];
%we alter again
vd1=v(1);
vd2=v2e;
vr=v(1)-v2e;
mnew=[(diode(vd1)+resistor(vr,1)-1+f(1))/eps;(diode(vd2)-resistor(vr,1)+f(2))/eps];
f=f';
m=[m,mnew];
dv=lusolve(m,f);%from winter term
diff=(dv(1)^2+dv(2)^2)^0.5;
v(1)=v(1)+dv(1);
v(2)=v(2)+dv(2);
h=h+1;
%v
end
toc
format short e
v
h
format compact