Small changes
This commit is contained in:
parent
59c61e5824
commit
93cf747abd
@ -4,12 +4,10 @@ a_0 = -1;
|
||||
b_0 = 3;
|
||||
|
||||
% Setup the functions under test
|
||||
syms x;
|
||||
|
||||
f_1 = (x-2)^2 + x*log(x+3);
|
||||
f_2 = exp(-2*x) + (x-2)^2;
|
||||
f_3 = exp(x)*(x^3 - 1) + (x-1)*sin(x);
|
||||
funs = [f_1, f_2, f_3];
|
||||
f_1 = @(x) (x-2)^2 + x*log(x+3);
|
||||
f_2 = @(x) exp(-2*x) + (x-2)^2;
|
||||
f_3 = @(x) exp(x)*(x^3 - 1) + (x-1)*sin(x);
|
||||
funs = {f_1, f_2, f_3};
|
||||
|
||||
% Setup the function titles
|
||||
title_f1 = "$f_1(x) = (x - 2)^2 + x \cdot \ln(x + 3)$";
|
@ -23,7 +23,7 @@ while b(k) - a(k) > lambda
|
||||
|
||||
% set new search reange
|
||||
k = k + 1;
|
||||
if subs(fun, x_1) < subs(fun, x_2)
|
||||
if fun(x_1) < fun(x_2)
|
||||
a(k) = a(k-1);
|
||||
b(k) = x_2;
|
||||
else
|
||||
@ -31,4 +31,3 @@ while b(k) - a(k) > lambda
|
||||
b(k) = b(k-1);
|
||||
end
|
||||
end
|
||||
|
@ -6,22 +6,22 @@
|
||||
|
||||
% Clear workspace and load the functions and region
|
||||
clear
|
||||
|
||||
funGivenEnv;
|
||||
addpath('..');
|
||||
GivenEnv;
|
||||
|
||||
% * epsilon: e = 0.001
|
||||
% * lambda: l > 2e = 0.001
|
||||
% * dl: A small step away from 2e
|
||||
% dl = 0.0001
|
||||
% * lambda_max: 0.1
|
||||
% * size: 25 points
|
||||
% * N: 50 points
|
||||
|
||||
size = 25;
|
||||
N = 50;
|
||||
epsilon = 0.001;
|
||||
dl = 0.0001;
|
||||
lambda_max= 0.1;
|
||||
lambda = linspace(2*epsilon + dl, lambda_max, size);
|
||||
k = zeros(1,size);
|
||||
lambda = linspace(2*epsilon + dl, lambda_max, N);
|
||||
k = zeros(1, N); % preallocate k
|
||||
|
||||
|
||||
%
|
||||
@ -29,15 +29,12 @@ k = zeros(1,size);
|
||||
% keep the number of iterations needed.
|
||||
% * Plot the iterations k(lambda) for each function
|
||||
%
|
||||
i = 0;
|
||||
for f = funs
|
||||
i = i + 1;
|
||||
j = 0;
|
||||
for l = lambda
|
||||
j = j + 1;
|
||||
[a, b, k(j)] = bisection(f, a_0, b_0, epsilon, l);
|
||||
|
||||
for i = 1:length(funs)
|
||||
for j = 1:N
|
||||
[a, b, k(j)] = bisection(funs{i}, a_0, b_0, epsilon, lambda(j));
|
||||
end
|
||||
subplot(1, 3, i)
|
||||
subplot(1, length(funs), i)
|
||||
plot(lambda, k, '-b', 'LineWidth', 1.0)
|
||||
title(titles(i), 'Interpreter', 'latex')
|
||||
xlabel('lambda')
|
@ -6,20 +6,20 @@
|
||||
|
||||
% Clear workspace and load the functions and region
|
||||
clear
|
||||
|
||||
funGivenEnv;
|
||||
addpath('..');
|
||||
GivenEnv;
|
||||
|
||||
% * lambda = 0.01
|
||||
% * epsilon: e < lambda/2 = 0.005
|
||||
% * de: A small step away from zero and lambda/2
|
||||
% de = 0.0001
|
||||
% * size: 25 points
|
||||
% * N: 50 points
|
||||
|
||||
size = 25;
|
||||
N = 50;
|
||||
lambda = 0.01;
|
||||
de = 0.0001;
|
||||
epsilon = linspace(de, (lambda/2)-de, size);
|
||||
k = zeros(1,size);
|
||||
epsilon = linspace(de, (lambda/2)-de, N);
|
||||
k = zeros(1,N); % preallocate k
|
||||
|
||||
|
||||
%
|
||||
@ -27,15 +27,11 @@ k = zeros(1,size);
|
||||
% keep the number of iterations needed.
|
||||
% * Plot the iterations k(epsilon) for each function
|
||||
%
|
||||
i = 0;
|
||||
for f = funs
|
||||
i = i + 1;
|
||||
j = 0;
|
||||
for e = epsilon
|
||||
j = j + 1;
|
||||
[a, b, k(j)] = bisection(f, a_0, b_0, e, lambda);
|
||||
for i = 1:size(funs,2)
|
||||
for j = 1:N
|
||||
[a, b, k(j)] = bisection(funs{i}, a_0, b_0, epsilon(j), lambda);
|
||||
end
|
||||
subplot(1, 3, i)
|
||||
subplot(1, length(funs), i)
|
||||
plot(epsilon, k, '-b', 'LineWidth', 1.0)
|
||||
title(titles(i), 'Interpreter', 'latex')
|
||||
xlabel('epsilon')
|
Loading…
x
Reference in New Issue
Block a user