{ diffnorm.pas ver.1 } { (c) Kenrou Adachi, 1993 } program diffnorm(input, output); { uses crtansi, graph; TP4 } uses crt, graph; { TP5.5 } {$I data.pas} procedure data_in(var a, b, xo, yo, ts, te : real); begin writeln; writeln('input a for the range of x-axes for [-a,a]'); write(' a = '); readln(a); writeln('input b for the range of y-axes for [-b,b]'); write(' b = '); readln(b); writeln('input xo,yo for initial point (xo,yo)'); write(' xo = '); readln(xo); write(' yo = '); readln(yo); writeln('input ts and te for time range [ts,te]'); write(' ts = '); readln(ts); write(' te = '); readln(te) end; procedure wind(a, b : real; var dx, dy, ox, oy : real); begin dx := 2.0 * a; dy := 2.0 * b; ox := 640.0 * a / dx; oy := 400.0 * b / dy end; procedure axes; begin setcolor(BLUE); line(320, 0, 320, 400); line(0, 200, 640, 200) end; procedure draw(xo, yo, ts, te, dx, dy, ox, oy : real); var t, h : real; i : integer; procedure pre_draw_graph(xo, yo, dx, dy, ox, oy : real); var oldx, oldy : real; begin oldx := 640.0 * xo / dx + ox; oldy := -400.0 * yo / dy + oy; moveto(round(oldx), round(oldy)) end; procedure run_kut(var xo, yo, t : real; h : real); var x1, x2, x3, x4, y1, y2, y3, y4 : real; begin x1 := h * fx(xo, yo, t); y1 := h * fy(xo, yo, t); x2 := h * fx(xo + x1 / 2.0, yo + y1 / 2.0, t + h / 2.0); y2 := h * fy(xo + x1 / 2.0, yo + y1 / 2.0, t + h / 2.0); x3 := h * fx(xo + x2 / 2.0, yo + y2 / 2.0, t + h / 2.0); y3 := h * fy(xo + x2 / 2.0, yo + y2 / 2.0, t + h / 2.0); x4 := h * fx(xo + x3, yo + y3, t + h); y4 := h * fy(xo + x3, yo + y3, t + h); xo := xo + (x1 + 2.0 * x2 + 2.0 * x3 + x4) / 6.0; yo := yo + (y1 + 2.0 * y2 + 2.0 * y3 + y4) / 6.0; t := t + h end; procedure draw_graph(xo, yo, dx, dy, ox, oy : real); begin setcolor(YELLOW); lineto(round(640.0 * xo / dx + ox), round(-400.0 * yo / dy + oy)) end; begin h := (te - ts) / 640.0; t := ts; pre_draw_graph(xo, yo, dx, dy, ox, oy); for i := 1 to 640 do begin run_kut(xo, yo, t, h); draw_graph(xo, yo, dx, dy, ox, oy) end end; var a, b, xo, yo, ts, te : real; dx, dy, ox, oy : real; graphdriver, graphmode : integer; begin clrscr; graphdriver := DETECT; initgraph(graphdriver, graphmode, ''); cleardevice; repeat repeat data_in(a, b, xo, yo, ts, te); wind(a, b, dx, dy, ox, oy) until (a > 0.0) and (a <= 128) and (b > 0.0) and (b <= 80.0) until (abs(xo) <= abs(a)) and (abs(yo) <= abs(b)); axes; draw(xo, yo, ts, te, dx, dy, ox, oy); gotoxy(0, 35); writeln('put return key !'); readln end.