ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Fri, 16 Feb 2018 13:40:42 +0100trying to plot the phase angle of a Laplace transfer functionhttps://ask.sagemath.org/question/41116/trying-to-plot-the-phase-angle-of-a-laplace-transfer-function/hello,
I'm new to sagemath and while i was trying to dig into it i came across the following problem
see my small program...
n=1;1;1000
T1=0.1 w=2*pi*10*n/1000
S=I*w
F(S)=1/(1+S*T1)
P1=plot_loglog(abs(F), xmin=0.1, xmax=100.0, ymin=0.1)
P2=plot_semilogx(arg(F), xmin=0.1, xmax=100.0, ymax=0, ymin=-90)
P=P1+P1 p.show()
I'm getting the following error message:
I dont know how to fix this, i would really apreciate if one can give me some hints...
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-1-b52c0c8fff57> in <module>()
8
9 P1=plot_loglog(abs(F), xmin=RealNumber('0.1'), xmax=RealNumber('100.0'), ymin=RealNumber('0.1'))
---> 10 P2=plot_semilogx(arg(F), xmin=RealNumber('0.1'), xmax=RealNumber('100.0'), ymax=Integer(0), ymin=-Integer(90))
11 P=P1+P1
12 p.show()
/home/sc_serv/sage/src/sage/symbolic/function.pyx in sage.symbolic.function.BuiltinFunction.__call__ (build/cythonized/sage/symbolic/function.cpp:11602)()
992 res = self._evalf_try_(*args)
993 if res is None:
--> 994 res = super(BuiltinFunction, self).__call__(
995 *args, coerce=coerce, hold=hold)
996
/home/sc_serv/sage/src/sage/symbolic/function.pyx in sage.symbolic.function.Function.__call__ (build/cythonized/sage/symbolic/function.cpp:6439)()
472 if callable(method):
473 return method()
--> 474 raise TypeError("cannot coerce arguments: %s" % (err))
475
476 else: # coerce == False
TypeError: cannot coerce arguments: no canonical coercion from Callable function ring with argument S to Symbolic RingWed, 14 Feb 2018 09:47:54 +0100https://ask.sagemath.org/question/41116/trying-to-plot-the-phase-angle-of-a-laplace-transfer-function/Answer by eric_g for <p>hello,
I'm new to sagemath and while i was trying to dig into it i came across the following problem
see my small program...
</p>
<pre><code>n=1;1;1000
T1=0.1 w=2*pi*10*n/1000
S=I*w
F(S)=1/(1+S*T1)
P1=plot_loglog(abs(F), xmin=0.1, xmax=100.0, ymin=0.1)
P2=plot_semilogx(arg(F), xmin=0.1, xmax=100.0, ymax=0, ymin=-90)
P=P1+P1 p.show()
</code></pre>
<p>I'm getting the following error message:</p>
<p>I dont know how to fix this, i would really apreciate if one can give me some hints...</p>
<pre><code>---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-1-b52c0c8fff57> in <module>()
8
9 P1=plot_loglog(abs(F), xmin=RealNumber('0.1'), xmax=RealNumber('100.0'), ymin=RealNumber('0.1'))
---> 10 P2=plot_semilogx(arg(F), xmin=RealNumber('0.1'), xmax=RealNumber('100.0'), ymax=Integer(0), ymin=-Integer(90))
11 P=P1+P1
12 p.show()
/home/sc_serv/sage/src/sage/symbolic/function.pyx in sage.symbolic.function.BuiltinFunction.__call__ (build/cythonized/sage/symbolic/function.cpp:11602)()
992 res = self._evalf_try_(*args)
993 if res is None:
--> 994 res = super(BuiltinFunction, self).__call__(
995 *args, coerce=coerce, hold=hold)
996
/home/sc_serv/sage/src/sage/symbolic/function.pyx in sage.symbolic.function.Function.__call__ (build/cythonized/sage/symbolic/function.cpp:6439)()
472 if callable(method):
473 return method()
--> 474 raise TypeError("cannot coerce arguments: %s" % (err))
475
476 else: # coerce == False
TypeError: cannot coerce arguments: no canonical coercion from Callable function ring with argument S to Symbolic Ring
</code></pre>
https://ask.sagemath.org/question/41116/trying-to-plot-the-phase-angle-of-a-laplace-transfer-function/?answer=41121#post-id-41121It turns out that the function `arg` behaves differently than `abs`: it is expecting a symbolic expression, not a function: `arg(F(S))` is possible, not `arg(F)`. On the contrary, for `abs` (and many other functions), booth are possible and lead to the same result:
sage: bool(abs(F)(S) == abs(F(S)))
True
So to solve your issue, it suffices to write
P2 = plot_semilogx(arg(F(S)), xmin=0.1, xmax=100.0, ymax=0, ymin=-90)
To keep consistent notations, you can rewrite `P1` as well, although this is not necessary in that case:
P1 = plot_loglog(abs(F(S)), xmin=0.1, xmax=100.0, ymin=0.1)Wed, 14 Feb 2018 14:07:53 +0100https://ask.sagemath.org/question/41116/trying-to-plot-the-phase-angle-of-a-laplace-transfer-function/?answer=41121#post-id-41121Comment by Matrin for <p>It turns out that the function <code>arg</code> behaves differently than <code>abs</code>: it is expecting a symbolic expression, not a function: <code>arg(F(S))</code> is possible, not <code>arg(F)</code>. On the contrary, for <code>abs</code> (and many other functions), booth are possible and lead to the same result:</p>
<pre><code>sage: bool(abs(F)(S) == abs(F(S)))
True
</code></pre>
<p>So to solve your issue, it suffices to write</p>
<pre><code>P2 = plot_semilogx(arg(F(S)), xmin=0.1, xmax=100.0, ymax=0, ymin=-90)
</code></pre>
<p>To keep consistent notations, you can rewrite <code>P1</code> as well, although this is not necessary in that case:</p>
<pre><code>P1 = plot_loglog(abs(F(S)), xmin=0.1, xmax=100.0, ymin=0.1)
</code></pre>
https://ask.sagemath.org/question/41116/trying-to-plot-the-phase-angle-of-a-laplace-transfer-function/?comment=41151#post-id-41151meanwhile I fixed it by writing `abs(F(I*S))` and `agr(F(I*S))`... step by step i was suspecting that `S` was replaced by real Values from the x-axis.
The function `F` stands or the Laplace Transform of a "first order low-pass filter", and the x-axis should equal `w`Fri, 16 Feb 2018 13:40:42 +0100https://ask.sagemath.org/question/41116/trying-to-plot-the-phase-angle-of-a-laplace-transfer-function/?comment=41151#post-id-41151Comment by eric_g for <p>It turns out that the function <code>arg</code> behaves differently than <code>abs</code>: it is expecting a symbolic expression, not a function: <code>arg(F(S))</code> is possible, not <code>arg(F)</code>. On the contrary, for <code>abs</code> (and many other functions), booth are possible and lead to the same result:</p>
<pre><code>sage: bool(abs(F)(S) == abs(F(S)))
True
</code></pre>
<p>So to solve your issue, it suffices to write</p>
<pre><code>P2 = plot_semilogx(arg(F(S)), xmin=0.1, xmax=100.0, ymax=0, ymin=-90)
</code></pre>
<p>To keep consistent notations, you can rewrite <code>P1</code> as well, although this is not necessary in that case:</p>
<pre><code>P1 = plot_loglog(abs(F(S)), xmin=0.1, xmax=100.0, ymin=0.1)
</code></pre>
https://ask.sagemath.org/question/41116/trying-to-plot-the-phase-angle-of-a-laplace-transfer-function/?comment=41133#post-id-41133Nothing is wrong with `arg()`: the issue arrises from the definition `F(S) = 1/(1+S*T1)` which redeclares `S` as a symbolic variable, thereby erasing the previous definition `S=I*w`. Can you precise what is the function `F` and its variable? i.e. which quantity do you want on the x-axis of the plot? Written as `F(S) = 1/(1+S*T1)` with `T1=0.1`, `F` is a real-valued function for `S` real, hence `arg(F(S)` is always zero.Thu, 15 Feb 2018 16:25:53 +0100https://ask.sagemath.org/question/41116/trying-to-plot-the-phase-angle-of-a-laplace-transfer-function/?comment=41133#post-id-41133Comment by Matrin for <p>It turns out that the function <code>arg</code> behaves differently than <code>abs</code>: it is expecting a symbolic expression, not a function: <code>arg(F(S))</code> is possible, not <code>arg(F)</code>. On the contrary, for <code>abs</code> (and many other functions), booth are possible and lead to the same result:</p>
<pre><code>sage: bool(abs(F)(S) == abs(F(S)))
True
</code></pre>
<p>So to solve your issue, it suffices to write</p>
<pre><code>P2 = plot_semilogx(arg(F(S)), xmin=0.1, xmax=100.0, ymax=0, ymin=-90)
</code></pre>
<p>To keep consistent notations, you can rewrite <code>P1</code> as well, although this is not necessary in that case:</p>
<pre><code>P1 = plot_loglog(abs(F(S)), xmin=0.1, xmax=100.0, ymin=0.1)
</code></pre>
https://ask.sagemath.org/question/41116/trying-to-plot-the-phase-angle-of-a-laplace-transfer-function/?comment=41128#post-id-41128Thank you that works,
the error message is gone...
and after a few corrections thats my code:
n=1;1;1000
T1=0.1
w=2*pi*10*n/1000
S=I*w
F(S)=1/(1+S*T1)
P1=plot_loglog(abs(F(S)), xmin=0.1, xmax=100.0, ymin=0.1)
P2=plot_semilogx(arg(F(S)), xmin=0.1, xmax=100.0, ymax=0, ymin=-pi/2)
P1.show()
P2.show()
but the output of the second plot is not what i was expecting.
Hmmm, sorry I'm not allowed to upload files, but let my explaine. The out put is just a straight line that covers the x-axis and it is supposed to be an s-shaped curve that goes from 0 to -pi/2.
So there ist still something wrong with that function arg(). Is there a way to examine the output of the function arg()?
Thu, 15 Feb 2018 07:42:23 +0100https://ask.sagemath.org/question/41116/trying-to-plot-the-phase-angle-of-a-laplace-transfer-function/?comment=41128#post-id-41128