syms c1 c2 c3 x

% Bazisne funkcije
phi0 = 1-x; phi1 = x*(1-x); phi2 = x^2*(1-x);

% Priblizno resenje
v = phi0 + c1*phi1 + c2*phi2;

% Greska
R = diff(v, 2) + x*diff(v, 1) + v - 2*x;

% Galerkinova metoda
[c1g, c2g] = solve(int(R*phi1, 0, 1), int(R*phi2, 0, 1))

% Kolokacija
[c1k, c2k] = solve(subs(R, x, 0), subs(R, x, 1)) 

% Najmanji kvadrati
[c1ls, c2ls] = solve(int(R*diff(R, c1), 0, 1), int(R*diff(R, c2), 0, 1)) 

% Zamenjujemo simbolicke promenljive c1 i c2 pronadjenim
% resenjima sistema
vg = subs(v, {c1, c2}, {c1s, c2s});
vk = subs(v, {c1, c2}, {c1k, c2k});
vls = subs(v, {c1, c2}, {c1ls, c2ls});

% Uproscavamo i ispisujemo rezultate
pretty(simplify(vg))
pretty(simplify(vk))
pretty(simplify(vls))
