From 59c61e58244ca112afe7e2caa107ae8e6b2d40e4 Mon Sep 17 00:00:00 2001 From: Christos Choutouridis Date: Sun, 3 Nov 2024 20:23:20 +0200 Subject: [PATCH] Add fixed epsilon and lambda variations for bisection method --- Work 1/scripts/bisection_epsilonFixed.m | 47 +++++++++++++++++++ ...A_lamdaFixed.m => bisection_lambdaFixed.m} | 6 +-- 2 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 Work 1/scripts/bisection_epsilonFixed.m rename Work 1/scripts/{bisectionA_lamdaFixed.m => bisection_lambdaFixed.m} (83%) diff --git a/Work 1/scripts/bisection_epsilonFixed.m b/Work 1/scripts/bisection_epsilonFixed.m new file mode 100644 index 0000000..2b93e8c --- /dev/null +++ b/Work 1/scripts/bisection_epsilonFixed.m @@ -0,0 +1,47 @@ +% +% Keeping epsilon fixed, test the iteration needed for different lambda +% values. +% + + +% Clear workspace and load the functions and region +clear + +funGivenEnv; + +% * 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 + +size = 25; +epsilon = 0.001; +dl = 0.0001; +lambda_max= 0.1; +lambda = linspace(2*epsilon + dl, lambda_max, size); +k = zeros(1,size); + + +% +% * Call the bisection method for each lambda value for each function and +% 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); + end + subplot(1, 3, i) + plot(lambda, k, '-b', 'LineWidth', 1.0) + title(titles(i), 'Interpreter', 'latex') + xlabel('lambda') + ylabel('Iterations') +end + + \ No newline at end of file diff --git a/Work 1/scripts/bisectionA_lamdaFixed.m b/Work 1/scripts/bisection_lambdaFixed.m similarity index 83% rename from Work 1/scripts/bisectionA_lamdaFixed.m rename to Work 1/scripts/bisection_lambdaFixed.m index 3caa575..28d98ab 100644 --- a/Work 1/scripts/bisectionA_lamdaFixed.m +++ b/Work 1/scripts/bisection_lambdaFixed.m @@ -1,6 +1,6 @@ % -% Keeping l (accuracy) fix, test the iteration needed for different e -% values. +% Keeping l (accuracy) fixed, test the iteration needed for different +% epsilon values. % @@ -25,7 +25,7 @@ k = zeros(1,size); % % * Call the bisection method for each epsilon value for each function and % keep the number of iterations needed. -% * Plot the (epsilon, iterations) for each function +% * Plot the iterations k(epsilon) for each function % i = 0; for f = funs