%% Konvergenstest för randvärdesproblem

clear all

N = 2.^(5:10);

% compute solutions
x = cell(size(N));
y = cell(size(N));
for k = 1:length(N)
	[x{k},y{k}] = rvp2(N(k));
end

% plot
figure(1)
plot(x{end},y{end});
title('y'''' = 4y - 50cos(4\pi x)');
xlabel('x')
ylabel('y')

% compare
q = N(end)./N;
for k = 1:length(N)-1
	exact = y{end}(1:q(k):end);
	err(k) = norm(y{k}-exact,'inf');
end
p = (log(err(2:end))-log(err(1:end-1)))./(log(N(2:end-1))-log(N(1:end-2)))
figure(2)
loglog(N(1:end-1),err,'.-');
grid on
xlabel('N')
ylabel('Error in max-norm')

