Autor Beitrag
fusco123
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 40



BeitragVerfasst: So 02.03.08 16:36 
Hab nen programm für die Potenzableitung geschrieben, nur geht es nicht ^^
Weiß jemand woran es liegt?

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
function ableitung(a,n,x: single): single;
  function ableitung_allgemein(a,n: single): string;
var
  Form21: TForm21;

implementation

{$R *.dfm}

function ableitung(a,n,x: single):single;
 begin
n*a*Power(x,(n-1));

 end;


function ableitung_allgemein(a,n: single): string;
begin
floattostr(n*a)+'X^'+floattostr(n-1);
end;

procedure TForm21.Button1Click(Sender: TObject);
var vorzahl,exponent, xwert: single;
begin
vorzahl:=strtofloat(Edit1.text);
exponent:=strtofloat(edit2.text);
xwert:=strtofloat(edit3.text);
label4.caption:=floattostr(ableitung(vorzahl,exponent,xwert));
label7.caption:=ableitung_allgemein(vorzahl,exponent);
end;

end.


Moderiert von user profile iconAXMD: Delphi-Tags hinzugefügt
Moderiert von user profile iconChristian S.: Topic aus Open Source Projekte verschoben am Sa 15.03.2008 um 19:13
AXMD
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 4006
Erhaltene Danke: 7

Windows 10 64 bit
C# (Visual Studio 2019 Express)
BeitragVerfasst: So 02.03.08 16:44 
Hallo!

Was genau "geht nicht"? Eine genauere Fehlerbeschreibung wäre hilfreich, um dir weiterhelfen zu können.

AXMD
Timosch
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 1314

Debian Squeeze, Win 7 Prof.
D7 Pers
BeitragVerfasst: So 02.03.08 16:56 
user profile iconfusco123 hat folgendes geschrieben:
Hab nen programm für die Potenzableitung geschrieben, nur geht es nicht ^^
Weiß jemand woran es liegt?

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
function ableitung(a,n,x: single): single;
  function ableitung_allgemein(a,n: single): string;
var
  Form21: TForm21;

implementation

{$R *.dfm}

function ableitung(a,n,x: single):single;
 begin
n*a*Power(x,(n-1));

 end;


function ableitung_allgemein(a,n: single): string;
begin
floattostr(n*a)+'X^'+floattostr(n-1);
end;

procedure TForm21.Button1Click(Sender: TObject);
var vorzahl,exponent, xwert: single;
begin
vorzahl:=strtofloat(Edit1.text);
exponent:=strtofloat(edit2.text);
xwert:=strtofloat(edit3.text);
label4.caption:=floattostr(ableitung(vorzahl,exponent,xwert));
label7.caption:=ableitung_allgemein(vorzahl,exponent);
end;

end.


Moderiert von user profile iconAXMD: Delphi-Tags hinzugefügt

Deine Functions geben nichts zurück. Der Rückgabewert muss der Pseudovariablen result zugewiesen werden.

_________________
If liberty means anything at all, it means the right to tell people what they do not want to hear. - George Orwell
fusco123 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 40



BeitragVerfasst: So 02.03.08 17:07 
Jop das wars, einfach result:=... eingeben und es geht ^^
hätte gedacht result würde automatisch eingefügt werden wenn nix da steht
Was mich allerdings irritiert hat, dass es ein Dezimalkomma, kein Punkt gibt.
Andreas Pfau
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 997



BeitragVerfasst: So 02.03.08 18:36 
Hi,

das ist so festgelegt in den Ländereinstellungen. Der Punkt wird in Delphi nur genutzt, weils sich an dem amerikanischen Standard orientiert. Ist eben kein deutsches Delphi. Kannst du aber umgehen, in dem du der Variable DecimalSeparator einen Punkt zuweist.

_________________
Life is a bad adventure, but the graphic is really good!
fusco123 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 40



BeitragVerfasst: Do 06.03.08 17:06 
Vielen Dank für eure zahlreichen Antworten, bin bald mit dem prog fertig, werde es dann hier komplett posten ...
fusco123 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 40



BeitragVerfasst: Sa 15.03.08 11:53 
hat jemand ne idee wie ich nach mehreren graden ableiten kann, die formel heißt ja
zb für grad 3 : (n-0)(n-1)(n-2)x^(n-3), ich es schon mit ner schleife versucht, kriegs aber irwie net hin
Fiete
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 620
Erhaltene Danke: 370

W7
Delphi 6 pro
BeitragVerfasst: Sa 15.03.08 14:44 
Moin fusco123,
schau mal hier nach www.delphi-forum.de/...tegrieren_78996.html

Gruß
Fiete

_________________
Fietes Gesetz: use your brain (THINK)
fusco123 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 40



BeitragVerfasst: So 16.03.08 15:28 
Hab jetzt ma probeweise mit ner höheren Ableitung grad 3 (könnte nätürlich auch (n-0)(n-1) ... schreiben, aber ich will es später ja für beliebig hohe Ableitungen machen) versucht geht aber nicht:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
function ableitung(a,n,x: single):single;
  var grad,i:integer;

 begin
 grad:=3;
for i := 0 to grad  do
 begin
result:=n*a*Power(x,(n-grad));
n:=n-1;
result:=result*(n)
  end;
end;


Moderiert von user profile iconAXMD: Delphi-Tags hinzugefügt
fusco123 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 40



BeitragVerfasst: Mo 17.03.08 12:33 
mir ist noch ne andere möglichkeit eingefallen, die allerdings auch nicht geht ^^:


function ableitung(a,n,x: single;grad:=cardinal):single;
var i:integer;
begin

for i := 0 to grad do
begin
result:=(n-i)*a*Power(x,(n-grad));

end;
end;


ich vermute, dass das irgenwie mit der schleife zu tun hat, hat jemand ne idee ???
fusco123 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 40



BeitragVerfasst: Mi 19.03.08 00:20 
user profile iconfusco123 hat folgendes geschrieben:
mir ist noch ne andere möglichkeit eingefallen, die allerdings auch nicht geht ^^:


function ableitung(a,n,x: single;grad:=cardinal):single;
var i:integer;
begin

for i := 0 to grad do
begin
result:=(n-i)*a*Power(x,(n-grad));

end;
end;


ich vermute, dass das irgenwie mit der schleife zu tun hat, hat jemand ne idee ???