Skip to content

Instantly share code, notes, and snippets.

View SeroviICAI's full-sized avatar
📚
programming and studying

Sergio Rodríguez Vidal SeroviICAI

📚
programming and studying
  • ICAI School of Engineering
  • Madrid, Spain
  • 06:52 (UTC +02:00)
View GitHub Profile
@SeroviICAI
SeroviICAI / cubic_spline_interp.m
Created February 24, 2023 09:08
This is a MATLAB function for computing and plotting a cubic spline interpolation given a set of input data points. Additionally, "zoom_image" is another function that takes an image file path and a zoom factor as input, and outputs a zoomed version of the image, using cubic spline interpolation.
function [s] = cubic_spline_interp(X, Y, options)
arguments
X (1,:) {mustBeVector}
Y (1,:) {mustBeVector}
options.Plotting (1, 1) string = 'False'
end
% Calculation of differences between consecutive x-coordinates.
n = length(X);
h = zeros(n-1, 1);
@SeroviICAI
SeroviICAI / naive_bayes.py
Created February 24, 2023 08:48
Multinomial Naive Bayes classifier for text data with example on use.
import numpy as np
__all__ = ["MultinomialNaiveBayes"]
class MultinomialNaiveBayes:
"""
Multinomial Naive Bayes classifier for text data.
Parameters:
@SeroviICAI
SeroviICAI / miller_test.py
Last active February 7, 2023 09:01
This is a python function that uses the Miller test to determine if a given number is prime or not. The function is deterministic and it checks if the given number is 2 or 3, less than 2, even, a multiple of 3, or less than 9. If the number satisfies any of these conditions, the function returns False. If not, the function uses the Miller test t…
import math
def miller_test(n: int) -> bool:
"""
Check if a number is a prime (Miller Test). This algorithm is deterministic.
:param n: integer to check
:return: True if n is a prime, False otherwise
"""
@SeroviICAI
SeroviICAI / decimal_to_IEEE754.m
Last active February 7, 2023 08:24
The function "decimal_to_IEEE754" is a Matlab function that converts a decimal number to its equivalent representation in the IEEE 754 format (double precision). It takes in one input, the decimal number to be converted, and returns the converted number as a string. The function first determines the sign bit of the number (0 for positive and 1 f…
function output = decimal_to_IEEE754(decimal)
% Given a decimal number, this function returns the exact same number in
% IEEE754 format (double precision)
% decimal: Decimal number to be converted
% output: Converted number (string)
% Get the sign bit (0 for positive, 1 for negative)
sign = 0;
if decimal < 0
sign = 1;
@SeroviICAI
SeroviICAI / newton_interpolation.m
Last active February 7, 2023 08:18
The function newton_interpolation takes in two arrays x and y as inputs, which represent the x and y coordinates of a set of data points. It then calculates the Newton Interpolation Polynomial of these data points, and displays both the polynomial equation and the divided difference table. The polynomial equation is displayed as a character stri…
function p = newton_interpolation(x, y)
% Plots the Newton Interpolation Polynomial and the divided difference table.
% x - the x-coordinates of the data points
% y - the y-coordinates of the data points
% Number of data points
n = length(x);
% Divided difference table
F = divided_differences(x, y);