Ask Your Question
0

Variable not found while trying to plot a parametric phase portrait

asked 2015-10-23 02:38:10 +0200

this post is marked as community wiki

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:

ValueError: Variable 't' not found

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:
        pretty_print("discriminant is negative. adjust parameters")

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

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2015-10-23 04:14:58 +0200

vdelecroix gravatar image

updated 2015-10-23 11:45:51 +0200

slelievre gravatar image

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

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2015-10-23 02:38:10 +0200

Seen: 434 times

Last updated: Oct 23 '15