
clear all;
close all;
format long;

L = 1;
A = 1e-4;
E1 = 7e10;
b = 100;
Fbar = 100;

c1 = (Fbar + b*L)/A;
c2 = -1;

for j = 1:8
    filename = sprintf('mesh%d.txt',j);
    data = load(filename);
    clear uexact;
    n = size(data,1);
    elemsize(j) = data(2,1) - data(1,1);
    uexact = zeros(n,1);
    for i = 1:n
        x = data(i,1);
        uexact(i) = -b/(A*E1)*(x*log(1+x) - (1+x)*log(1+x) + (1+x) + c2) + c1/E1*log(1+x);
    end
    e(j) = norm(uexact-data(:,2))/norm(uexact);
end

plot1 = figure();
plot(data(:,1),data(:,2),'ro');
hold on;
plot(data(:,1),uexact);
legend('fem solution','exact solution',...
       'Location','best');

plot2 = figure();
plot(elemsize,e,'b-o');
xlabel('element size');
ylabel('error between exact and FE solutions');
title('error versus element size');

