x,y = var('x y')
maxima.eval('load("plotdf");')
eq='(x+y)/(x-y)'
x0,x1,y0,y1=-3,3,-3,3
eq=sage_eval(eq,locals={'x':x,'y':y})
p=implicit_plot(eq==0, (x, x0, x1), (y, y0, y1), color="red")
p=p+implicit_plot(1/(eq)==0,(x, x0, x1),(y, y0, y1),color="yellow")
show(p)
@interact
def df(eq='-x/y',usemaxima=False,window=matrix(2,2,[-3,3,-3,3]),IVP=False,xinit=0,yinit=1):
x0=window[0,0]
x1=window[0,1]
y0=window[1,0]
y1=window[1,1]
eq=sage_eval(eq,locals={'x':x,'y':y})
html(r'This is the vector field corresponding to $\frac{dy}{dx}='+latex(eq)+'$')
if not usemaxima:
p=implicit_plot(eq==0, (x, x0, x1), (y, y0, y1), color="red")
p=p+plot_slope_field(eq, (x,x0,x1), (y, y0, y1))
p=p+implicit_plot(1/eq==0,(x, x0, x1),(y, y0, y1),color="yellow")
if IVP:
p+=list_plot(desolve_rk4(eq,y,ics=[xinit,yinit],ivar=x,end_points=[x0,x1])
,ymin=y0,ymax=y1)
p.show(aspect_ratio=1)
else:
if IVP:
maxima.plotdf(eq,str([y,y0,y1]),str([x,x0,x1]),
'[trajectory_at, %s, %s]'%(str(xinit), str(yinit) ))
else:
maxima.plotdf(str(eq),str([y,y0,y1]),str([x,x0,x1]))