%%% Aufstellen der Matrix A %%%%%%%%%%%%%%%%
A = zeros(3,3);
for i=1:3
for j=1:3
f = @(x) phi(x,i) .* phi(x,j);
A(i,j) = integral(f,0,1);
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Aufstellen des Vektors w %%%%%%%%%%%%%%%%
u = @(x) 24 .* ( x.^2 );
w=zeros(3,1);
for i=1:3
f = @(x) phi(x,i).* u(x);
w(i) = integral(f,0,1);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% Projektion %%%%%%%%%%%%%%%%%%%%%%%%%%%%
v = A \ w
p = @(x) ( v(1) .* phi(x,1) + v(2) .* phi(x,2) + v(3).* phi(x,3) );
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% Plot %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
hold on
fplot(p,[0,1])
fplot(u,[0,1])
for i=1:3
f = @(x) phi(x,i);
fplot(f,[0,1]);
end
hold off
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%