Updated 2014-03-19 13:14:37 by arjen

Arjen Markus (18 march 2014) The other day I wanted to examine the shape of a simple polynomial function. The main problem was that it has two parameters (both should be positive), so the shape depends on the values of these parameters. More importantly, I was looking for evidence that the polynomial might have roots with positive real parts.

Rather than tackling this analytically - the function is fairly simple, but the expressions get nasty and a mistake is easily made - I just wrote a small GUI to visualise the function. By using sliders I can vary the value of the two parameters and see the effect on the shape.

While this is nothing fancy and the curve I draw is quite angular (I use too few points to make it smooth), writing the GUI and testing it took less time than checking the analytical expressions for the right signs and summation of terms.
# Examine a polynomial function that has two parameters
# The idea:
# Find parameter values that give it a particular shape
# Background:
# (Complex or real) roots with a positive real part mean the
# the underlying system is unstable.
package require Plotchart

grid [canvas .c -width 600 -height 400] - -sticky news
grid [scale .alpha -from 0.0 -to 2.0 -variable alpha -orient horizontal -resolution 0.01 -command redraw] \
     [scale .beta  -from 0.0 -to 2.0 -variable beta  -orient horizontal -resolution 0.01 -command redraw] -sticky news

set p [::Plotchart::createXYPlot .c {-3 5 1} {-10 10 5}]

proc redraw {dummy} {
    global p alpha beta

    .c delete data

    $p plot xline -3 0
    $p plot xline  5 0
    $p plot yline  0 -10
    $p plot yline  0  10

    $p plot data -3 {}
    foreach x {-3 -2 -1 0 1 2 3 4 5} {
        $p plot data $x [expr {1.0 - (1.0 + $x)**2 * (1.0 + $alpha + $beta * $x)}]

The user-interface looks like this: