Fórum Funçao 2º Grau #279615
29/04/2005
0
[b:a96130b491][u:a96130b491]CODIGO[/u:a96130b491][/b:a96130b491]:
unit EquacaoUnt;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
Label2: TLabel;
edA: TEdit;
edB: TEdit;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
edC: TEdit;
edX1: TEdit;
Label6: TLabel;
Label7: TLabel;
edX2: TEdit;
Button1: TButton;
Label8: TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
a,b,c,Delta,Func1,Func2,Z,W: real;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
a:=StrToFloat(edA.Text);
b:=strtofloat(edB.Text);
c:=strtofloat(edC.Text);
Delta:=b*b - 4*a*c;
Z:=-b + sqrt(Delta);
W:=-b - sqrt(Delta);
Func1:=Z/2*a;
Func2:=W/2*a;
edX1.Text:=floattostr(Func1);
edX2.Text:=floattostr(Func2);
end;
end.
Plinho_v
Curtir tópico
+ 0Posts
29/04/2005
Massuda
... Func1:=Z/(2*a); Func2:=W/(2*a); ...
Gostei + 0
29/04/2005
Plinho_v
[]´s
Gostei + 0
30/04/2005
Plinho_v
[]´s
Gostei + 0
30/04/2005
Marco Salles
Acredito , que o Problema da , quando Delta form Menor que zero --->>>
Porque ai se tem Raizes Complezas
Para este caso , eu não sei se lembro bem. mas as raizes são
Z:=-b + i*sqrt(Delta);
W:=-b - i*sqrt(Delta);
Onde i é o numero complexo
Para este casos , acredito que voce deve testar uma condição que separe as Respostas reais das complexas
Tente isto :arrow: :arrow:
procedure TForm1.Button1Click(Sender: TObject); begin a:=StrToFloat(edA.Text); b:=strtofloat(edB.Text); c:=strtofloat(edC.Text); Delta:=b*b - 4*a*c; if Delta >= 0 then begin Z:=-b + sqrt(Delta); W:=-b - sqrt(Delta); Func1:=Z/(2*a); Func2:=W/(2*a); edX1.Text:=floattostr(Func1); edX2.Text:=floattostr(Func2); end else begin Delta:=-1*Delta; edX1.Text:=FloatToStr(-b)+´ +i*´+FloatToStr(sqrt(Delta)); edX2.Text:=FloatToStr(-b)+´ -i*´+FloatToStr(sqrt(Delta)); end end;
Gostei + 0
30/04/2005
Plinho_v
[]´s
Gostei + 0
30/04/2005
Massuda
Gostei + 0
30/04/2005
Marco Salles
Não tem porque da erro , quando Delta = 0 , pois a raiz quadrada de Zero é Zero
A função sqtr(0) = 0 e pronto.
Gostei + 0
30/04/2005
Marco Salles
begin
a:=StrToFloat(edA.Text);
b:=strtofloat(edB.Text);
c:=strtofloat(edC.Text);
Delta:=b*b - 4*a*c;
if Delta >= 0 then
begin
Z:=-b + sqrt(Delta);
W:=-b - sqrt(Delta);
Func1:=Z/(2*a);
Func2:=W/(2*a);
edX1.Text:=floattostr(Func1);
edX2.Text:=floattostr(Func2);
end
else
begin
Delta:=-1*Delta;
edX1.Text:=FloatToStr(-b/(2*a))+´ +i*´+FloatToStr(sqrt(Delta)/(2*a));
edX2.Text:=FloatToStr(-b/2*a)+´ -i*´+FloatToStr(sqrt(Delta)/(2*a));
end
end;
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)