








Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!









Problem Set
Figure 1: RLC circuit
FORTRAN Problem 4.10.36: The three cube roots of 1 are 1, (^12)
( −1 + i
) , and (^12)
( − 1 − i
) , where i =
− 1. Confirm this by writting a FORTRAN program that raises each of the last two expressions to the third power.
FORTRAN Problem 4.10.37: Write a code segment to find the complex conjugate a − bi of the value a + bi in a COMPLEX16 variable named Z.
Solution to the Problem Set
v(t) = Ri(t) + L di(t) dt
c
∫ i(t)dt (1)
v(t) is a constant DC voltage of 100V. The current that flows thrugh the capacitor is the current of the circuit: dQ(t) dt = i(t) The state space representation of the system can be written as:
x 1 (t) = Q(t) x 2 (t) = ˙x 1 = dQ dt(t) We will now drop the (t) notation for simplicity. STATE EQUATIONS x ˙ 2 = R L x 2 − (^) LC^1 x 1 + (^) L^1 VDC x ˙ 1 = x 2 Rewritting this equations using the values of the RLC circuit of Figure 1 yields: x ˙ 2 = − 1500 x 2 − 8 .3¯ 3 × 106 x 1 + 83333.3¯ 3 x˙ 1 = x 2
The time step that will be used in the numerical solutions is ∆t = C 2 = 5 × 10 −^5.
Solution by Eulers Method Eulers Method for the system of equations (2) is described by the the following expression:
x( 2 k +1)= x( 2 k )+ ∆t
( x ˙( 2 k)
)
x( 1 k +1)= x( 1 k )+ ∆t
( x ˙( 1 k)
First Iteration: k = 0, x(0) 2 = 0, x(0) 1 = 0 x˙(0) 2 = −1500(0) − 8 .3¯ 3 × 106 (0) + 83333.3¯3 = 83333.3¯ 3 ∆t
( x ˙(0) 2
) = 5 × 10 −^5 (83333.3¯3) = 4.16¯ 6 x(1) 2 = 0 + 4.16¯6 = 4.16¯ 6 x˙(0) 1 = 0 ∆t
( x ˙(0) 1
) = 0 x(1) 1 = 0
Second Iteration: k = 1, x(1) 2 = 4.16¯ 6 , x(1) 1 = 0 x˙(1) 2 = −1500(4.16¯6) − 8 .3¯ 3 × 106 (0) + 83333.3¯3 = 20833.3¯ 3 ∆t
( x ˙(1) 2
) = 5 × 10 −^5 (20833.3¯3) = 1.0416¯ 6 x(2) 2 = 4.16¯6 + 1.0416¯6 = 5.2083¯ 3 x˙(1) 1 = 4.16¯ 6 ∆t
( x ˙(1) 1
) = 5 × 10 −^5 (4.16¯6) = 2. 08 × 10 −^4 x(2) 1 = 0 + 2. 08 × 10 −^4 = 2. 08 × 10 −^4
x˙ 2 p = −1500(4.7309) − 8 .3¯ 3 × 106
(
)
( 5 × 10 −^5
) = 3. 90625 x(2) 1 = 2.08¯ 3 × 10 −^4 + (^12)
( 5 × 10 −^5
) = 4.5¯ 3 × 10 −^4
Tables 1 and 2 present the solution for the system of equations 2. Note that x 2 is the current in the circuit.
Exact Solution In order to compare the accuracy of Euler’s and Modified Euler’s method, implemented in a MATLAB program that will be shown latter, the exact solution of (1) must be found. The differential equation (1) has an exact solution. Differentiation of (1) yields:
di dt
di^2 dt^2
i = 0
Rewritting: di^2 dt^2
di dt
i = 0
The characteristic equation: s^2 + R L s + (^) LC^1 = 0 s 1 = − 14422 s 2 = − 577. 81
The general solution is defined by:
i(t) = K 1 ǫs^1 t^ + K 2 ǫs^2 t^ = K 1 ǫ−^14422 t^ + K 2 ǫ−^577.^81 t
Considering initial conditions, the constants K 1 and K 2 can be found:
i(0) = 0 = K 1 + K 2 (5)
di dt
= − 14422 K 1 ǫ−^14422 t^ − 577. 81 K 2 ǫ−^577.^81 t^ (6)
di dt
∣∣ ∣∣ t=0+
Evaluating equation (6) at t = 0 ans susbtituting the results of equation (7) yields:
− 14422 K 1 − 577. 81 K 2 = 83333 (8)
Solving equation (5) and (8) for K 1 and K 2 yields:
K 1 = − 6 .0193; K 2 = 6. 0193
And, thus, the solution is:
i(t) = − 6. 0193 ǫ−^14422 t^ + 6. 0193 ǫ−^577.^81 t^ (9)
This expression will be used to compare the accuracy of the MATLAB implementation of the numerical methods in next section.
MATLAB implementation of Euler’s and Modified Euler’s Methods The following program uses Euler, Modified Euler and the exact solution to solve the system of equations in (1).
0001 %%%%%%%%%%%%%%%%%%%%%%%%%%% 0002 % Solving by Eulers Method 0003 clear; clc; 0004 x1 = 0; % Initial value of the capacitor charge 0005 x2 = 0; % Initial value of the current 0006 R = 18; % Resistence 0007 L = 0.0012; % Inductance 0008 C = 0.0001; % Capacitance 0009 V = 100; % DC Voltage 0010 Dt = C/2; % Time Step 0011 Kt = 100; % Kt iterations 0012 time = 0; % Initial time 0013 % Solving by Eulers method 0014 for k=1:1:Kt+ 0015 X1(k) = x1; 0016 X2(k) = x2; % Store X2 solution 0017 T(k) = time; % Store current time 0018 x2p = -(R/L)x2 - (1/(LC))x1 + V/L; % First Derivative of X 0019 x2pDt = x2pDt; % Delta-time * x2p 0020 x2 = x2 + x2pDt; % New value for X 0021 x1p = x2; % First derivative of X 0022 x1pDt = x1pDt; % Delta-time * x1p 0023 x1 = x1 + x1pDt; % New value for X 0024 time = time + Dt; % Compute time at the next iteration 0025 end 0026 Ieul = X2; %Stores de current 0027 Teul = T; %Stores the time array 0028 %%%%%%%%%%%%%%%%%%%%%%%% 0029 % Modified Euler Method 0030 % Re-initializing variables 0031 x1 = 0; % Initial value of the capacitor charge 0032 x2 = 0; % Initial value of the current 0033 time = 0; % Initial time 0034 % Solving by Modified Eulers method 0035 for k=1:1:Kt+ 0036 X2(k) = x2; % Store X2 solution 0037 X1(k) = x1; % Store X1 solution 0038 T(k) = time; % Store current time 0039 x2o = x2; % X2 at the begining of the interval 0040 x2p = -(R/L)x2 - (1/(LC))x1 + V/L; % First Derivative of X 0041 x2 = x2 + x2pDt; % New value of X2 to calculate the derivative 0042 x1o = x1; % X1 at the begining of the interval 0043 x1p = x2; % First derivative of X 0044 x1 = x1 + x1pDt; % New value of X1 to calculate the derivative 0045 % Derivative at the end of the interval 0046 x2p_t2 = -(R/L)x2 - (1/(LC))x1 + V/L; % Derivative at the end of the interval 0047 x1p_t2 = x2; % Derivative at the end of the interval 0048 % New values of x2 and x 0049 x2 = x2o + (1/2)(x2p + x2p_t2)Dt; % Final estimation of X 0050 x1 = x1o + (1/2)(x1p + x1p_t2)Dt; % Final estimation of X 0051 time = time + Dt; % Compute time at the next iteration 0052 end 0053 Imeul = X2; % Stores the current 0054 Tmeul = T; % Stores the time array 0055 %%%%%%%%%%%%%%%% 0056 % Exact solution 0057 as2 = (R/(2L))ˆ2; % Damping coefficient
0 1 2 3 4 5 x 10−
0
1
2
3
4
5
6
7
8
Solution by Euler, Modified Euler and Analytical Methods
Current (Amperes)
Time (Seconds)
Euler Modified Euler Exact Solution
∆t=C
Exact Solution
Modified Euler
Euler
Figure 3: Solution with ∆t = C
0 1 2 3 4 5 6 7 x 10−
−
−
−
−
0
5
10
15
20
Solution by Euler
TIME (SEC.)
CURRENT (AMPERES)
∆t = 1.22C
∆t = 1.26C
∆t = 1.30C
Figure 4: Numerical Oscillation with Euler’s Method
0 1 2 3 4 5 x 10−
−
−
−
−
−
−
−
0
10
Solution by Modified Euler
TIME (SEC.)
CURRENT (AMPERES)
∆ t = 1.25C
∆ t = 1.28C
∆ t = 1.31C ∆ t = 1.34C
∆ t = 1.37C
Figure 5: Numerical Oscillation with Modified Euler’s Method
Figure 2 presents the solution when ∆t = C/ 2 ; which is the same solution presented at the begining of the section with manual calculations in Table 1 and Table 2. It should be noted that the manual computations agree with the Matlab solution, of course, with certain amount of deviation that emerges from human errors in computation. Figure 2 presents the solutions with Euler, Modified Euler and Analytical methods, it can be observed that with the adequate selection of the time step, ∆t, the numerical methods provide a good aproximation compared with the exact solution.
Figure 3 presents the solution when ∆t = C. In this case, the selection of an ill value for the time step can be observed; both Euler and Modified Euler methods show a bad approximation of the solution at the begining of the transient and do provide an adequate approximation for the end of the transient. Nevertheless, it should be noted that neither the values obtained with Euler or Modified Eueler can be used to estimate the maximum current, and thus, the solution they provide is not useful when a bad selected time step is used.
Figure 4 and 5 where obtained as a curiosity to further analyze the numerical problems in the methods; they show the instability of Euler and Modified Euler methods, respectively. From Figure 4 we can observe that a ∆t = 1. 3 C can produce numerical oscillation, values beyond of ∆t = 1. 28 C are keen to produce this effect. Figure 5 shows the solution with Modified Euler’s method, in this case our attention is driven to the fact that a value beyond ∆ = 1. 25 C are keen to produce odd results in the method or non at all.
→ The FORTRAN problems are not well solved, they contain an awfull error by mixing types. The following FORTRAN programs try to overcome this error: =⇒ Problem 4.10.36:
C C This program solves problem 4.10.36 of the book. C C REAL8 RE1, IM1, RE2, IM2, SQ3,SOL1R,SOL2R COMPLEX16 ROT1,ROT2,SOL1,SOL SQ3=SQRT(3.D0) RE1=-0.5D IM1=0.5D0SQ RE2=-0.5D IM2=-0.5D0SQ ROT1=DCMPLX(RE1,IM1) ROT2=DCMPLX(RE2,IM2) SOL1=ROT1ROT1ROT SOL2=ROT2ROT2ROT SOL1R=DREAL(SOL1) SOL2R=DREAL(SOL2) PRINT *,’First complex root: ’,ROT PRINT *,’Second complex root: ’,ROT PRINT *,’First complex root raised to the third power: ’,SOL1R PRINT *,’Second comples root raised to the third power: ’,SOL2R STOP END =⇒ Problem 4.10.37:
C C C This program solves problem 4.10. C REAL8 A,B COMPLEX16 Z,ZC PRINT *,’Enter a complex number a+jb in the form (a,b):’ READ *,Z A=DREAL(Z) B=DIMAG(Z) ZC=DCMPLX(A,-B) PRINT *,’The complex conjugate of ’,Z,’ is: ’,ZC STOP END
→ The RLC circuit problem was solved using MATLAB. Prof. Kupferschmid pointed out that it would be a nice task to program both Euler and Modified Euler’s method for this problem with FORTRAN. The following programs emerged from Prof. Kupferschmid’s suggestion: =⇒ RLC circuit solved with EULERS Method:
C This program solves the RLC circuit of HW4, using euler. C Luigi Vanfretti, March, 1 - 2006. C --------------------------------- C CHANGES C ******* C date description C ---- ----------- C 04/01/06 original code C 04/08/06 declaration of DT and proper assignment of type C C variable meaning C -------- ------- C DT time step C TIME time value C KINI initial iteration C KFINAL final iteration C X2P first derivative of X C X2 current (I - amperes) C X1P first derivative of X C X1 initial value of the capacitor charge C R resistance C L inductance C C capacitance C VDC DC voltage C ------------------------------------------------ REAL*8 R,L,C,VDC,TIME,X2P,X2,X1P,X1,DT INTEGER KINI,KFINAL C C C set circuit parameters C R = 18.0D L = 0. C = 0. VDC = 100.0D PRINT *,’R is:’,R,’ L is:’,L,’ C is;’,C C C set time step, initial and final time C DT = 5.0D- PRINT *,DT TIME = 0.0D KINI = 0 KFINAL = 208
C C set initial value for charge and current C X1 = 0.0D X2 = 0.0D
=⇒ RLC circuit solved with MODIFIED EULERS Method:
C This program solves the RLC circuit of HW4, using C modified euler. C Luigi Vanfretti, March, 1 - 2006. C --------------------------------- C CHANGES C ******* C date description C ---- ----------- C 04/01/06 original code C 04/08/06 declaration of DT and proper assignment of type C C variable meaning C -------- ------- C DT time step C TIME time value C KINI initial iteration C KFINAL final iteration C X2PF first derivative of X2 at the end of the interval C X2P first derivative of X C X2 current (I - amperes) C X1PF first derivative of X1 at the end of the interval C X1P first derivative of X C X1 initial value of the capacitor charge C X20 dummy variable that saves the current X C X10 dummy variable that saves the current X C R resistance C L inductance C C capacitance C VDC DC voltage C ------------------------------------------------ REAL*8 R,L,C,VDC,TIME,X2P,X2,X1P,X1,DT INTEGER KINI,KFINAL C C C set circuit parameters C R = 18.0D L = 0. C = 0. VDC = 100.0D PRINT *,’R is:’,R,’ L is:’,L,’ C is;’,C C C set time step, initial and final time C DT = 5.0D- TIME = 0.0D KINI = 0 KFINAL = 208 PRINT *,’DT IS:’,DT
C C set initial value for charge and current C X1 = 0.0D X2 = 0.0D
X2P = 0 X1P = 0 C C Solve with modified eulers method C DO 1 I = KINI,KFINAL, C C C computing the derivatives at the begining of the interval C X20 = X X2P = -(R/L)X2-(1.0D0/(LC))X1 + VDC/L X2 = X2 + X2PDT X10 = X X1P = X X1 = X1 + X1PDT C C C computing the derivatives at the end of the interval C X2PF = -(R/L)X2-(1.0D0/(LC))X1 + VDC/L X1PF = X C C C computing the new values for X2 and X C X2 = X20 + (0.5D0)(X2P + X2PF)DT X1 = X10 + (0.5D0)(X1P + X1PF)DT K = I IT = K TIME = TIME + DT PRINT *,’x2 (current) at time ’,TIME,’ is: ’,X 1 CONTINUE STOP END
References
[1] M. Kupferschmid. Classical FORTRAN. Marcel Dekker, Inc. New York, 2002.