ENG104 MATLAB Assignment
Due 5pm 4/10/19
1. Consider the RL circuit shown in Figure 1.
(a) [1 mark] Determine an ODE for the current i owing through the inductor.
(b) [1 marks] Approximate the derivative as
di ∼= i(t+δt)−i(t)
dt δt
to get a recursive equation for i(t + δt) in terms of i(t).
(c) [2 marks] Write a MATLAB script RLPlotter1c that uses the result of 1(b) to compute and plot ifort∈[0,T]. UsevaluesofR=1Ω,L=2H,T =10s,Vs =10V,i(0)=0A,andδt=0.1s. Ensure that the axis labels are labeled.
(d) [2 marks] Write a MALTAB function RLSolver that takes six inputs and returns two outputs. The inputs should be the values of R, L, T, Vs, i(0), and δt. The rst output should be a vector containing the values of t and the second output should be a vector containing the corresponding values of i(t). (You should be able to reuse code from the previous question for this).
(e) [2 marks] Write a MATLAB script RLPlotter1e that makes use of RLSolver to produce a plot showing i(t) for δt = 0.01s, δt = 0.1s, and δt = 1s (all other parameters are as given in 1(c)). Ensure the plot contains axis labels as well as a legend.
(f) [2 marks] Write a MATLAB script RLPlotter1f that makes use of RLSolver to produce a plot showing i(t) for all four possible combinations of R = 1 Ω or R = 2 Ω and L = 1 H or L = 2 H (all other parameters are as given in 1(c)). Ensure the plot contains axis labels as well as a legend.
R
+
Vs
i
L
−
Figure 1: RL circuit.
1
2. Now consider the RLC circuit shown in Figure 2.
(a) [2 marks] Determine an ODE for the current i owing through the inductor.
(b) [1 marks] Make the substitution ψ(t) = di to convert the second order ODE into a pair of single dt
order ODEs.
(c) [2 marks] Approximate the derivatives as
di ∼= i(t+δt)−i(t),
dt δt
dψ ∼= ψ(t+δt)−ψ(t) dt δt
to get a pair of recursive equations for i(t + δt) and ψ(t + δt) in terms of i(t) and ψ(t).
(d) [3 marks] Write a MATLAB function RLCSolver that takes eight inputs and returns two outputs. The inputs should be the values of R, L, C, T, Vs, i(0), ψ(0), and δt. The rst output should be a vector containing the values of t and the second output should be a vector containing the corresponding values of i(t).
(e) [2 marks] Write a MATLAB script RLCPlotter2e that makes use of RLCSolver to produce a plot showing i(t) for C = 1F, T = 20s, Vs = 10V, i(0) = 0A, ψ(0) = 0As−1, δt = 0.1s and all four possible combinations of R = 1Ω or R = 2Ω and L = 1H or L = 2H. Ensure the plot contains axis labels as well as a legend. Note that the current should converge to the same value as in the RL circuit for t → ∞.
R
Vs+ C −
Figure 2: RLC circuit.
i
L
Submission guidelines
• Your MATLAB scripts and functions should all be dierent les (please use the suggested names).
• Your answers to 1(a), 1(b), 2(a), 2(b), and 2(c) can either be in a single le or multiple les. Typed or scanned handwritten answers are both ne.
• Include all les in a single zip le and submit on MyLO. Please include your name and student number in the name of the zip le.
2