.


:




:

































 

 

 

 


4.




.

. , (.. ). , 12 .

 

.

1. ( , , , ). PrintIntegr, : . . , , NIL. .

2. WHILE, . PrintIntegr REPEAT, , (Y / N)? N.

 

:

,

, .

:

, ,
, .

-: .

 

Sum. : f, [ a, b ], n. : , .

. .

1. .

2. 0.

3. i 0 n -1 :

. .

4. .

. .

 

Integr. : f, [ a, b ], δ. : .

. .

1. n 8.

2. ( Result) f [ a, b ] n .

3. :

. P.

. n.

. f [ a, b ] n ( Sum).

4. | Result - P |<δ (.. ).

. .

 

PrintIntegr. : f () G.

. .

1. :

. " [ a, b ]".

. a, b.

. " ", Integr (f, a, b,10-6), "0.000001".

. , " ", G (b)- G (a).

. " (Y / N)?".

. ot.

2. ot = 'N'.

. .

 

Lab4.

. .

1. Loop "".

2. Loop "", :

. : "1
2
3
4
5 ".

. " ".

. n.

. n:

1. n =1, PrintIntegr f1 G1.

2. n =2, PrintIntegr f2 G2.

3. n =3, PrintIntegr f3 .

4. n =4, PrintIntegr f4 .

5. n =5, Loop "".

3. .

. .

 

program Lab4;

{$APPTYPE CONSOLE}

uses SysUtils;

type

Func=function (x:Real):Real;

 

function Sum(f:Func;a,b:Real;n:Integer):Real;

var

dx:Real;

i:Integer;

begin

dx:=(b-a)/n;

Result:=0;

for i:=0 to n-1 do

Result:=Result+dx*f(a+i*dx+dx/2);

end;

 

function Integr(f:Func;a,b,MaxError:Real):Real;

var

n:Integer;

Prev:Real;

begin

n:=8;

Result:=Sum(f,a,b,n);

repeat

Prev:=Result;

n:=n*2;

Result:=Sum(f,a,b,n);

until Abs(Result-Prev)<MaxError;

end;

 

procedure PrintIntegr(f,G:Func);

var

a,b:Real;

ch:Char;

begin

repeat

Write(' : ');

ReadLn(a,b);

 

Writeln(' : ',
Integr(f,a,b,1e-6):1:6,'+-',1e-6:1:6);

if @G<>nil then

Writeln(' : ',
G(b)-G(a):1:10);

 

Write(' (Y/N)? ');

Readln(ch);

until UpCase(ch)='N';

end;

 

function f1(x:Real):Real;

begin f1:=x*sin(x) end;

function G1(x:Real):Real;

begin G1:=sin(x)-x*cos(x) end;

 

function f2(x:Real):Real;

begin f2:=sqr(cos(x)) end;

function G2(x:Real):Real;

begin G2:=x/2+sin(2*x)/4 end;

 

function f3(x:Real):Real;

begin f3:=sin(x)/x end;

 

function f4(x:Real):Real;

begin f4:=exp(sqr(x)) end;

 

var

n:Integer;

Loop:Boolean;

begin

Loop:=True;

while Loop do

begin

Writeln(':');

Writeln('1. x*sin(x)');

Writeln('2. sqr(cos(x))');

Writeln('3. sin(x)/x');

Writeln('4. exp(sqr(x))');

Writeln('5. ');

Write(' : ');

Readln(n);

Writeln;

case n of

1:PrintIntegr(f1,G1);

2:PrintIntegr(f2,G2);

3:PrintIntegr(f3,nil);

4:PrintIntegr(f4,nil);

5:Loop:=False;

end;

Writeln;

end;

end.

 

, . , . . .

 

a b
x sinx     0.3011680.000001 0.3011686789
x sinx     1.7415910.000001 1.7415910999
x sinx     1.3695070.000001 1.3695063979
x sinx     3.1110980.000001 3.1110974979
cos2 x     0.7273250.000001 0.7273243567
cos2 x     0.8107990.000001 0.8107993762
cos2 x     0.6193470.000001 0.6193467493
cos2 x     1.4301460.000001 1.4301461255
sin x / x     0.6593300.000001
sin x / x     0.2432390.000001
sin x / x     0.9025700.000001
ex2     1.4626520.000001
ex2     14.9899760.000001
ex2     16.4526280.000001

 

, .

 





:


: 2016-12-17; !; : 1593 |


:

:

.
==> ...

1756 - | 1610 -


© 2015-2024 lektsii.org - -

: 0.033 .