diff --git a/algorithms/math/factorial_recursive.m b/algorithms/math/factorial_recursive.m new file mode 100644 index 0000000..38d4025 --- /dev/null +++ b/algorithms/math/factorial_recursive.m @@ -0,0 +1,7 @@ +function result = factorial_recursive(n) + if n == 0 || n == 1 + result = 1; + else + result = n * factorial_recursive(n - 1); + end +end diff --git a/algorithms/math/fftshift1.m b/algorithms/math/fftshift1.m new file mode 100644 index 0000000..0d0e161 --- /dev/null +++ b/algorithms/math/fftshift1.m @@ -0,0 +1,18 @@ +I = magic(10); % Sample input + +[rows, cols] = size(I); +mid_row = ceil(rows / 2); +mid_col = ceil(cols / 2); + +% Rearrange the image pixels to shift the center +top_left = I(mid_row+1:end, mid_col+1:end); +top_right = I(mid_row+1:end, 1:mid_col); +bottom_left = I(1:mid_row, mid_col+1:end); +bottom_right = I(1:mid_row, 1:mid_col); + +shifted_image = [top_left, top_right; bottom_left, bottom_right]; + +% Display the original and shifted images +figure("Name","FFTShift"); +subplot(1, 2, 1), imshow(I, []), title('Original Image'); +subplot(1, 2, 2), imshow(shifted_image, []), title('Shifted Image'); \ No newline at end of file diff --git a/algorithms/searching/linearSearch.m b/algorithms/searching/linearSearch.m new file mode 100644 index 0000000..558986e --- /dev/null +++ b/algorithms/searching/linearSearch.m @@ -0,0 +1,11 @@ +% Linear search function +function index = linearSearch(array, target) + index = -1; % Initialize index to -1 (not found) + + for i = 1:length(array) + if array(i) == target + index = i; % Target found at index i + break; % Exit the loop + end + end +end