. . , , , ( 4 ). R () . , R (). , . .
4
,
s , .
, .
function[]=LocalizExtrem1D_170809();
%
function y=f(x)
%
% ,
%
y=(x+2).*(x-4); % * .
% ;
%
end
% :
disp(' ');
disp(' : y=(x+2)*(x-4)');
disp(' , ');
function[x,y,mas1x,mas1y,xleft1,xright1,nn]=LocExt1(); %
disp(' ');
disp(' ');
disp('y=(x+2)*(x-4)');
disp(' , ')
%
xleft=input(' =');
xright=input(' =');
choice=input(' ? =1 =0');
if choice==0
yeps=input(' :');
else
yeps=input(' :');
end
xleft1=xleft;
xright1=xright;
%
n=5; %5 , 4
nn=1;
TheEnd=0;
while TheEnd==0
dx=(xright-xleft)/4;
masx(1)=xleft;
masy(1)=f(xleft);
disp(' ');
for i=2:n
%
masx(i)=masx(i-1)+dx;
masy(i)=f(masx(i));
string=strcat(:,num2str(masx(i)), :,num2str(masy(i)));
disp(string);
%
if choice==1
if abs(masy(i)-masy(i-1))<yeps
TheEnd=1;
end
else
if abs(xright-xleft)<eps
TheEnd=1;
end
end
end
%
min=masy(1)
num=1;
for i=2:n
if masy(i)<min
min=masy(i);
num=i;
end
end
string=strcat( :,num2str(masx(num)), :,num2str(masy(num)));
|
|
disp(string);
%
if num==1
xright=masx(2);
elseif num==n
xleft=masx(n-1);
else
xleft=masx(num-1);
xright=masx(num+1);
end
%
for i=1:5
mas1x(nn)=masx(i);
mas1y(nn)=masy(i);
nn=nn+1;
end
end
%
x=masx(num);
y=masy(num);
end
disp(' ');
disp(' ');
disp('y=(x+2)*(x-4)');
disp(' , ')
%
[x,y,mas1x,mas1y,xleft1,xright1,nn]=LocExt1();
nn=nn-1;
%
choiceTab=input(' ? =1 =0 ');
choiceGraf=input(' ? =1 =0 ');
%
if choiceTab==1
disp(' ');
for i=1:nn
string=print(= %4i\t= %7.3f\t= %7.3f,i,mas1x(i),mas1y(i));
disp(string);
end
end
%
% num2str
disp(' ')
sx=strcat(' =',num2str(x));
sy=strcat(' =',num2str(y),' :',num2str(abs(mas1y(nn)-mas1y(nn-1))));
sn=strcat(':',num2str(nn),' ');
disp(sx) %
disp(sy)
%
h=0.1;
x1=xleft1:h:xright1;
y1=f(x1);
plot(x1,y1,k-);
grid on;
title('y=(x+2)(x-4)');
xlabel('X');
ylabel('Y');
text(x,y,\leftarrow Minimum);
zeroMas=x1*0;
hold on;
if choiceGraf==1
plot(mas1x,mas1y,r.);
legend(plot with minimal step,points by Localisation method,0);
else
legend(plot with minimal step,0);
end
hold on;
plot(x1,zeroMas,k-,zeroMas,y1,k-);
end
, :
: y=(x+2)*(x-4)
,
y=(x+2)*(x-4)
,
=-10
=10
? =1 =01
:0.01
:-5 :27
:0 :-8
:5 :7
:10 :72
:0 :-8
:-2.5 :3.25
:0 :-8
:2.5 :-6.75
:5 :7
:0 :-8
:-1.25 :-3.9375
:0 :-8
:1.25 :-8.9375
:2.5 :-6.75
:1.25 :-8.9375
:0.625 :-8.8594
:1.25 :-8.9375
:1.875 :-8.2344
:2.5 :-6.75
:1.25 :-8.9375
|
|
:0.9375 :-8.9961
:1.25 :-8.9375
:1.5625 :-8.6836
:1.875 :-8.2344
:0.9375 :-8.9961
:0.78125 :-8.9521
:0.9375 :-8.9961
:1.0938 :-8.9912
:1.25 :-8.9375
:0.9375 :-8.9961
? =1 =0 1
? =1 =0 1
= 1 =-10.000 =112.000
= 2 = -5.000 = 27.000
= 3 = 0.000 = -8.000
= 4 = 5.000 = 7.000
= 5 = 10.000 = 72.000
= 6 = -5.000 = 27.000
= 7 = -2.500 = 3.250
= 8 = 0.000 = -8.000
= 9 = 2.500 = -6.750
= 10 = 5.000 = 7.000
= 11 = -2.500 = 3.250
= 12 = -1.250 = -3.938
= 13 = 0.000 = -8.000
= 14 = 1.250 = -8.938
= 15 = 2.500 = -6.750
= 16 = 0.000 = -8.000
= 17 = 0.625 = -8.859
= 18 = 1.250 = -8.938
= 19 = 1.875 = -8.234
= 20 = 2.500 = -6.750
= 21 = 0.625 = -8.859
= 22 = 0.938 = -8.996
= 23 = 1.250 = -8.938
= 24 = 1.563 = -8.684
= 25 = 1.875 = -8.234
= 26 = 0.625 = -8.859
= 27 = 0.781 = -8.952
= 28 = 0.938 = -8.9961
= 29 = 1.094 = -8.991
= 30 = 1.250 = -8.938
=0.9375
=-8.9961 :0.053711
. 2.3.
:
: y=(x+2)*(x-4)
,
y=(x+2)*(x-4)
,
=-10
=10
? =1 =00
:0.1
:-5 :27
:0 :-8
:5 :7
:10 :72
:0 :-8
:-2.5 :3.25
:0 :-8
:2.5 :-6.75
:5 :7
:0 :-8
:-1.25 :-3.9375
:0 :-8
:1.25 :-8.9375
:2.5 :-6.75
:1.0156 :-8.9998
:0.97656 :-8.9995
:1.0156 :-8.9998
:1.0547 :-8.997
:1.0938 :-8.9912
:1.0156 :-8.9998
:0.99609 :-9
:1.0156 :-8.9998
:1.0352 :-8.9988
:1.0547 :-8.997
:0.99609 :-9
? =1 =0 1
? =1 =0 1
|
|
= 1 =-10.000 =112.000
= 2 = -5.000 = 27.000
= 3 = 0.000 = -8.000
= 4 = 5.000 = 7.000
= 5 = 10.000 = 72.000
= 6 = -5.000 = 27.000
= 7 = -2.500 = 3.250
= 8 = 0.000 = -8.000
= 9 = 2.500 = -6.750
= 10 = 5.000 = 7.000
= 11 = -2.500 = 3.250
= 12 = -1.250 = -3.938
= 13 = 0.000 = -8.000
= 14 = 1.250 = -8.938
= 15 = 2.500 = -6.750
= 39 = 1.055 = -8.997
= 40 = 1.094 = -8.991
= 41 = 0.977 = -8.999
= 42 = 0.996 = -9.000
= 43 = 1.016 = -9.000
= 44 = 1.035 = -8.999
= 45 = 1.055 = -8.997
=0.99609
=-9 :0.0017548