Last active
July 15, 2017 02:52
-
-
Save johnrichardrinehart/55a976e60442f8a93dcc7259076fcc17 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Obtained from https://en.wikipedia.org/wiki/Telegrapher%27s_equations#Lossy_transmission_line | |
" | |
telegrapher(L,C,R=0,G=0,n=100) | |
returns an array of differential equations that can be | |
used to solve for the travelling voltages and currents as a function of time. | |
All quantities are expected to be per-length quantities (in S.I. units). | |
The problem is solved by discretizing the transmission line into n sections. If | |
the solution is too coarse then try changing n. | |
" | |
function telegrapher(L, C, R=0, G=0 ;n=100, vs=t->1, is=t->0) | |
if L == 0 || C == 0 | |
error("Both the inductance and capacitance need to be non-zero.") | |
end | |
return function(t,u,du) | |
u[1] = vs(t) | |
u[n+1] = is(t) | |
dx = 1/(n-1) | |
for i = 2:n | |
# voltage equation | |
du[i] = (-1/C)*((u[n+i-1]-u[n+i])/dx + G*u[i]) | |
# current equation | |
du[n+i] = (-1/L)*((u[i-1]-u[i])/dx + R*u[n+i]) | |
end | |
end | |
end | |
" | |
tline_solve(f,L,C,R=0,G=0,t=(0,1),n=100) | |
Solves for the time-domain response of a transmission line to an incident | |
voltage waveform f(t). | |
### Arguments | |
u0: initial voltage applied to the line\n | |
t: solution interval\n | |
n: number of tline discretizations\n | |
" | |
function tline_solve(u0,vs,is,L,C,R=0,G=0;t=(0.,1.),n=100,dt=1e-3) | |
prob = DifferentialEquations.ODEProblem(telegrapher(L,C,R,G,n=n,vs=vs),u0,t) | |
solver = DifferentialEquations.Euler() | |
sol = DifferentialEquations.solve( | |
prob, | |
solver, | |
reltol=1e-8, | |
abstol=1e-8, | |
dt=dt | |
) | |
return sol | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment