![]() |
AW: ln-Funktion
Delphi-Quellcode:
Ich glaube mein Befehl ist einfach falsch, aber ich weiß halt nicht, wie ich ihn richtig schreiben soll
procedure TForm1.FormCreate(Sender: TObject); //Koordinatensystem
var i: integer; begin with image1.Canvas do begin moveto(20,220); lineto(440,220); //x-Achse moveto(220,5); lineto(220,420); //y-Achse moveto(430,215); lineto (442,220); lineto (430,225); //x-Pfeil moveto(215,15); lineto (220,5); lineto (225,15); //y-Pfeil textout(445,225,'x'); //Beschriftung x textout(200,0,'y'); //Beschriftung y for i:=-10 to 10 do begin moveto(220+50*i,215); lineto (220+50*i,225); //x-Einteilung moveto(215,220+50*i); lineto (225,220+50*i); //y-Einteilung textout(222+50*i,225,inttostr(i)); //Zahlen x-Achse if i <> 0 then textout (205,213+50*i,inttostr(-i)); //Zahlen y-Achse end; end; procedure TForm1.Button7Click(Sender: TObject); //Logarithmusfunktion, die nicht klappt :( var float:Double; x,y:real; i,j:integer; begin Val(edit1.Text,a,f1); begin float:= Ln(a); float := Exp(float); i:=20; while i<420 do begin i:=i+1; x:=(i-220)/50; //x skalieren y:=float; //y sklarieren //Befehl Quelle: [url]http://www.physik-multimedial.de/cvpmm/sle/trigonometrie/sinusfunktion.html[/url] j:=round((220-y*50)); //j berechnen image1.Canvas.Pixels[i,j]:=clteal; //zeichnen image1.Canvas.Font.Color:=clteal; image1.Canvas.TextOut(340,405, 'y=ln(a)'); end; end; end; |
AW: ln-Funktion
PS: ich habe mich dazu entschieden aus der logarithmusfunktion eine exponentialfunktion mit f(x)=a^x zu machen. wäre toll, wenn hr mir dabei helfen würdet ^^
|
AW: ln-Funktion
Hallo,
Zitat:
Wenn Du hingegen y = ln (x) ∀ x ∈ R: 0 < x ≤ 4 plotten möchtest, dann sollte die Berechnung des jeweiligen Funktionswerts schon in der while-Schleife erfolgen. Also so:
Delphi-Quellcode:
procedure TForm7.Button1Click(Sender: TObject);
var c : TCanvas; i, j : Integer; x, y : Double; begin c := Image1.Canvas; i := 220; while i < 420 do begin Inc (i); x := (i - 220) / 50; y := Ln (x); j := Round (220 - y * 50); c.Pixels [i, j] := clTeal end; c.Font.Color := clTeal; c.TextOut (340, 405, 'y = ln (x)') end; Zitat:
Gruß |
AW: ln-Funktion
ich danke dir :)
Endlich siehts gut aus und vor allem wie eine ln-funktion ;) wie formuliere ich das aber, dass ich f(x)=log(basis a)x (a element R, a>, a ungleich 1) bekomme?. Quasi, dass der user selbst den parameter a bestimmen kann? |
AW: ln-Funktion
Eine Funktion sieht ja immer so aus
Code:
Also brauchst du etwas, dass dir dieses f(x) abbildet.
y = f(x)
Delphi-Quellcode:
und du könntest dir dann solch eine Prozedur bauen
type
TPlotFunction = class public function Name : string; virtual; function f( x : double ) : double; virtual; end;
Delphi-Quellcode:
Eine konkrete Funktion ist ja diese Ln(x)
procedure Plot( ACanvas : TCanvas; AFunction : TPlotFunction );
var i, j : Integer; x, y : Double; begin i := 220; while i < 420 do begin Inc (i); x := (i - 220) / 50; y := AFunction.f(x); j := Round (220 - y * 50); ACanvas.Pixels [i, j] := clTeal end; ACanvas.Font.Color := clTeal; ACanvas.TextOut (340, 405, AFunction.Name ); end;
Delphi-Quellcode:
Deine ButtonClick-Methode würde dann so aussehen
type
TLN_PlotFunction = class( TPlotFunction ) public function Name : string; override; function f( x : double ) : double; end; function TLN_PlotFunction.Name : string; override; begin Result := 'y = ln(x)'; end; function TLN_PlotFunction.f( x : double ) : double; begin Result := ln(x); end;
Delphi-Quellcode:
Und das mit der y = Log(a)x Funktion geht dann so
procedure TForm7.Button1Click(Sender: TObject);
var LFunction : TLN_PlotFunction; begin LFunction := TLN_PlotFunction.Create; try Plot( Image1.Canvas, LFunction ); finally LFunction.Free; end; end;
Delphi-Quellcode:
und angewendet dann so
type
TLOGA_PlotFunction = class( TPlotFunction ) private Fa : Integer; public property a : Integer read Fa write Fa; function Name : string; override; function f( x : double ) : double; end; function TLOGA_PlotFunction.Name : string; override; begin Result := Format( 'y = log(%d)x',[a] ); end; function TLN_PlotFunction.f( x : double ) : double; begin Result := log(a)*x; end;
Delphi-Quellcode:
procedure TForm7.Button1Click(Sender: TObject);
var LFunction : TLOGA_PlotFunction; begin LFunction := TLOGA_PlotFunction.Create; try LFunction.a := 3; // für f(x) = log(3)*x Plot( Image1.Canvas, LFunction ); finally LFunction.Free; end; end; |
Alle Zeitangaben in WEZ +1. Es ist jetzt 06:18 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz