x = linspace(-1,1,201);
T = -50*exp(x) + 50*x*sinh(1) + 100 + 50*cosh(1);

phi1 = (1-x).*(1+x);
phi2 = x.*phi1;

% Collocation method
%K = [-2, 2; -2, -2];
%b = [-50*exp(-1/3); -50*exp(1/3)];

% MWR
K = [-8/3, 0; 0, -8/5];
b = [-200*exp(-1); -100*exp(1) + 700*exp(-1)];

% Find coefficients
a = K\b;

% Calculate Ta, error, and residual
Ta = 100 + a(1)*phi1 + a(2)*phi2;
E  = Ta - T;
R  = -2*a(1) - 6*a(2)*x + 50*exp(x);

% Plot everything
figure(1);
plot(x,Ta,'--');hold on;
plot(x,T); hold off;
grid on;
xlabel('x');

figure(2);
plot(x,E);
grid on;
xlabel('x');
ylabel('Error in T');

figure(3);
plot(x,R);
grid on;
xlabel('x');
ylabel('Residual');
