First, your set notation is very strange. You mean S = (−∞, −2) ∪ (−1, ∞), that is, S is the union of two open intervals. You can also write S = [−2, −1]^C or S = {x ∈ ℝ: x < −2 or x > −1}. Also, your picture is certainly not a parabola; it looks much more like a hyperbola.
Anyhow, plotting the graphs of functions f: ℝ → ℝ is simple. You only need to take care of the coordinate transformation between your logical coordinate system and the screen's coordinate system. Define
type
TRealVector = record
X, Y: real;
end;
as a point in ℝ² and your maps are
const
xmin = -10;
xmax = 10;
ymin = -10;
ymax = 10;
function TForm5.LogToScreen(LogPoint: TRealVector): TPoint;
begin
result.X := round(ClientWidth * (LogPoint.X - xmin) / (xmax - xmin));
result.Y := ClientHeight - round(ClientHeight * (LogPoint.Y - ymin) / (ymax - ymin));
end;
function TForm5.ScreenToLog(ScreenPoint: TPoint): TRealVector;
begin
result.X := xmin + (ScreenPoint.X / ClientWidth) * (xmax - xmin);
result.Y := ymin + (ymax - ymin) * (ClientHeight - ScreenPoint.Y) / ClientHeight;
end;
Then you just have to plot!
procedure TForm5.FormPaint(Sender: TObject);
var
PrevPoint, CurrPoint: TPoint;
x: integer;
logx: real;
logy: real;
y: integer;
begin
PrevPoint := Point(-1, -1);
Canvas.Brush.Color := clWhite;
Canvas.FillRect(ClientRect);
for x := 0 to ClientWidth - 1 do
begin
logx := ScreenToLog(Point(x, 0)).X;
logy := logx*logx; // y = f(x)
y := LogToScreen(RealVector(logx, logy)).Y;
CurrPoint := Point(x, y);
if PrevPoint.X = -1 then
Canvas.MoveTo(CurrPoint.X, CurrPoint.Y)
else
Canvas.LineTo(CurrPoint.X, CurrPoint.Y);
PrevPoint := CurrPoint;
end;
end;
Don't forget:
procedure TForm5.FormResize(Sender: TObject);
begin
Invalidate;
end;
(source: rejbrand.se)