Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1995
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1995

[Date Index] [Thread Index] [Author Index]

Search the Archive

DirectionFieldPlot[]

  • To: mathgroup at christensen.cybernetics.net
  • Subject: [mg1242] DirectionFieldPlot[]
  • From: Xah Y Lee <xyl10060 at fhda.edu>
  • Date: Fri, 26 May 1995 05:50:05 -0400

Hello, here is a little crude program that plot direction field.

--------------------------- 
FieldPlot::usage = "FieldPlot[ f[x,y], {x,xMin,xMax,(dx)}, 
{y,yMin,yMax,(dy)}, 
(LineLength->1)] Plots the direction field of a scaler function f[x,y].";

Clear[unitV, FieldPlot]
unitV[{x_,y_}] := {x,y}/Sqrt[x^2+y^2]
Options[FieldPlot] = {LineLength->Automatic};
FieldPlot[ fun_, {xmin_,xmax_,dx_:Automatic}, {ymin_,ymax_,dy_:Automatic},
        opts___Rule]:=
        Module[{ll,i,j,dx2,dy2, gridList, slopeList, gp},
                ll = LineLength  /. {opts} /. Options[FieldPlot];
                If[dx===Automatic, dx2 = (xmax-xmin)/9, dx2 = dx];
                If[dy===Automatic, dy2 = (ymax-ymin)/9, dy2 = dy];
                If[ll===Automatic, ll = (dx2+dy2)/2 .9];
                gridList = 
                        N@Flatten[ Table[{i,j}, 
{i,xmin,xmax,dx2},{j,ymin,ymax,dy2}], 1];
                slopeList = N@fun[Sequence@@#]& /@ gridList;
                slopeList = slopeList /. m_/;NumberQ[m]->{1,m};
                slopeList = gridList + ll * (unitV/@ slopeList);
                
                gp = {  MapThread[Line[{#1,#2}]& , {gridList, slopeList}],
                                Point /@ gridList};
                Show[
                        Graphics[{Hue[0.],PointSize[.01], gp }, Axes->True,
                        AspectRatio->Automatic]
                ]

        ]/; NumberQ[N@xmin] && NumberQ[N@xmax] && NumberQ[N@ymin] && 
NumberQ[N@ymax]

FieldPlot[
        expr_,{x_,xmin_,xmax_, dx_},{y_,ymin_,ymax_, dy_}, opts___Rule ]:=
        FieldPlot[Function[{x,y},expr],{xmin,xmax,dx},{ymin,ymax,dy},opts];

FieldPlot[
        expr_,{x_,xmin_,xmax_},{y_,ymin_,ymax_}, opts___Rule ]:=
        FieldPlot[Function[{x,y},expr],{xmin,xmax},{ymin,ymax},opts];

----------------------------------

Example,

FieldPlot[ x^2-y, {x,-4,4,.5},{y,-4,4,.5}]

one can also use the package PlotField.m. For example,

Needs["Graphics`PlotField`"]

PlotVectorField[  unitV[{1,x^2-y}] , {x,-4,4},{y,-4,4},
        Axes->True, ColorFunction->Hue
]

 Xah       74631.731 at compuserve.com
 Quote of the day:
  Your nonsense is as good as mine.   --Metamathematician of metaland.



  • Prev by Date: Question about FindRoot function?
  • Next by Date: Re: HELP: DXF files and Mma
  • Previous by thread: Question about FindRoot function?
  • Next by thread: brackets and braces in frontend with german DEC-keyboard