Skip to content

Instantly share code, notes, and snippets.

@caiorss
caiorss / gist:160d8090d946d22a9878d93ed81846ae
Created December 25, 2016 21:21 — forked from tausen/gist:1547052
MATLAB fourier series test
syms n t;
% Set d to the series, using symsum()
d=1+symsum(sin(n/2*t)*(sin(((n+2)*pi)/(2))*4/(pi^2*n^2)+(-1)^n*2/(n*pi)),n,1,100);
% Prep an x-axis
t=linspace(-10,10,1000);
% Evaluate the values accordingly
data=eval(d);
% And plot it
plot(t,data);
@caiorss
caiorss / gist:ec93dfe0c03f7c45d7cf929dc57c13d0
Created December 25, 2016 21:21 — forked from fbrosser/gist:1229329
Monte Carlo method MATLAB
function [answer] = montecarlo()
N = 100000;
M = 0;
for i = 1:N
x = rand-0.5;
y = rand-0.5;
M = M + (sqrt((x^2+y^2)) < 0.5);
end
@caiorss
caiorss / linear_regression.m
Created December 25, 2016 21:20 — forked from jcchurch/linear_regression.m
Linear Regression in Matlab
function [m b] = linear_regression(X, Y)
n = length(Y);
EX = sum(X);
EY = sum(Y);
EX2 = sum(X.*X);
EXY = sum(X.*Y);
m = (n*EXY - EX*EY) / (n*EX2 - EX*EX);
b = (EY - m*EX) / n;
end
@caiorss
caiorss / gaussSeidel.m
Created December 25, 2016 21:20
matlab_2_7
function [ x,iter ] = gauss_seidel(A,b,itermax,toll,x0)
%ESERCIZIO_2_7_F1 Summary of this function goes here
% Detailed explanation goes here
% [ x,iter ] = gauss_seidel(A,b,itermax,toll,xo)
%input:
% A->matrice sistema lineare ,
% b-> vettore termine noto,
% itermax -> numero massimo di iterazioni,
% toll-> tolleranza richiesta,
% x0 -> vettore soluzione iniziale
@caiorss
caiorss / base64.m
Created December 25, 2016 21:20 — forked from fbender/base64.m
Base64 for MATLAB
function b64 = base64( str )
%BASE64 Encode string (array of chars) into Base64
% Currently seems to fail for any input > 4 characters. :(
%% Settings
% Valid output codes to choose from.
base64Chars = char([65:90, 97:122, 48:57, 43, 47]); % +/ per RFC 2045 et al.
%base64UrlChars = char([65:90, 97:122, 48:57, 45, 95]); % -_ per RFC 4648 §4
base64PadChar = '=';
@caiorss
caiorss / plotFFT.m
Created December 25, 2016 21:18 — forked from dhda/plotFFT.m
Matlab FFT plotting function
function [f, X, peaks, locs] = plotFFT( t, x, p )
Fs = 1 / mean(abs(t(2:end) - t(1:end-1)));
%n = 2^nextpow2(length(x));
n = length(x);
X = fft(x-mean(x), n) / length(x);
f = 0.5*Fs * linspace(0, 1, ceil(0.5*n+1));
X = X(1:ceil(0.5*n+1));
mX = abs(X);
@caiorss
caiorss / fft_demo.m
Created December 25, 2016 21:17 — forked from morganp/fft_demo.m
Basic Matlab FFT
%% Trial FFT
% http://www.mathworks.co.uk/help/matlab/math/fast-fourier-transform-fft.html
fs = 48000; % Sample Rate
n = 4096; % Power of 2 number of samples/ length of FFT
% Get/Generate data
t = 0:1/fs:10-1/fs; % 10 sec sample
x = (1.3)*sin(2*pi*15*t) ... % 15 Hz component
+ (1.7)*sin(2*pi*40*(t-2)) ... % 40 Hz component
@caiorss
caiorss / .m
Created December 25, 2016 21:17 — forked from GiovanniBalestrieri/.m
Snippet - Basic Filter Matlab
% This scipt loads and plots data from a .mat file
clc
gxFdata = 0;
gyFdata = 0;
gzFdata = 0;
% Loads samples from file
dat = load('GyroSamples.mat');
dat = load('samples.mat');
@caiorss
caiorss / histograms.matlab
Created December 25, 2016 21:17 — forked from weinberz/histograms.matlab
Simple histograms in MATLAB
names = {}
x = hist(Lifetimes,[50 100 150 200 250 300 350 400])
for i = 1:size(x)
x(:,i) = x(:,i)./sum(x(:,i))
end
hist(Lifetimes,[50 100 150 200 250 300 350 400])
legend(names)
bins = [50 100 150 200 250 300 350 400];
figure()
[Stanford Machine Learning](https://www.class-central.com/mooc/835/coursera-machine-learning)
[Functional Programming in Scala](https://www.class-central.com/mooc/422/coursera-functional-programming-principles-in-scala)
[MIT Analytics Edge](https://www.class-central.com/mooc/1623/edx-15-071x-the-analytics-edge)
[Principles of Reactive Programming](https://www.class-central.com/mooc/1186/coursera-principles-of-reactive-programming)
[Stanford Algorithms Part 1](https://www.class-central.com/mooc/374/coursera-algorithms-design-and-analysis-part-1)