function prikladGalerkinovyMetody()

% -k*u''(x) = f v (0,1)
%      u(0) = 0
%   k*u'(1) = tau

k = 1; f = 2; tau = 0; %3;
beta = -2*(1+tau/f);
upresne = @(x) ((-0.5*f/k).*x.*(x+beta));

x = linspace(0,1,100);
u = upresne(x);
plot(x,u); pause

A = k*[1,1;1,4/3];
b = f*[1/2;1/3] + [tau;tau];
alfa = A\b;

hold on
plot(x,alfa(1)*x+alfa(2)*x.^2,'r')
pause


syms t

for n = 1:10
    n
    A = zeros(n,n); b = zeros(n,1);
    for i=1:n
        for j=1:n
            A(i,j) = k * int(i*cos(i*t)*j*cos(j*t),t,0,1);
        end
        b(i) = f * int(sin(i*t),t,0,1) + tau*sin(i);
    end
    alfa = A\b;
    
    hold on
    un = 0*x;
    for j=1:n
        un = un + alfa(j) * sin(j*x);
    end

    close all
    plot(x,upresne(x),'r',x,un,'k')
    pause
end