New package for drawing direction fields with gnuplot
Subject: New package for drawing direction fields with gnuplot
From: Mark H Weaver
Date: Mon, 22 Nov 2010 16:54:09 -0500
Adam Majewski <adammaj1 at o2.pl> writes:
> f(zx,zy):=block([i:0,zx2,zy2,cx:0,cy:0,ER2:4,iMax:20],
> zx2:zx*zx,zy2:zy*zy,
> while zx2+zy2<ER2 and i<iMax do
> (zy:2*zx*zy+cy,zx:zx2-zy2+cx,zx2:zx*zx,zy2:zy*zy,i:i+1),
> return(i));
It looks as though you are trying to approximate the Mandelbrot set, but
if so, cx and cy should be the parameters of the function, and zx and zy
should be locals initialized to 0. As it is now, cx and cy are always
0, so why include them?
Regardless, drawdf is for drawing direction fields of differential
equations, and I don't see a differential equation here. The first
parameter of drawdf (or plotdf) should be either dy/dx or [dx/dt,dy/dt].
f(x,y) returns an integer (number of iterations), which I guess you mean
to interpret as a potential.
If you already have a potential function and wish to draw equipotential
lines, you probably want to use implicit(), which can be passed to
either draw2d or drawdf. Maybe something like this:
draw2d(implicit('(f(x,y))=5, x,-4,4, y,-4,4),
implicit('(f(x,y))=10, x,-4,4, y,-4,4),
implicit('(f(x,y))=15, x,-4,4, y,-4,4))$
or better yet, with Maxima 5.22.1 or newer:
draw2d(makelist(implicit('(f(x,y))=C, x,-4,4, y,-4,4), C, [5,10,15]))$
Note: for a smoother implicit plot, try the ip_grid option,
e.g. ip_grid=[100,100]
Regarding the field lines: if you had a continuous potential function,
you could easily compute its field by taking the gradient of the
potential. However, since your potential function is discrete,
computing a gradient that behaves nicely is more tricky. I'm not sure
drawdf is the right tool for this job.
Best,
Mark
> I have tried :
>
> drawdf('(f(x,y)), [x,-2,2], [y,-2,2]);
> drawdf('(f(x,y)), [x,-2,2], [y,-2,2],soln_at(1,1));
>
> drawdf('(f(x,y)), [x,-2,2], [y,-2,2],equipots_at(1,1));
>
> I was expecting that field lines will be straight lines towards (0,0)
> and equipotential lines will be concentric circles
> like on the left image :
> http://commons.wikimedia.org/w/index.php?title=File:Jung50e.png