# prenesi file https://gml.noaa.gov/webdata/ccgg/trends/co2/co2_mm_mlo.txt
# to so vaje 2026-01-08
podatki = load("co2_mm_mlo.txt");
# podatki(:,[3,4])
A = zeros(height(podatki), 4);
A(:, 1) = podatki(:, 3);
A(:, 2) = ones(height(A), 1);
A(:, 3) = sin(2*pi*podatki(:, 3));
A(:, 4) = cos(2*pi*podatki(:, 3));
b = podatki(:, 4);
x = A\b;
F1 = @(t) x(1)*t+x(2)+x(3)*sin(2*pi*t)+x(4)*cos(2*pi*t)
A = zeros(height(podatki), 5);
A(:, 1) = podatki(:, 3).^2;
A(:, 2) = podatki(:, 3);
A(:, 3) = ones(height(A), 1);
A(:, 4) = sin(2*pi*podatki(:, 3));
A(:, 5) = cos(2*pi*podatki(:, 3));
x = A\b;
F2 = @(t) x(1)*t^2+x(2)*t+x(3)+x(4)*sin(2*pi*t)+x(5)*cos(2*pi*t)
F1(2050)
F2(2050)
F1(2100)
F2(2100)
hold on
plot(podatki(:, 3), podatki(:, 4), "red")
x = linspace(podatki(1, 3), podatki(height(podatki), 3), 1000);
plot(x, arrayfun(F1, x), "green")
plot(x, arrayfun(F2, x), "blue")
