% Galerkin method and Exact Solution- Final Question 1a

clear all;
clc;

syms x T T0 L c2 p h A T_inf k
N1 = x*(x-2*L);
T = T0+ c2*N1;

R = k*diff(diff(T))-(p*h/A)*(T-T_inf);

e1 = int(N1*R,0,L);

d = 1e-3; L = 50e-3; T_inf = 30; h = 20; k = 200; T0 = 300;
A = pi*d^2/4; p = pi*d; m = sqrt(h*p/k/A);
a = solve(e1, c2);
c2 =eval(a);

y = [0 10 20 30 40 50]*10^-3;

for i = 1:6
    x = y(i);
    Temp(i) = eval(T);
    Temp_ex(i) = T_inf+(T0-T_inf)/cosh(m*L)*cosh(m*(L-x));
end

plot(y,Temp_ex,'s--', y, Temp,'o-');
xlabel('x(m)'); ylabel('Temperature (deg C)');
legend('Exact Solution', 'Galerkin Method');
% legend on;
hold on;