Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
i_last = Branch(k).I_last; v_last = Branch(k).V_last; ON_or_OFF = Branch(k).State; % Check if Switch needs to be turned OFF if i_last <= 0.0 & ON_or_OFF==1 & time > 5*DeltaT if(ShowExtra==1) fprintf(Turn OFF (Brn %d) time = %12.1f usecs \n, k,time*1.0E6-DeltaT); fprintf(i_Switch(l) = %12.6f \n,i_last); fprintf(v_load(l) = %12.6f \n,v_last); end; Branch(k).State=0; Branch(k).Value = Branch(k).R_OFF; Branch(1).I_last=0.0; Branch(2).I_last=0.0; Branch(3).I_last=0.0; i_RL(l-1) = 0.0; Branch(2).V_last = v_source; Reform_G = 1; end; % Check if Switch needs to be turned ON if v_last > 1.0 & ON_or_OFF==0 Branch(k).Value = Branch(k).R_ON; Branch(k).Reff = Branch(k).Value; Branch(k).State=1; Reform_G = 1; if(ShowExtra==1) fprintf(Turn ON time = %12.1f usecs\n,time*1.0E6); fprintf(v_last = %20.14f \n,v_last); end; end; end; % if end; % for if(ShowExtra==1) fprintf(Reform_G = %d \n,Reform_G); end; return % =============== END of Check_Switch.m ================ function [G] = Form_G(DeltaT,Debug); global Branch global No_Brn global No_Nodes global ShowExtra % Initialize [G] matrix to zero for k=1:No_Nodes; for kk=1:No_Nodes; G(kk,k) = 0.0; end; end; for k=1:No_Brn Type = Branch(k).Type;
= = = =
= G(To,To) + 1/R_eff;
F.4
This MATLAB procedure generates the frequency response of different discretisation methods by evaluating the frequency response of the resulting rational function in z that characterises an RL circuit. The results are shown in section 5.5.3.
% Compare Methods for Continuous to discrete conversion % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Initialise the variable space % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% clear; format long; StepLength = input(Enter Step-length (usecs) > );
for fr = 1:fmax, w = 2*pi*f(fr); den(fr)=0; num(fr)=0; % Calculate Denominator polynomial for h=1:DenOrder+1, den(fr) = den(fr) + b(h)*exp(-j*w*(h-1)*deltaT); end; % Calculate Numerator polynomial for v=1:NumOrder+1, num(fr) = num(fr) + a(v)*exp(-j*w*(v-1)*deltaT); end; end; % Calculate Rational Function if i==1 Gt1 = num./den; elseif i==2 Gt2 = num./den; elseif i==3 Gt3 = num./den; elseif i==4 Gt4 = num./den; elseif i==5 Gt5 = num./den; elseif i==6 Gt6 = num./den; end; end; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% PLOT 1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%% figure(1); clf; subplot(211); plot(f,abs(Gt1),r-.,f,abs(Gt2),y:,f,abs(Gt3),b:,f,abs(Gt4), g-.,f,abs(1./Gt5),c:,f,abs(Gt6),m--,f,abs(Theory),k-);
Appendix G
G.1
This program demonstrates the state variable analysis technique for simulating the dynamics of a network. The results of this program are presented in section 3.6.
!**************************************************************** ! PROGRAM StateVariableAnalysis ! !**************************************************************** ! ! This program demonstrates state space analysis ! . ! x = Ax + Bu ! y = Cx + Du ! ! Where x in the state variable vector. ! y is the output vector. ! u the input excitation vector. ! . ! x = (dx/dt) ! ! The program is set up to solve a second order RLC circuit at ! present, and plot the results. The results can then be compared ! with the analytic solution given by SECORD_ORD. ! !--------------------------------------------------------------! Version 1.0 (25 April 1986) converted to FORTRAN90 2001 !**************************************************************** IMPLICIT NONE ! Definition of variables. ! -----------------------INTEGER, PARAMETER:: RealKind_DP = SELECTED_REAL_KIND(15,307) REAL (Kind = RealKind_DP), PARAMETER :: pi = 3.141592653589793233D0
REAL REAL REAL REAL REAL REAL REAL REAL REAL REAL REAL
(Kind (Kind (Kind (Kind (Kind (Kind (Kind (Kind (Kind (Kind (Kind
= = = = = = = = = = =
RealKind_DP) RealKind_DP) RealKind_DP) RealKind_DP) RealKind_DP) RealKind_DP) RealKind_DP) RealKind_DP) RealKind_DP) RealKind_DP) RealKind_DP)
CHARACTER*1 CHARB CHARACTER*10 CHARB2 LOGICAL LOGICAL LOGICAL LOGICAL :: :: :: :: STEP_CHG CONVG Check_SVDot OptimizeStep ! ! ! ! Step Change Converged Check Derivative of State Variable Optimize Step length
COMMON/COMPONENTS/R,L,C,E ! ! Initialize variables. --------------------Time = 0.0 Xt(1) = 0.0 Xt(2) = 0.0 E=0.0 Switch_Time =0.1D-3 ! Seconds Check_SVDot=.FALSE. OptimizeStep=.FALSE. OPEN(Unit=1,STATUS=OLD,file=SV_RLC.DAT) READ(1,*) R,L,C READ(1,*) EPS,Check_SVDot,OptimizeStep
&
&
986 &