kill(all)$

maxima :'see truebasic :code', vectorfield2d with trajectory,version 1.0b
peter.vlasschaert@gmail.com,20/10/2020

ref:truebasic
vector field 2d : with trajectory , version 1.0

load packages ,option
=================

load(draw),ratprint = false $

a)  source code :vector field 2D 
========================

w:0.3$ /*length vectors ,w */
a:0$   /* parameter */
b:-2.0$
c:2.0$
d:0$
p:[]$  /* empty list p */
n:21$  /* odd integer : otherwise */
xmax:2$ /* xmin ≤ x ≤ xmax */
xmin:-xmax$
ymax:2$ /* ymin ≤ y ≤ ymax */
ymin:-ymax$
di:(xmax-xmin)/n$ 
dj:(ymax-ymin)/n$
for i:1 thru n 
 do(   
for j:1 thru n  
 do(
  x:xmin+i*di,       
  y:ymin+j*dj,   
 dx : a*x+b*y, /* general: dx = f1(x,y) */
 dy : c*x+d*y, /* general: dy = f2(x,y) */
    ds:sqrt((dx)^2+(dy)^2),        
 if ds > 0 then      
   m1:[x-w*dx/ds,y-w*dy/ds],
   m2:[x+w*dx/ds,y+w*dy/ds],
  p:endcons(points([m1,m2]),p) /*draw small vectors, AB,figure 1,red dashes 
                                 lines below wxdraw2d :u1 */         
    )       
 )$   

p$

b) draw : vector field (2d)
===================

u1:wxdraw2d(point_type = dot,points_joined=true,line_type=dashes,color =red,
   proportional_axes = 'xy,p
)$

u2:wxdraw2d(point_type = dot,points_joined=true,line_type=dashes,color =red,
   proportional_axes = 'xy,p
),wxplot_size=[600,600]$

c) source code of trajectory
=====================

m:[]$
nu:50$
xx1:makelist(0,i,1,nu)$ /* empty list,dimension:nu */
yy1:makelist(0,i,1,nu)$
xx1[1]:0.01$            /*initial values:trajctory */
yy1[1]:0.01$
for k:1 thru nu-1 do
       (
    dx0 : ev(float(a*xx1[k]+b*yy1[k]),nouns),
    dy0 : ev(float(c*xx1[k]+d*yy1[k]),nouns),
    ds0 : (dx0)^2+(dy0)^2,
    xx1[k+1] : xx1[k] + w*dx0/(ds0)^(1/2),  /*sign before w = + */
    yy1[k+1] : yy1[k] + w*dy0/(ds0)^(1/2),
     m:endcons([[xx1[k],yy1[k]],[xx1[k+1],yy1[k+1]]][1],m),
     /* index k :first coordinate , index k+1: second coordinate */
    xx1[k]:xx1[k+1], /* to fill the list */
    yy1[k]:yy1[k+1]
       )$

d) draw vector field 2d & trajectory
===========================

wxdraw2d(point_type = dot,
         points_joined=true,
         line_type=dashes,color =red,
         proportional_axes = 'xy,
         p,         /* red color */       
         color = blue,
         line_width = 2,       
         points(m) /*blue color */
        )$    

rem : blue dashes  follow the red dashes,in the figure, above.