() ( ) (). [x, y]=fminbnd(name, a, b, options). :
name -,
a, b ,
options ,
x, y .
, name . , y(x)=x4-0.5x3-28x2+140
, , -4 -2.
[x,y]=fminbnd(@ext,-4,-2), @ext - .
-6 6, @ext, @ext_2, y(x) , y(x)=-(x4-0.5x3-28x2+140). .
, () , .
.
z=f(x1, x2, , xn) [X,Z]=fminsearch(name, x0, options) :
name - z=f(x1, x2, , xn),
0 n , ,
options ,
n , , z=f(x1, x2, , xn) ,
Z .
, [X, Z]=fminsearch(@extr, [3 2]); @extr - extr, z=x12+x22-6x2-2x1+11, [3 2] 1 2 . .
2. MATLAB
(, ) , , , ( , ) , .
(, ) , , , , .
, , . , (, ) , . ( ) , ( ), , .
|
|
, .
, , , . , , , . , .
, .
, .
Function[]=Scanirovanie1D_030809();
%
function y=f(x)
%
% ,
%
y=(x+2).*(x-4); % * .
% ;
%
end
% :
disp(' ');
% disp , ,
disp(' : y=(x+2)*(x-4)');
disp(' , ');
function[x,y,masx,masy,xleft,xright,n]=scan1();
% .
disp(' c ')
disp(' ')
disp('y=(x+2)*(x-4)')
% , :
%
disp(' ')
xleft=input(' ');
xright=input(' ');
h=input(' ');
%
n=ceil(abs((xright-xleft)/h)); %
% ceil
masx(1)=xleft;
masy(1)=f(xleft);
disp(' ');
for i=2:n
masx(i)=masx(i-1)+h;
masy(i)=f(masx(i));
end
%
for i=1:n
string=strcat( :,int2str(i), :,num2str(masx(i)), :,num2str(masy(i));
disp(string);
% string , strcat , , , int2str(i) , ( )
end
%
min=masy(1); %
num=1;
for i=2:n
if masy(i)<min
min=masy(i);
num=i;
end
end
% ()
x=masx(num);
y=masy(num);
end
%
[x,y,masx,masy,xleft,xright,n]=scan1();
%
|
|
choiceTab=input(' ? =1 =0 ');
choiceGraf=input(' ? =1 =0 ');
%
if choiceTab==1 %
disp(' ');
for i=1:n
%string=strcat(=,int2str(i), =,num2str(masx(i)), =,num2str(masy(i)));
%disp(string);
string=sprint(= %4i\t= %7.3f\t= %7.3f,i,masx(i),masy(i));
% %4i 4- : \t
% %7.3f : 7 , 3 : \t
disp(string);
end
end
%
% num2str
disp(' ')
sx=strcat(' =',num2str(x),' :',num2str(abs(masx(n)-masx(n-1))));
% sx ( ). x
sy=strcat(' =',num2str(y),' :',num2str(abs(masy(n)-masy(n-1)));
sn=strcat(':',num2str(n),' ');
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'); % x
ylabel('Y'); % y
text(x,y,\leftarrow Minimum);
zeroMas=x1*0;
hold on;
if choiceGraf==1
plot(masx,masy,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)
,
c
y=(x+2)*(x-4)
-10
10
.5
:1 :-10 :112
:2 :-9.5 :101.25
:3 :-9 :91
:4 :-8.5 :81.25
:15 :-3 :7
:16 :-2.5 :3.25
:17 :-2 :0
:18 :-1.5 :-2.75
:19 :-1 :-5
:20 :-0.5 :-6.75
:21 :0 :-8
:22 :0.5 :-8.75
:23 :1 :-9
:24 :1.5 :-8.75
:25 :2 :-8
:26 :2.5 :-6.75
:27 :3 :-5
:36 :7.5 :33.25
:37 :8 :40
:38 :8.5 :47.25
:39 :9 :55
:40 :9.5 :63.25
? =1 =0 0
? =1 =0 1
=1 :0.5
=-9 :0.25
:40
. 2.1.
.
|
|
Fn = Fn 1 + Fn 2; F 0 = 1.
( ) :
1) Δ, Δ = (X max X min)/ Fs , Fs s, : N = (X max X min)/Δ;
2) Fs, :
Fs 1 < N ≤ Fs;
3) :
h min= (X max X min)/ Fs;
4) R , X 1 = X min + h min Fs 2;
5) R , X 2 = X 1 + h min Fs 3;
6) R (X 2) < R (X 1), X 3 = X 2 + h min Fs 4.
3 = X 1 h min Fs 4 R.
, .
, .
Function[]=FibonachiChisla1D_170809();
%
function y=f(x);
%
% ,
% - y=(x+2).*(x-4);
% * .
% ;
%
end
% :
disp(' ');
disp(' : y=(x+2)*(x-4)');
disp(' , ');
function [x,y,masx,masy,xleft,xright,dy]=Fib1();
%
disp( ')
disp( ')
disp('y=(x+2)*(x-4)')
disp (' , )
eps=input(' =');
xleft=input(' =');
xright=input(' =');
F(1)=1;
F(2)=2;
s=2;
N=abs(xright-xleft)/eps;
%
while N>F(s)
s=s+1;
F(s)=F(s-1)+F(s-2);
end % while
%
disp(' ');
for i=1:s
string=strcat( :,int2str(i), :,int2str(F(i)));
disp(string);
end
disp( ͒);
h=(xright-xleft)/F(s);
x1=xleft+h*F(s-2);
R1=f(x1); % y=f(x)
x2=x1+h*F(s-3);
R2=f(x2); % y=f(x)
k=s-3;
x3=0;
n=1;
disp(' ');
while k>1 %
k=k-1;
if R2<R1
x3=x2+h*F(k);
else
x3=x1-h*F(k);
end % if
%
x1=x2;
R1=R2;
x2=x3;
R2=f(x3);
masx(n)=x3;
masy(n)=R2;
n=n+1;
%
string=strcat(' :',int2str(k),' :',num2str(x3),' :',num2str(R2));
disp(string);
end % while
n=n-1;
%
x=x3;
y=R2;
dy=abs(y-masy(n-1));
end %
% ( )
[x,y,masx,masy,xleft,xright,dy]=Fib1();
%
choiceTab=input(' ? =1 =0 ');
choiceGraf=input(' ? =1 =0 ');
|
|
%
if choiceTab==1
disp(' ');
for i=1:length(masx)
string=print(= %4i\t= %7.3f\t= %7.3f,i,masx(i),masy(i));
disp(string);
end
end
%
% num2str
disp(' ')
sx=strcat(' =',num2str(x));
sy=strcat(' =',num2str(y),' :',num2str(dy));
sn=strcat(':',num2str(length(masx)),' ');
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'); % x
ylabel('Y'); % y
string=strcat(\leftarrow Minimum (,num2str(x),,,num2str(y),));
text(x,y,string);
zeroMas=x1*0;
hold on;
if choiceGraf==1
plot(masx,masy,r.); %
legend(plot with minimal step,points by Fibonachi 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)
, , =0.01 =-10, =10
:1 :1
:2 :2
:3 :3
:4 :5
:5 :8
:6 :13
:7 :21
:8 :34
:9 :55
:10 :89
:11 :144
:12 :233
:13 :377
:14 :610
:15 :987
:16 :1597
:17 :2584
:13 :5.2786 :9.3067
:12 :0.55728 :-8.804
:11 :1.6718 :-8.5486
:3 :0.99845 :-9
:2 :1.0139 :-8.9998
:1 :0.99071 :-8.9999
? =1 =0 1
? =1 =0 1
= 1 = 5.279 = 9.307
= 2 = 0.557 = -8.804
= 3 = 1.672 = -8.549
= 4 = -0.132 = -7.720
= 5 = 1.246 = -8.939
= 6 = 1.509 = -8.741
= 7 = 1.084 = -8.993
= 8 = 1.184 = -8.966
= 9 = 1.022 = -9.000
= 10 = 1.060 = -8.996
= 11 = 0.998 = -9.000
= 12 = 1.014 = -9.000
= 13 = 0.991 = -9.000
=0.99071
=-8.9999 :0.00010783
:13
. 2.2.