errors = zeros(1,12);
condnums = zeros(1,12);
h = zeros(1,12);
h2 = zeros(1,12);
for k=0:11
    n=10*2^k;
    err = (initmatrix(n)\sinusoidalforces(n)) - sinusoidalcorrect(n);
    errors(1,k+1) = abs(err(n));
    condnums(1,k+1) = condest(initmatrix(n), 2);
    h(1,k+1) = 2/n;
    h2(1,k+1)= 4/n^2;
end

figure;

subplot(1,2,1);
ax1 = plotyy(h, errors, h, h2, 'loglog', 'loglog');
title('Problem 5: Discretization Errors vs h^2, Sinuosoidal Pile');
xlabel('h (meters between discretization points)');
ylabel(ax1(1),'error at x=L (in meters)');
ylabel(ax1(2),'h^2');

subplot(1,2,2);
ax2 = plotyy(h, errors, h, condnums, 'loglog', 'loglog');
ylim(ax2(1), [1e-12, 1e+2]);
title('Problem 5: Discretization Errors vs Condition Number, Sinuosoidal Pile');
xlabel('h (meters between discretization points)');
ylabel(ax2(1),'error at x=L (in meters)');
ylabel(ax2(2),'condition number');