# Variable not found while trying to plot a parametric phase portrait

This post is a wiki. Anyone with karma >750 is welcome to improve it.

I'm trying to plot a parametric phase portrait of a differential equations system, but i get the following error:

Here's what I'm trying to do:

@interact
def _(a1 = slider(-30, 30, 0.001, default=0, label='a1'),
b1 = slider(-30, 30, 0.001, default=0, label='b1'),
a2 = slider(-30, 30, 0.001, default=0, label='a2'),
b2 = slider(-30, 30, 0.001, default=0, label='b2'),
g1 = slider(-30, 30, 0.001, default=0, label='g1'),
g2 = slider(-30, 30, 0.001, default=0, label='g2'),
auto_update=True):
discriminant = b2^2-2*b1*b2+b1^2+4*a1*a2

pretty_print("discriminant = " + str(discriminant))
if discriminant >= 0:
t = var('t')

M1 = function('M_1', t)
M2 = function('M_2', t)

de1 = diff(M1,t) == a1 * M2 - b1 * M1 + g1
de2 = diff(M2,t) == a2 * M1 - b2 * M2 + g2

plot_vector_field((de1.rhs(),de2.rhs()),(M1,-3,3),(M2,-3,3))
else:


Can't really figure out why is t not found and how to fix it

edit retag close merge delete

Sort by ยป oldest newest most voted

You cannot use functions (like M1 and M2) as variables (as you did in plot_vector_field). They are not interchangeable. Instead you can do

M1, M2 = var('M1 M2')

de1 = a1 * M2 - b1 * M1 + g1
de2 = a2 * M1 - b2 * M2 + g2

plot_vector_field((de1, de2), (M1, -3, 3), (M2, -3, 3)).show()


(without the .show() I did not get any picture).

more