Ask Your Question

Andrei Halanay's profile - activity

2015-03-20 04:10:49 -0600 received badge  Nice Answer (source)
2013-01-17 09:45:55 -0600 received badge  Teacher (source)
2012-11-07 00:43:27 -0600 received badge  Editor (source)
2012-11-07 00:41:25 -0600 answered a question Phase portraits of 2-dimensional systems

The following function allows you to move the initial point and determines the "corners" of the picture with respect to the maximum an minimum values of the solutions.

@interact 
    def syst(x0=slider(-2,2,0.1,0.5),y0=slider(-2,2,0.1,0.5)):
        x,y=var('x y')
        vect=[-y,-x]
        sol=desolve_odeint(vect,[x0,y0],srange(-4,4,0.1),[x,y])
        xmin=sol[0,0]
        xmax=sol[0,0]
        ymin=sol[0,1]
        ymax=sol[0,1]
        for i in range(0,len(sol)):
            if sol[i,0] > xmax:
                xmax=sol[i,0]
            if sol[i,0]< xmin:
                xmin=sol[i,0]
        for i in range(0,len(sol)):
           if sol[i,1] > ymax:
               ymax=sol[i,0]
           if sol[i,1]< ymin:
               ymin=sol[i,0]
        p1=plot_vector_field((vect[0],vect[1]),(x,xmin-2,xmax+2),(y,ymin-2,ymax+2),plot_points=60)
        p=line(zip(sol[:,0],sol[:,1]))
        (p+p1).show(aspect_ratio=1)

Of course the solution using maxima is the nicest.