. ( ) . , .
, . , , , .
, ( ), ( ). . , , . .
, .
Function[]=ObratnPolovShag1D_170809();
function y=f(x)
y=(x+2).*(x-4);
end
disp(' ');
disp(' : y=(x+2)*(x-4)');
disp(' , ');
function[x,y,mas1x,mas1y,xleft,xright,nn]=ObrShag1()
disp(' ')
disp(' ')
disp('y=(x+2)*(x-4)')
%
disp(' ')
xleft=input(' ');
xright=input(' ');
choice=input(' ? =1 =0');
if choice==0
eps=input(' :');
else
yeps=input(' :');
end
%
dx1=(xright-xleft)/100;
if choice==1
dx2=dx1;
else
dx2=eps*10;
end
if dx1<dx2
dx=dx1;
else
dx=dx2;
end
nn=1;
%
n=1;
masx(1)=xleft;
masy(1)=f(masx(1));
TheEnd=0;
while TheEnd==0
n=n+1;
masx(n)=masx(n-1)+dx;
masy(n)=f(masx(n));
string=strcat(:,num2str(masx(n)), :,num2str(masy(n)));
disp(string);
%
mas1x(nn)=masx(n);
mas1y(nn)=masy(n);
nn=nn+1;
% ,
if masx(n)>xright
disp( );
break;
end
%
if choice==1
if abs(masy(n)-masy(n-1))<yeps
TheEnd=1;
disp(yeps);
end
else
if abs(masx(n)-masx(n-1))<eps
TheEnd=1;
disp('xeps');
end
end
% ,
if masy(n)>masy(n-1)
%
dx=-dx/2
masx(1)=masx(n);
masy(1)=masy(n);
n=1;
end
end % while
%
x=masx(n);
y=masy(n);
nn=nn-1;
end
%
[x,y,mas1x,mas1y,xleft,xright,nn]=ObrShag1();
%
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),' ( ):',num2str(abs(mas1x(nn)-mas1x(nn-1))));
sy=strcat(' =',num2str(y),' ( ):,num2str(abs(mas1y(nn)-mas1y(nn-1))));
sn=strcat(:,num2str(nn), );
disp(sx); %
disp(sy);
disp(sn);
%
h=0.1;
x1=xleft:h:xright;
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,plot with your step,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.1
:-9.8 :107.64
:-9.6 :103.36
:-9.4 :99.16
:-9.2 :95.04
:-9 :91
:-8.8 :87.04
:-8.6 :83.16
:-8.4 :79.36
:-8.2 :75.64
:-8 :72
:-1.4 :-3.24
:-1.2 :-4.16
:-1 :-5
:-0.8 :-5.76
:-0.6 :-6.44
:-0.4 :-7.04
:-0.2 :-7.56
:-2.0539e-015 :-8
:0.2 :-8.36
:0.4 :-8.64
:0.6 :-8.84
:0.8 :-8.96
:1 :-9
yeps % ,
? =1 =0 1
? =1 =0 1
= 1 = -9.800 =107.640
= 2 = -9.600 =103.360
= 3 = -9.400 = 99.160
= 48 = -0.400 = -7.040
= 49 = -0.200 = -7.560
= 50 = -0.000 = -8.000
= 51 = 0.200 = -8.360
= 52 = 0.400 = -8.640
= 53 = 0.600 = -8.840
= 54 = 0.800 = -8.960
= 55 = 1.000 = -9.000
=1 ( ):0.2
=-9 ( ):0.04
|
|
:55
. 2.4.
: