.
[1,2]. .
(2):
(4)
(script ):
e = 1e-04; %
xk = 1.5; %
I = 0; % I
delta = xk;
while abs(delta) > e %
xk_plus_1 = 0.4 + atan(sqrt(xk)); %
delta = xk_plus_1 - xk; %
xk = xk_plus_1; %
I = I+1;
end;
Str = [' : ' num2str(xk) ];
disp(Str)
Str = [': ' num2str(delta) ];
disp(Str)
Str = [' : ' num2str(I) ];
disp(Str)
1.5 ( 10-4):
>> : 1.2389
: -5.971e-005
: 6
(, ). , . , , ( , : , ). . :
e = 1e-04; %
dx = 0.1; % ,
a = 1;
b = a;
while f(a)*f(b) > 0 % ,
b = b + dx; % F(x)
end;
a = b - dx;
x = (a+b)/2; % -
%
I = 1; % "1"
X=[x]; %
Y=[f(x)];
while abs(f(x)) > e
if f(x) * f(a) < 0 %
% ,
b = x; %
else
a = x; %
end;
x = (a+b)/2; %
I = I + 1; % 1
X = [X x];
Y = [Y f(x)];
end;
Str = [' : ' num2str(x) '; : ' num2str(I)];
disp(Str)
figure %
subplot(2, 1, 1);
plot(X, '-r'), grid on
subplot(2, 1, 2);
plot(Y, '-b'), grid on
-, :
function [ y ] = f (x)
y = 0.4 + atan(sqrt(x)) - x;
f, , , f.m, x, y. , .
|
|
:
>> : 1.2389; : 9
, . ( ).
( , ).
, . :
.
, . :
.
:
. 1. (script-):
%
% F(x)=0
% F(x)=(4x^2+1)^(1/2)+(4x^2+1)^(1/4)-12
% F'(x)=2x(2(4x^2+1)^(-1/2)+(4x^2+1)^(-3/4))
% : sqrt(20) -sqrt(20)
%
% = 1
e = 1e-08; %
x_k = 1; %
I = 0; % I
delta = x_k;
D = [ delta ];
while abs(delta) > e %
xk_plus_1 = x_k - fun(x_k) / fun1(x_k); %
delta = xk_plus_1 - x_k; %
D = [ D delta ];
x_k = xk_plus_1; % ,
I = I+1;
end;
Str = [' : ' num2str(x_k) ];
disp(Str)
Str = [': ' num2str(delta) ];
disp(Str)
Str = [' : ' num2str(I) ];
disp(Str)
plot(D)
, : ( , ). :
function [ y ] = fun (x)
y = (4*x^2+1)^(1/2)+(4*x^2+1)^(1/4)-12;
function [ y1 ] = fun1(x)
y1 = 2*x*(2*(4*x^2+1)^(-1/2)+(4*x^2+1)^(-3/4));
:
>> : 4.4721
: 1.7764e-015
: 4
(, ):
, MatLab fzero, , . :
>> x0=1;
>> x=fzero('fun', x0)
:
>> x =
4.4721
. ( fum.m), fplot (, ). :
|
|
>> fplot('fun', [-6 6]);
:
. Matlab ( Symbolic Math).
() , , , . , , .
. .
. , , , :
% ( )
% F(x)
syms x; % ()
% F(x)
f = sin(log(x)) - cos(log(x)) + 2*log(x);
f1 = diff(f); % F'(x)
% Matlab diff ( )
% Matlab diff
%
% diff ,
% , diff(f, 2)
ezplot(f), grid on, pause %
% .
% pause ,
%
% .
% L ,
% , Enter
x0 = input(' x0: ') %
%
% input
%
err = 1e-05; %
delta = x0; %
X = [ x0 ]; %
%
n = 1; %
N = [ n ]; %
%
%
while abs(delta) > err %
%
x1 = x0 - subs(f, x, x0) / subs(f1, x, x0); %
% .
% SUBS
% 0
%
delta = x1 - x0; %
x0 = x1; %
X = [X x1]; %
n = n+1; %
N = [N n]; % N
end;
str_out = 'x = '; %
res = num2str(x1);
str_out = strcat(str_out, ' ', res);
disp(str_out); %
plot(N, X, 'Linewidth', 3, 'Color', [0 1 0]), grid on %
%
.
, , 1 2. , , , 3, .
|
|
. , . 1.3749.
, , , . , ( ) Matlab . , ( , ). , fzero.
, , (, , ).