Menu

#4784 bode_gain() and bode_phase() are not working

None
open
nobody
5
2026-06-16
2026-06-16
No

I use maxima in a Ubuntu machine. My current setup, given by the build_info() function in a Ubuntu 26.04 machine, is:


Maxima-version: "5.49.0"
Maxima build date: "2026-02-12 23:50:16"
Host type: "x86_64-pc-linux-gnu"
Lisp implementation type: "GNU Common Lisp (GCL)"
Lisp implementation version: "GCL 2.7.1 git tag Version_2_7_2pre7"
User dir: "/home/user/.maxima"
Temp dir: "/tmp"
Object dir: "/home/user/.maxima/binary/5_49_0/gcl/GCL_2_7_1_git_tag_Version_2_7_2pre7"
Frontend: false


In Ubuntu 24.04, which packages maxima 5.46, I had no problem using the bode_gain and the bode_phase functions. However, in Ubuntu 26.04, both functions fail with an error:

plot2d: expression evaluates to non-numeric value everywhere in plotting range.
plot2d: nothing to plot.

Upon investigation, I found that both functions' definitions in the file /usr/share/maxima/5.49.0/share/contrib/bode.mac use the buildq function to construct the final command that is subsequently run by the ev() function (last line in each function definition). If we print the command instead of evaluating it by using the function print() instead of ev(), we see what the problem is that, for the bode_phase() function, the buildq() function converts the carg() function call to atan2(0, H), as can be seen below:

(%i1) H: 10^5/(s + 10^5);
            100000
(%o1)     ----------
          s + 100000
(%i2) load("bode")$
(%i3) bode_phase(H, [w, 10^4, 10^7]);
            180 atan2(0, H)
bode_plot2d(---------------, range, [logx, true], 
                  %pi
                                     [gnuplot_preamble, my_preamble]) 
                  180 atan2(0, H)
(%o3) bode_plot2d(---------------, range, [logx, true], 
                        %pi
                                     [gnuplot_preamble, my_preamble])

This is wrong since H above is an expression over the complex numbers. I did the same thing (using print() instead of ev() in the bode.mac file) in a Ubuntu 24.04 machine, and I found that the buildq() function preserves the carg() function, instead of converting it to atan2().

A similar problem affects the bode_gain() function.

I'm not sure of the reason for this change of behavior, but I found a workaround for this problem by defining H to be complex in the definition of both function (bode_gain() and bode_phase()) in the bode.mac file:

  H : subst (%i * omega, s, H),
  declare(H, complex),  /* <---- This is the new, added line */

It'd be nice if this simple solution or another more appropriate were integrated in the distribution.

Thanks.

Discussion


Log in to post a comment.

Auth0 Logo