![]() |
|
#1
|
|||
|
|||
![]() Здравствуйте ,алгоритм задания на картинке , подскажите в чем ошибка .
Код:
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Buttons, ExtCtrls, TeeProcs, TeEngine, Chart, Series; type TForm1 = class(TForm) Chart1: TChart; BitBtn1: TBitBtn; Button1: TButton; Edit1: TEdit; Edit2: TEdit; Edit3: TEdit; Edit4: TEdit; Label1: TLabel; Label2: TLabel; Label3: TLabel; Label4: TLabel; Label5: TLabel; Series1: TLineSeries; procedure FormCreate(Sender: TObject); procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} type t=function(x:extended):extended ; function y(x:extended):extended; begin y:=2*x*x+x; end; procedure TForm1.FormCreate(Sender: TObject); begin edit1.clear; edit2.clear; edit3.clear; edit4.clear; label5.caption:=''; end; procedure TForm1.Button1Click(Sender: TObject); var x1,x0,a,b,shag,c,pog,x:extended; begin a:=strtofloat(edit1.text); b:=strtofloat(edit2.text); shag:=strtofloat(edit3.text); pog:=strtofloat(edit4.text); series1.clear; x0:=a; x1:=b; x:=(x0+x1)/2; repeat series1.AddXY(x0,y(x0),'',clblue); x0:=x0+0.1; // шаг repeat series1.AddXY(x1,y(x1),'',clred); x1:=x1+0.1; if (y(x0))*(y(x))>0 then (x1=x) else (x0=x) ; c:=(x0+x1)/2; label5.caption:=+floattostr(c); until (x1-x0)<0.000000001 ; end; end. Последний раз редактировалось qpmr, 24.05.2012 в 23:21. |
#2
|
||||
|
||||
![]() Смотря каково её проявление.
jmp $ ; Happy End! The Cake Is A Lie. |
#3
|
|||
|
|||
![]() [Error] Unit1.pas(71): Statement expected, but expression of type 'Boolean' found
При задании условия .. |
#4
|
||||
|
||||
![]() Код:
if (y(x0))*(y(x))>0 then (x1=x) and (y(x1)=y(x)) else (x0=x) and (y(x0)=y(x)) ; Ну так конечно. And - логическа операция, а не объединение действий. ![]() Вообще смысл не очень понял. Перевожу написанное на русский язык: "Если y(x0)*y(x) больше 0 то (x1 равно x) ^ (y(x1) равно y(x)) иначе ..." Ну равно x и y(x1), компьютеру-то что делать? ![]() jmp $ ; Happy End! The Cake Is A Lie. |
#5
|
||||
|
||||
![]() предположу, что где-то тут, что-то не так...
Код:
if (y(x0))*(y(x))>0 then (x1=x) and (y(x1)=y(x)) else (x0=x) and (y(x0)=y(x)) ; Код:
(x1=x) and (y(x1)=y(x)) Код:
(x0=x) and (y(x0)=y(x)) Понять, что хочет заказчик - бесценно, ведь он платит MasterCard ![]() |
#6
|
|||
|
|||
![]() так ведь в алгоритме именно так и написано ..
|
#7
|
||||
|
||||
![]() Так надо отличать в алгоритме условия и нахождение значения переменных.
jmp $ ; Happy End! The Cake Is A Lie. |
#8
|
|||
|
|||
![]() А как отличить , по алгоритмам мы еще не писали ничего , получается функции нужно поубирать ?
|
#9
|
|||
|
|||
![]() Вот поправил , но не рисует почему-то..
Последний раз редактировалось qpmr, 31.05.2012 в 22:24. |
#10
|
|||
|
|||
![]() Наконец удалось . частично . Считает только один корень и почему -то не выводит в chart !
Код:
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls, TeEngine, Series, TeeProcs, Chart; type TForm1 = class(TForm) Button1: TButton; Label1: TLabel; Chart1: TChart; Series1: TLineSeries; Edit1: TEdit; Edit2: TEdit; Edit3: TEdit; Edit4: TEdit; Label2: TLabel; Label3: TLabel; Label4: TLabel; Label5: TLabel; procedure Button1Click(Sender: TObject); procedure FormCreate(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} Function f(x: extended): extended; Begin f:=x*x+x+1; End; procedure TForm1.Button1Click(Sender: TObject); var a,b,e,c,x,h: extended; begin series1.clear; a:=strtofloat(edit1.Text); b:=strtofloat (edit2.Text); e:=strtofloat(edit4.Text); h:=strtofloat(edit3.text); repeat c:=(a+b)/2; if f(a)*f(c)>0 then a:=c else b:=c; until abs(b-a)<e ; label1.caption:='Корень = '+floattostr(c); x:=с; repeat x:=x+h; series1.AddXY(x,f(x)); until abs(b-a)>=e; end; procedure TForm1.FormCreate(Sender: TObject); begin edit1.Clear;edit2.Clear;edit3.Clear;edit4.Clear; end; end. |