Friday, December 4, 2015

HP Prime: Slopefield (Differential Equations)

HP Prime:  Slopefield (Differential Equations)

Here is a program that graphs the slopefield of a differential equation in the form dy/dx = f(x,y).  This program is adopted from Alan Ziv’s SLPFIELD program, which Ziv programmed for the Casio fx-9850G.  The link to the original program is here:  http://www.spiderpixel.co.uk/caspro/progs/9x50g/slopefield.txt


For the HP Prime version, enter dy/dx in quotes, and use capital letters X and Y.  I recommend that you are in the Function app for this.  The window should be set up before running SLOPEFIELD.

Program SLOPEFIELD

EXPORT SLOPEFIELD(dxy)
BEGIN
// dxy: dx/dy = f′(x,y)
// Adopted from Alan Ziv -
// Casio
// dxy is in quotes
LOCAL X,Y,C,D,J,K,G,H;
LOCAL F,xa,xb,ya,yb,E;

// Use the Function App
RECT();
C:=(Ymax-Ymin)/220;
D:=(Xmax-Xmin)/320;

FOR J FROM 0 TO 50 DO
E:=Xmin+(8*J+3)*D;
FOR K FROM 0 TO 27 DO
F:=Ymin+(8*K+3)*C;

X:=E;
Y:=F;
G:=EXPR(dxy);
H:=2*D;

IF ABS(G)>C/D THEN
H:=2*C/ABS(G);
END;

IF 2*H>D THEN
xa:=E-H; ya:=G*(xa-E)+F;
xb:=E+H; yb:=G*(xb-E)+F;
LINE(xa,ya,xb,yb);
ELSE
LINE(E,F+2*C,E,F-2*C);
END;
END;
END;

// Draw Axis
LINE(Xmin,0,Xmax,0,#C0C0C0h);
LINE(0,Ymin,0,Ymax,#C0C0C0h);
WAIT(0);

END;

 Examples:

dy/dx = X*^Y^2 + 3*X

 
dy/dx = Y*SIN(X)

This blog is property of Edward Shore.  2015

Eddie


Spotlight: Sharp EL-5200

  Spotlight: Sharp EL-5200 As we come on the 13 th (April 16) anniversary of this blog, I want to thank you. Blogging about mathematic...