AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

ln-Funktion

Ein Thema von Rebel · begonnen am 2. Feb 2014 · letzter Beitrag vom 5. Feb 2014
Antwort Antwort
Seite 2 von 2     12   
Rebel

Registriert seit: 10. Jan 2014
18 Beiträge
 
#11

AW: ln-Funktion

  Alt 4. Feb 2014, 17:48
Delphi-Quellcode:
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;
Ich glaube mein Befehl ist einfach falsch, aber ich weiß halt nicht, wie ich ihn richtig schreiben soll
  Mit Zitat antworten Zitat
Rebel

Registriert seit: 10. Jan 2014
18 Beiträge
 
#12

AW: ln-Funktion

  Alt 4. Feb 2014, 18:18
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 ^^
  Mit Zitat antworten Zitat
Volker Z.

Registriert seit: 3. Dez 2012
Ort: Augsburg, Bayern, Süddeutschland
419 Beiträge
 
Delphi XE4 Ultimate
 
#13

AW: ln-Funktion

  Alt 4. Feb 2014, 19:50
Hallo,

Zitat:
Ich glaube mein Befehl ist einfach falsch [...]
Naja, wenn Du den Graphen y = ln (a), für festes a > 0 im Interval [-4; 4] zeichnen möchtest, dann machst Du schon alles richtig - zwar sehr umständlich, aber richtig; es ist doch eine konstante Funktion.

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:
PS: ich habe mich dazu entschieden aus der logarithmusfunktion eine exponentialfunktion mit f(x)=a^x zu machen [...]
f(x) = exp(x) geht dann ähnlich.

Gruß
Volker Zeller
  Mit Zitat antworten Zitat
Rebel

Registriert seit: 10. Jan 2014
18 Beiträge
 
#14

AW: ln-Funktion

  Alt 5. Feb 2014, 11:07
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?
  Mit Zitat antworten Zitat
Benutzerbild von Sir Rufo
Sir Rufo

Registriert seit: 5. Jan 2005
Ort: Stadthagen
9.454 Beiträge
 
Delphi 10 Seattle Enterprise
 
#15

AW: ln-Funktion

  Alt 5. Feb 2014, 12:14
Eine Funktion sieht ja immer so aus
Code:
y = f(x)
Also brauchst du etwas, dass dir dieses f(x) abbildet.
Delphi-Quellcode:
type
  TPlotFunction = class
  public
    function Name : string; virtual;
    function f( x : double ) : double; virtual;
  end;
und du könntest dir dann solch eine Prozedur bauen
Delphi-Quellcode:
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;
Eine konkrete Funktion ist ja diese Ln(x)
Delphi-Quellcode:
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;
Deine ButtonClick-Methode würde dann so aussehen
Delphi-Quellcode:
procedure TForm7.Button1Click(Sender: TObject);
var
  LFunction : TLN_PlotFunction;
begin
  LFunction := TLN_PlotFunction.Create;
  try
    Plot( Image1.Canvas, LFunction );
  finally
    LFunction.Free;
  end;
end;
Und das mit der y = Log(a)x Funktion geht dann so
Delphi-Quellcode:
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;
und angewendet dann so
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;
Kaum macht man's richtig - schon funktioniert's
Zertifikat: Sir Rufo (Fingerprint: ‎ea 0a 4c 14 0d b6 3a a4 c1 c5 b9 dc 90 9d f0 e9 de 13 da 60)
  Mit Zitat antworten Zitat
Antwort Antwort
Seite 2 von 2     12   


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 05:54 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz