В project1 :
- Код: Выделить всё
program project1;
{$mode objfpc}{$H+}
uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Classes, Unit1
{ you can add units after this };
{$R *.res}
var z,b,c,d,r,w: complex;
q: real;
begin
z:= compl(1,2);
b:=product(im,im);
writec(b); //sqr(i)=-1
c:=minus(z,z);
writec(c); // x-x=0
d:=conj(im);
writec(d); // i*=-i
w:= expc(prod(q,im));
writec(w);
{r:= diviz(z,z) ;
writec(r); // x/x=1 }
writec( z);
readln( );
end.
end.
В unit1:
- Код: Выделить всё
{ complex arifmetics }
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils;
type complex=record
re: real;
im: real;
end;
const im: complex = (re: 0;im :1);
function compl(x,y: real): complex;
procedure writec(x: complex); // complex write
function sum(x,y: complex): complex;
function conj(x: complex): complex;
function neg(x: complex): complex;
function product (x,y: complex): complex;
function norm (x: complex): real;
function diviz(x,y: complex): complex;
function norm2(x: complex): real;
function minus(x,y: complex): complex;
function expc(x: complex): complex;
function prod(x: real;y: complex): complex;
implementation
function compl(x,y: real): complex;
begin
compl.re:=x;
compl.im:=y;
end;
procedure writec(x:complex);
begin
writeln('re : ',x.re);
writeln('im : ',x.im);
writeln
end;
function sum(x,y: complex): complex;
begin
sum.re:=x.re+y.re;
sum.im:=x.im+y.im;
end;
function conj(x: complex): complex;
begin
conj.re:=x.re;
conj.im:= -x.im;
end;
function neg(x: complex): complex;
begin
neg.re:=-x.re;
neg.im:=-x.im;
end;
function product (x,y: complex): complex;
begin
product.re:=x.re*y.re-x.im*y.im;
product.im:=x.re*y.im+x.im*y.re;
end;
function diviz(x,y: complex): complex;
begin
diviz:=prod(1/norm(y),product(x,conj(y)));
end;
function norm (x: complex): real;
var
z: real;
begin
norm:=sqrt(sqr(x.re)+sqr(x.im));
end;
function norm2(x: complex): real;
begin
norm2:=sqr(norm(x));
end;
function minus(x,y: complex): complex;
begin
minus.im:=x.im-y.im;
minus.re:=x.re-y.re;
end;
function expc(x: complex): complex;
begin
expc.re:=exp(x.re)*cos(x.im);
expc.im:=exp(x.re)*sin(x.im);
end;
function prod(x: real;y: complex): complex;
begin
prod.re:=x*y.re;
prod.im:=x*y.im;
end;
end.
И еще что-то напартачил в к коде с арифметической регрессией:
- Код: Выделить всё
program project1;
{$mode objfpc}{$H+}
uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Classes
{ you can add units after this };
{$R *.res}
var
j: text; x,y: array[0..100] of real; s: string;
a,b: real;
i,c,n: integer;
l,k,m,d,w: real;
begin
AssignFile(j,'j.txt');
reset(j);
i:=0;
while not eof(j) do
begin
Readln(j,s);
Val(s,x[i],c);
Readln(j,s);
val(s,y[i],c);
inc(i);
end;
CloseFile(J);
n:=i-1;
for i:=0 to n do
begin
writeln(x[i],' ',y[i]);
end;
l:=0;k:=0;m:=0;d:=0;w:=0;
for i:=0 to n do
begin
l:=y[i]+l;
k:= sqr(x[i])+k;
m:=x[i]+m;
d:=x[i]*y[i]+d;
w:=1+w;
end;
b:=(k*l-m*d)/(k*w-m*m);
a:=(d*w-m*l)/(k*w-m*m);
writeln(a);
writeln(b);
readln( );
end.
В последнем пишет проект вызвал класс исключения' External:SIGFPE'.