Autor Beitrag
Arno Nym
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 131



BeitragVerfasst: Mi 07.06.06 17:32 
Hi!
der Begriff "record file" ist komisch, sowas gibs nich in delphi.
Mann könnte es allerdings zuerst in einem "Record" und dann in einem "File" abspeichern...
Frage 2 wäre was genau gespeichert werden soll
eine Funktionstabelle ?
also nach sowas:
[x0 = 0]
[n = 20]
//x y
-3 50
-2.4 22
...
...
[/n]
[n=21]
...
...
[/n]
[/x0]

oder wie ?
MFG, Arno Nym
Master3 Threadstarter
Hält's aus hier
Beiträge: 12



BeitragVerfasst: Mi 07.06.06 19:35 
Ja, ich denke mal das es in einem File extra abgespeichert werden muss.

Also als Aufgabe wird gesagt, das die jeweils berechnete Taylor Reihe in geeigneten Records in einem File abgespeichert werden müssen.
Da bin ich mir selbst unschlüssig was da genau abgespeichert werden muss.
Ich schätze schon eine Funktionstabelle. Also wahrscheinlich die y und x Werte.
Oder wüsstest du was?
Was anderes kann ich mir da nicht vorstellen.
Arno Nym
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 131



BeitragVerfasst: Mi 07.06.06 20:11 
Hi!
also da es nicht genauer definiert ist gehen wir mal von der für uns einfachsten Variante aus :)
Ich würd sagen du speicherst einfach die 500 Punkte die in da für ein Polynom N-ten grades berechnet werden.

Also zuerst definierst du im interfaceteil den Typ:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
type Trealpoint = record
 x: real;
 y: real;
end;

und nun das array dazu...
ausblenden Delphi-Quelltext
1:
var polyarray : array[0..500] of Trealpoint;					

...was ja eigentlich 501 sind aber deine schleife geht ja auch von 0 bis 500...
und genau da in die Schleife kommt dann..
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
 ...
 For i := 0 To 500 do begin; // Hauptroutine   
  x := (-4+(8/500)*i);   
  y := round(taylorpolynom(x,x0,n) * (500/8));
 polyarray[i].x := x;
 polyarray[i].y := y / (500*8); //wär natürlich schöner das zwischen dem aufruf von taylorpolynom und dem 
 ...                            // multiplizieren mit (500/8) zu machen

so, da wird das nun gefüllt.
Jetzt brauchst du nur noch nen SaveDialog und nen Knopf zum speichern
und da steht dann beim drücken:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
procedure TForm1.ButtonSaveClick(Sender: TObject);
var F: TextFile;
    i : Integer;
begin
 if Savedialog1.Execute then begin; //savesdialog ausführen
  {$I-}
  AssignFile(F, Savedialog1.FileName); // F der Datei im Savedialog.Filename zuweisen
  Rewrite(F);  // datei zum schreiben öffnen
   For i := 0 To 500 do begin;
    writeln(F,polyarray[i].x, polyarray[i].y);
   end;
  CloseFile(F); // datei schließen
  {$I+}
 end;
end;

und nu stehts alles in der Datei...
MFG, Arno Nym
Master3 Threadstarter
Hält's aus hier
Beiträge: 12



BeitragVerfasst: Do 08.06.06 15:55 
Da ich noch das Koordinatensystem verschieben musste, hatte ich noch eine SChleife eingebaut für die restlichen Pixel, da vorne sonst ein Stück fehlte.
Nun funktioniert das aber nicht so mit dem Speichern.
Der muss ja nun von -5 bis 3 Speichern, machts aber von -4 bis 4.
So sieht das Programm nun aus.
Mit der 2ten SChleife gibts Probleme.

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:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242:
243:
244:
245:
246:
247:
248:
249:
250:
251:
252:
253:
254:
255:
256:
257:
258:
259:
260:
261:
262:
263:
264:
265:
266:
267:
268:
269:
270:
271:
272:
273:
unit Unit1;

interface


uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, Buttons,math ;

 type Trealpoint = record
 x: real;
 y: real;
 end;
type
  TForm1 = class(TForm)
    PaintBox1: TPaintBox;
    BitBtn1: TBitBtn;
    Button2: TButton;
    Edit1: TEdit;
    ScrollBar1: TScrollBar;
    Edit3: TEdit;
    Label1: TLabel;
    GroupBox1: TGroupBox;
    GroupBox2: TGroupBox;
    Label2: TLabel;
    Label3: TLabel;
    Button3: TButton;
    GroupBox3: TGroupBox;
    Button1: TButton;
    SaveDialog1: TSaveDialog;
    GroupBox4: TGroupBox;
    {procedure Button1Click(Sender: TObject);}
    procedure Button2Click(Sender: TObject);
    procedure ScrollBar1Change(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private

    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;
  polyarray : array[0..500] of Trealpoint;
implementation

{$R *.dfm}


Function Fakultaet(n:Integer):real;
var i : Integer;
begin;
 result := 1;
 For i := 2 To n do begin;
  result := result * i;
 end;
 IF n < 1 Then result := 1;
end;

Function Taylorpolynom(x, x0: real; n:Integer):real;
var i : Integer;
begin;
 result := 0;
 For i := 0 To n do begin;
  result := result + (exp(x0)/fakultaet(i))*(power(x-x0,i))
 end;

end;



Function GZahl(strin:String):Integer;
var code:Integer;
    Integ:Integer;
begin;
 VAL(strin,Integ,code);
 GZahl := Integ;
end;

Function Zahl(strin:String):Real;
begin;
 Zahl := StrtoFloat(Strin);
end;

 procedure TForm1.Button2Click(Sender: TObject);
var x, x0,ye : real;
    i, n, y, oldy: Integer;
begin
    n := gZahl(edit1.text);
    x0 := Zahl(edit3.Text);
    paintbox1.Canvas.pen.Color := clblack;
    paintbox1.Canvas.Brush.Color:=clwhite;
   paintbox1.Canvas.rectangle(0,0,500,500);
   paintbox1.Canvas.MoveTo(0,250);

   for i:=-250 to 250 do                {Zählschleife für Pixel}
   begin
    ye:=(exp((i*8)/500))*(500/8);             {Aufteilung der Pixel}
    paintbox1.canvas.LineTo(i+round(312.5),250-round(ye));
    paintbox1.canvas.MoveTo(i+round(312.5),250-round(ye));  {e^x zeichnen}
   end;


  with paintbox1.canvas do
  begin
   Pen.Color:=clblack;
   MoveTo(round(312.5),0);         {Achsen}
   LineTo(round(312.5),500);
   MoveTo(0,250);
   lineto(500,250);
   pen.color:=clblack;

   for i:=1 to 3 do                           {x-Achse}
      begin
        moveto(round(i*62.5)+round(312.5),255);
        lineto(round(i*62.5)+round(312.5),245);
        textout(round(i*62.5)+round(309.5),230,inttostr(i));
      end;
   for i:=1 to 4 do                                    {y-Achse}
     begin
       moveto(round(317.5),250-round(i*62.5));
       lineto(round(308.5),250-round(i*62.5));
       textout(round(295.5),250-round(i*62.5)-5,inttostr(i));
     end;

    for i:=-5 to-1 do
       begin
         moveto(round(312.5)-(abs(round(i*62.5))),255);
         lineto(round(312.5)-(abs(round(i*62.5))),245);
         textout(round(308.5)-(abs(round(i*62.5))),230,inttostr(i));
       end;
     for i:=-4 to -1 do
       begin
       moveto(round(317.5),abs(round(i*62.5))+250);
       lineto(round(308.5),abs(round(i*62.5))+250);
       textout(round(295.5),abs(round(i*62.5))+245,inttostr(i));
      end;
   end;

 paintbox1.Canvas.Pen.Color := clred;
 x := (-5+(8/500)*round(62.5));  // Startwert berechnen
 oldy := round(taylorpolynom(x,x0,n) * (500/8)); // Starty berechnen
 For i := 0 To 500 do begin; // Hauptroutine
  x := (-4+(8/500)*i);
  y := round(taylorpolynom(x,x0,n) * (500/8));
  polyarray[i].x := x;
  polyarray[i].y := y / (500*8);
  paintbox1.Canvas.MoveTo(i-1+round(62.5),250-oldy);
  paintbox1.Canvas.LineTo(i+round(62.5),250-y);
  oldy := y;
 end;
  for i:= -round(62.5) to 0 do begin             //hier in der schleife gibts das problem, ohne dem 2ten polyarray gehts
  x := (-4+(8/500)*i);                           //aber nicht richtig 
  y := round(taylorpolynom(x,x0,n)* (500/8));   
  {polyarray[i].x := x;
  polyarray[i].y := y / (500*8);}

  paintbox1.Canvas.MoveTo(i-1+round(62.5),250-oldy);
  paintbox1.Canvas.LineTo(i+round(62.5),250-y);
  oldy := y;
   end;

end;

procedure TForm1.ScrollBar1Change(Sender: TObject);
begin
edit1.Text:=inttostr(scrollbar1.position);
end;

procedure TForm1.Button3Click(Sender: TObject);
var x, x0,ye : real;
    i, n, y, oldy,runner: Integer;
begin
    n:=gZahl(edit1.text);
 For runner := 0 To n do begin;
   begin

    x0 := Zahl(edit3.Text);
    paintbox1.Canvas.pen.Color := clblack;
   paintbox1.Canvas.Brush.Color:=clwhite;
   paintbox1.Canvas.rectangle(0,0,500,500);
   paintbox1.Canvas.MoveTo(0,250);

   for i:=-250 to 250 do                {Zählschleife für Pixel}
   begin
    ye:=(exp((i*8)/500))*(500/8);             {Aufteilung der Pixel}
    paintbox1.canvas.LineTo(i+round(312.5),250-round(ye));
    paintbox1.canvas.MoveTo(i+round(312.5),250-round(ye));  {e^x zeichnen}
   end;


  with paintbox1.canvas do
  begin
   Pen.Color:=clblack;
   MoveTo(round(312.5),0);         {Achsen}
   LineTo(round(312.5),500);
   MoveTo(0,250);
   lineto(500,250);
   pen.color:=clblack;
   for i:=1 to 3 do                           {x-Achse}
      begin
        moveto(round(i*62.5)+round(312.5),255);
        lineto(round(i*62.5)+round(312.5),245);
        textout(round(i*62.5)+round(309.5),230,inttostr(i));
      end;
   for i:=1 to 4 do                                    {y-Achse}
     begin
       moveto(round(317.5),250-round(i*62.5));
       lineto(round(308.5),250-round(i*62.5));
       textout(round(295.5),250-round(i*62.5)-5,inttostr(i));
     end;

    for i:=-5 to-1 do
       begin
         moveto(round(312.5)-(abs(round(i*62.5))),255);
         lineto(round(312.5)-(abs(round(i*62.5))),245);
         textout(round(308.5)-(abs(round(i*62.5))),230,inttostr(i));
       end;
     for i:=-4 to -1 do
       begin
       moveto(round(317.5),abs(round(i*62.5))+250);
       lineto(round(308.5),abs(round(i*62.5))+250);
       textout(round(295.5),abs(round(i*62.5))+245,inttostr(i));
      end;
   end;

 paintbox1.Canvas.Pen.Color := clred;
 x := (-5+(8/500)*round(62.5));  // Startwert berechnen
 oldy := round(taylorpolynom(x,x0,runner) * (500/8)); // Starty berechnen
 For i := 0 To 500 do begin; // Hauptroutine
  x := (-4+(8/500)*i);
  y := round(taylorpolynom(x,x0,runner)* (500/8));
  polyarray[i].x := x;
  polyarray[i].y := y / (500*8);
  paintbox1.Canvas.MoveTo(i-1+round(62.5),250-oldy);
  paintbox1.Canvas.LineTo(i+round(62.5),250-y);
  oldy := y;
  end;
  for i:= -round(62.5) to 0 do begin
  x := (-4+(8/500)*i);
  y := round(taylorpolynom(x,x0,runner)* (500/8));
 { polyarray[i].x := x;
  polyarray[i].y := y / (500*8);}

  paintbox1.Canvas.MoveTo(i-1+round(62.5),250-oldy);
  paintbox1.Canvas.LineTo(i+round(62.5),250-y);
  oldy := y;
   end;
   if n<10 then sleep(1200) else sleep(500);

   end;
end;
end;

procedure TForm1.Button1Click(Sender: TObject);

var F: TextFile;
    i : Integer;
begin
 if Savedialog1.Execute then begin; //savesdialog ausführen
  {$I-}
  AssignFile(F, Savedialog1.FileName); // F der Datei im Savedialog.Filename zuweisen
  Rewrite(F);  // datei zum schreiben öffnen
   For i := 0 To 500 do begin;
    writeln(F,polyarray[i].x, polyarray[i].y);
   end;
  CloseFile(F); // datei schließen
  {$I+}
 end;
end;


end.


Edit: Habs hingekriegt
Hab den Zählbereich geändert. Von -62,5 zu 437,5, dann gings.
Wenn du aber irgendwelche Verbersserungsvorschläge hättest, würde ich die gern hören.