.


:




:

































 

 

 

 


()




() . , . . f(x) [a,b]. , , ( ). ε , .

, . ε. . . . (, ) , .. f(xi)>fmax , fmax := f(xi), . f(xi)<fmax , , , .. (xi-2h, xi), h . ( ) . , h ε.

, . . y=2x3 +10x2 +6x-20 [a,b] :

 

//

// ()

N2:=0; //

ReadLn(A,B,Eps,H);

Xn:=A;

while H>Eps do

begin

I:=0;

//

Ymax:=((2*Xn+10)*Xn+6)*Xn-20;

Xmax:=Xn;

//

//

repeat

I:=I+1;

//

X:=Xn+(I-1)*H;

//

Y:=((2*X+10)*X+6)*X-20;

N2:=N2+1;

//

//

if Y>Ymax then

begin

Ymax:=Y;

Xmax:=X;

end;

until (Y<Ymax);

//

//

Xn:= Xmax-H;

//

H:=H/2;

end;

 

, f(x) -f(x).

, , , . () . () ( ), .

. , ( , , , ). :

 

until (Y<Ymax)or(X>=B);

Xn:= Xmax-H;//

//

if Xn<A then Xn:=A; //

//

 

, , ( , , ) . ( ) . .

() . () . .

 

program Extremum;

{

()

y=2x3 +10x2 +6x-20 [a,b] eps

h.

y=6x2 +20x+6 - ,

y=12x+20 -

}

{$APPTYPE CONSOLE}

uses

SysUtils;

var

X,A,B,Aa,Bb,H,Y,Ymax,Ya,Yb,Ysr,Eps,Xmax,Dx,Xn,Xsr:Real;

I,N1,N2,K,Mon:Integer;

begin

WriteLn(' a,b,eps,h');

ReadLn(A,B,Eps,H);

Mon:=0; // :0 ;1-

// ,

// (

// )

Ya:= 6*A*A+20*A+6;

if Ya=0 then

Xmax:=A

else

begin

Yb:=6*B*B+20*B+6;

if Yb=0 then

Xmax:=B

else if Ya*Yb>0 then

begin

WriteLn (' '

+' ');

WriteLn (' 1,'

+' - -1');

ReadLn(K);

Mon:=1;

end

else

begin

Aa:=A;

Bb:=B;

Xsr:=(Aa+Bb)/2;

Ysr:= 6*Xsr*Xsr+20*Xsr+6;

while (Abs(Bb-Aa)>Eps)and(Ysr*Ya<>0) do

begin

if Ya*Ysr>0 then Aa:=Xsr else Bb:=Xsr;

Xsr:=(Aa+Bb)/2;

Ysr:= 6*Xsr*Xsr+20*Xsr+6;

end;

Xmax:=Xsr;

end;

end;

//

//

//( ,

// )

if Mon=0 then

begin

if 12*Xmax+20<0 then

K:=1

else

K:=-1;//

// f(x)

//

Ymax:=K*((2*Xmax+10)*Xmax+6)*Xmax-20;

case k of

1: WriteLn('ymax=',k*ymax:10:5,' xmax=',xmax:10:5);

-1: WriteLn('ymin=',k*ymax:10:5,' xmin=',xmax:10:5);

end;

ReadLn;

end;

//

// ,

//

N1:=Trunc((B-A)/Eps)+1;

//

Ymax:=((2*A+10)*A+6)*A-20;

Xmax:=A;

Dx:=Eps;

for I:=1 to N1-1 do

begin

X:=A+I*Dx;

Y:= K*(((2*X+10)*X+6)*X-20);

if Y>Ymax then

begin

Ymax:=Y;

Xmax:=X;

end;

end;

case k of

1: WriteLn('ymax=',k*ymax:10:5,' xmax=',xmax:10:5);

-1: WriteLn('ymin=',k*ymax:10:5,' xmin=',xmax:10:5);

end;

WriteLn('n1=',n1);

ReadLn;

//

// ()

N2:=0; //

Xn:=A;

while H>Eps do

begin

//

Ymax:=K*((2*Xn+10)*Xn+6)*Xn-20;

Xmax:=Xn;

I:=0;

//

//

repeat

I:=I+1;

X:=Xn+(I-1)*H; //

//

Y:=K*(((2*X+10)*X+6)*X-20);

N2:=N2+1;

if Y>Ymax then

//

//

begin

Ymax:=Y;

Xmax:=X;

end;

until (Y<Ymax)or(X>=B);

Xn:= Xmax-H; //

//

//

if Xn<A then

Xn:=A;

H:=H/2; //

end;

case k of

1: WriteLn('ymax=',k*ymax:10:5,' xmax=',xmax:10:5);

-1: WriteLn('ymin=',k*ymax:10:5,' xmin=',xmax:10:5);

end;

WriteLn('n1=',n1);

ReadLn;

end.





:


: 2016-11-22; !; : 784 |


:

:

- , , .
==> ...

1738 - | 1516 -


© 2015-2024 lektsii.org - -

: 0.023 .