ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 11 Sep 2013 00:45:26 -0500plotting inverse laplace transformhttp://ask.sagemath.org/question/10532/plotting-inverse-laplace-transform/Hi there,
I'm studying a 4th order (two second order filters cascaded) electronic filter and I need it's time response.
I have derivated the transfert function and to get the time response, I apply the inverse laplace transform of the transfer function multiplied by a ramp.
Sage returns a result and I would like to plot this result, in order to check if this is correct but I don't know how to do so...
#!/opt/sage-5.11/sage
import cmath as m
from sage.calculus.calculus import inverse_laplace
r11 = 200.00e3
r21 = 800.00e3
c11 = lambda n: 1.25e-12 * (n+1)
c21 = lambda n: 312.5e-15 * (n+1)
wz1 = lambda n: 1/(r21*c11(n))
wp1 = lambda n: 1/(r11*c11(n))
# second filter
r12 = 266.67e3
r22 = 200.00e3
r32 = 800.00e3
c12 = lambda n: 1.25e-12*(n+1)
c22 = lambda n: 312.5e-15*(n+1)
A = r32/r12
w02 = lambda n: abs(1/(m.sqrt(r22*r32*c12(n)*c22(n))))
w02sq = lambda n: 1/(r22*r32*c12(n)*c22(n))
# second order coefficient
a = lambda n: 1/w02sq(n)
b = lambda n: r22*r32*c22(n)*((1/r12) + (1/r22) + (1/r32))
# gain
k = lambda n: A/wz1(n)
# input pulse
gain = 4
# electron injection
injfc = lambda x: x*1.602177e-19
# input
ampout = lambda x: injfc(x)/50e-15
# some more gain
gainout = lambda x: ampout(x)*gain
# set a value for i
i = 3
# declare p as a variable
p = var('p')
# the transfer function
f = ((k(i)*p) / (((1+p/wp1(i))**2) * ((p/w02(i))**2 + b(i)*p + 1)))
# transfer function multiplied by a very fast ramp and the input
fs = f*(2.00e6/p**2)*gainout(25000)
# please, gimme the inverse laplace
g = fs.inverse_laplace(p,x)
print "g(x) = ", g
# this is where I would like to plot g
# plot (g(x))
Thank you very much for your help
Best regards,
Olivier
Tue, 10 Sep 2013 06:21:37 -0500http://ask.sagemath.org/question/10532/plotting-inverse-laplace-transform/Comment by vdelecroix for <p>Hi there,
I'm studying a 4th order (two second order filters cascaded) electronic filter and I need it's time response.
I have derivated the transfert function and to get the time response, I apply the inverse laplace transform of the transfer function multiplied by a ramp.
Sage returns a result and I would like to plot this result, in order to check if this is correct but I don't know how to do so...</p>
<pre><code>#!/opt/sage-5.11/sage
import cmath as m
from sage.calculus.calculus import inverse_laplace
r11 = 200.00e3
r21 = 800.00e3
c11 = lambda n: 1.25e-12 * (n+1)
c21 = lambda n: 312.5e-15 * (n+1)
wz1 = lambda n: 1/(r21*c11(n))
wp1 = lambda n: 1/(r11*c11(n))
# second filter
r12 = 266.67e3
r22 = 200.00e3
r32 = 800.00e3
c12 = lambda n: 1.25e-12*(n+1)
c22 = lambda n: 312.5e-15*(n+1)
A = r32/r12
w02 = lambda n: abs(1/(m.sqrt(r22*r32*c12(n)*c22(n))))
w02sq = lambda n: 1/(r22*r32*c12(n)*c22(n))
# second order coefficient
a = lambda n: 1/w02sq(n)
b = lambda n: r22*r32*c22(n)*((1/r12) + (1/r22) + (1/r32))
# gain
k = lambda n: A/wz1(n)
# input pulse
gain = 4
# electron injection
injfc = lambda x: x*1.602177e-19
# input
ampout = lambda x: injfc(x)/50e-15
# some more gain
gainout = lambda x: ampout(x)*gain
# set a value for i
i = 3
# declare p as a variable
p = var('p')
# the transfer function
f = ((k(i)*p) / (((1+p/wp1(i))**2) * ((p/w02(i))**2 + b(i)*p + 1)))
# transfer function multiplied by a very fast ramp and the input
fs = f*(2.00e6/p**2)*gainout(25000)
# please, gimme the inverse laplace
g = fs.inverse_laplace(p,x)
print "g(x) = ", g
# this is where I would like to plot g
# plot (g(x))
</code></pre>
<p>Thank you very much for your help</p>
<p>Best regards, </p>
<p>Olivier</p>
http://ask.sagemath.org/question/10532/plotting-inverse-laplace-transform/?comment=17024#post-id-17024It will be hard to plot a function like exp(-1000000*x) which appears in the expression for g... you can try to isolate the terms which matter and create a new expression which only involve them.Tue, 10 Sep 2013 09:04:26 -0500http://ask.sagemath.org/question/10532/plotting-inverse-laplace-transform/?comment=17024#post-id-17024Comment by osfe for <p>Hi there,
I'm studying a 4th order (two second order filters cascaded) electronic filter and I need it's time response.
I have derivated the transfert function and to get the time response, I apply the inverse laplace transform of the transfer function multiplied by a ramp.
Sage returns a result and I would like to plot this result, in order to check if this is correct but I don't know how to do so...</p>
<pre><code>#!/opt/sage-5.11/sage
import cmath as m
from sage.calculus.calculus import inverse_laplace
r11 = 200.00e3
r21 = 800.00e3
c11 = lambda n: 1.25e-12 * (n+1)
c21 = lambda n: 312.5e-15 * (n+1)
wz1 = lambda n: 1/(r21*c11(n))
wp1 = lambda n: 1/(r11*c11(n))
# second filter
r12 = 266.67e3
r22 = 200.00e3
r32 = 800.00e3
c12 = lambda n: 1.25e-12*(n+1)
c22 = lambda n: 312.5e-15*(n+1)
A = r32/r12
w02 = lambda n: abs(1/(m.sqrt(r22*r32*c12(n)*c22(n))))
w02sq = lambda n: 1/(r22*r32*c12(n)*c22(n))
# second order coefficient
a = lambda n: 1/w02sq(n)
b = lambda n: r22*r32*c22(n)*((1/r12) + (1/r22) + (1/r32))
# gain
k = lambda n: A/wz1(n)
# input pulse
gain = 4
# electron injection
injfc = lambda x: x*1.602177e-19
# input
ampout = lambda x: injfc(x)/50e-15
# some more gain
gainout = lambda x: ampout(x)*gain
# set a value for i
i = 3
# declare p as a variable
p = var('p')
# the transfer function
f = ((k(i)*p) / (((1+p/wp1(i))**2) * ((p/w02(i))**2 + b(i)*p + 1)))
# transfer function multiplied by a very fast ramp and the input
fs = f*(2.00e6/p**2)*gainout(25000)
# please, gimme the inverse laplace
g = fs.inverse_laplace(p,x)
print "g(x) = ", g
# this is where I would like to plot g
# plot (g(x))
</code></pre>
<p>Thank you very much for your help</p>
<p>Best regards, </p>
<p>Olivier</p>
http://ask.sagemath.org/question/10532/plotting-inverse-laplace-transform/?comment=17022#post-id-17022well, this is not an issue since the x domain is [0:100e-6].Tue, 10 Sep 2013 21:38:54 -0500http://ask.sagemath.org/question/10532/plotting-inverse-laplace-transform/?comment=17022#post-id-17022Answer by vdelecroix for <p>Hi there,
I'm studying a 4th order (two second order filters cascaded) electronic filter and I need it's time response.
I have derivated the transfert function and to get the time response, I apply the inverse laplace transform of the transfer function multiplied by a ramp.
Sage returns a result and I would like to plot this result, in order to check if this is correct but I don't know how to do so...</p>
<pre><code>#!/opt/sage-5.11/sage
import cmath as m
from sage.calculus.calculus import inverse_laplace
r11 = 200.00e3
r21 = 800.00e3
c11 = lambda n: 1.25e-12 * (n+1)
c21 = lambda n: 312.5e-15 * (n+1)
wz1 = lambda n: 1/(r21*c11(n))
wp1 = lambda n: 1/(r11*c11(n))
# second filter
r12 = 266.67e3
r22 = 200.00e3
r32 = 800.00e3
c12 = lambda n: 1.25e-12*(n+1)
c22 = lambda n: 312.5e-15*(n+1)
A = r32/r12
w02 = lambda n: abs(1/(m.sqrt(r22*r32*c12(n)*c22(n))))
w02sq = lambda n: 1/(r22*r32*c12(n)*c22(n))
# second order coefficient
a = lambda n: 1/w02sq(n)
b = lambda n: r22*r32*c22(n)*((1/r12) + (1/r22) + (1/r32))
# gain
k = lambda n: A/wz1(n)
# input pulse
gain = 4
# electron injection
injfc = lambda x: x*1.602177e-19
# input
ampout = lambda x: injfc(x)/50e-15
# some more gain
gainout = lambda x: ampout(x)*gain
# set a value for i
i = 3
# declare p as a variable
p = var('p')
# the transfer function
f = ((k(i)*p) / (((1+p/wp1(i))**2) * ((p/w02(i))**2 + b(i)*p + 1)))
# transfer function multiplied by a very fast ramp and the input
fs = f*(2.00e6/p**2)*gainout(25000)
# please, gimme the inverse laplace
g = fs.inverse_laplace(p,x)
print "g(x) = ", g
# this is where I would like to plot g
# plot (g(x))
</code></pre>
<p>Thank you very much for your help</p>
<p>Best regards, </p>
<p>Olivier</p>
http://ask.sagemath.org/question/10532/plotting-inverse-laplace-transform/?answer=15444#post-id-15444Ok, since you know the domain of definition of your function you can do
sage: plot(g, xmin=0, xmax=10^-6)
But I am not sure if you can believe what you will see...
VincentWed, 11 Sep 2013 00:45:26 -0500http://ask.sagemath.org/question/10532/plotting-inverse-laplace-transform/?answer=15444#post-id-15444