# 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 Ring

edit retag close merge delete

Sort by » oldest newest most voted

It 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)

more

Thank 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()?

( 2018-02-15 00:42:23 -0500 )edit

Nothing 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.

( 2018-02-15 09:25:53 -0500 )edit

meanwhile 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

( 2018-02-16 06:40:42 -0500 )edit