Форум по Delphi программированию

Delphi Sources



Вернуться   Форум по Delphi программированию > Все о Delphi > [ "Начинающим" ]
Ник
Пароль
Регистрация <<         Правила форума         >> FAQ Пользователи Календарь Поиск Сообщения за сегодня Все разделы прочитаны

 
 
Опции темы Поиск в этой теме Опции просмотра
  #1  
Старый 20.07.2011, 16:03
ТехЗомби ТехЗомби вне форума
Прохожий
 
Регистрация: 20.07.2011
Сообщения: 1
Репутация: 10
По умолчанию Вычисление функции[Delphi]

Составить схему алгоритма и программу в Delphi вычисления заданной функции и построения её графика.
Функция: http://s1.uploads.su/j3g5dt.jpg
Параметры изменения аргумента (Входные данные):
Xn-начальное значение x
Xk-конечное значение x
dx-шаг
Программу вроде написал:
Код:
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
unit Unit1;
 
interface
 
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Grids, ComCtrls, StdCtrls, ExtCtrls, TeEngine, TeeFunci, Series,
  TeeProcs, Chart, XPMan;
 
type
  TForm1 = class(TForm)
    Panel1: TPanel;
    Label1: TLabel;
    Image1: TImage;
    Panel2: TPanel;
    Panel3: TPanel;
    Button1: TButton;
    Label2: TLabel;
    Edit1: TEdit;
    Edit2: TEdit;
    Label3: TLabel;
    Edit3: TEdit;
    Label4: TLabel;
    Button2: TButton;
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    TabSheet2: TTabSheet;
    StringGrid1: TStringGrid;
    Label5: TLabel;
    Edit4: TEdit;
    Chart1: TChart;
    Series1: TLineSeries;
    TeeFunction1: TAddTeeFunction;
    Series2: TLineSeries;
    XPManifest1: TXPManifest;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Edit1KeyPress(Sender: TObject; var Key: Char);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
 
var
  Form1: TForm1;
 
implementation
 
{$R *.dfm}
 
procedure TForm1.Button1Click(Sender: TObject);
begin
close;
end;
 
procedure TForm1.Button2Click(Sender: TObject);
   var a,y,dx,Xn,Xk,x:Extended;
   trow:integer;
begin
dx:=00;
    if trystrtofloat(edit1.text,xn) and trystrtofloat(edit2.text,xk) and trystrtofloat(edit3.text,dx) and (dx>0) and trystrtofloat(edit4.text,a)  then begin // проверяем условие
    x:=xn;
    form1.StringGrid1.Cells[0,0]:='Значения X';
    form1.StringGrid1.Cells[1,0]:='Значения Y';
    form1.StringGrid1.RowCount:=round((xk-xn)/dx)+1;
    form1.Series1.Clear;
    form1.Series2.Clear;
    trow:=1;
       while x<Xk do begin
             x:=x+dx;
             if x<=0 then begin Y:=exp(x+a);
             form1.Series1.Addxy(x,y);
             end
              else begin Y:=ln(x*a);
              form1.Series2.Addxy(x,y);
              end;
             form1.StringGrid1.cells[0,trow]:=formatfloat('0.0000000000000',x);
             form1.StringGrid1.cells[1,trow]:=formatfloat('0.0000000000000',y);
             trow:=trow+1;
 
 
 
       end;
    end;
end;
 
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if ((key>'0') and (key<'9')) or (key=#8) or (key=',') or (key='-') then
else key:=#0;
 
end;
 
end.
Как дописать,чтобы в таблице значений писало "ошибка",когда под н.логарифмом(ln(x*a)) получается отрицательное число (при а<0)?
Ответить с цитированием
 


Опции темы Поиск в этой теме
Поиск в этой теме:

Расширенный поиск
Опции просмотра

Ваши права в разделе
Вы не можете создавать темы
Вы не можете отвечать на сообщения
Вы не можете прикреплять файлы
Вы не можете редактировать сообщения

BB-коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход


Часовой пояс GMT +3, время: 08:36.


 

Сайт

Форум

FAQ

Соглашения

Прочее

 

Copyright © Форум "Delphi Sources" by BrokenByte Software, 2004-2025