A thin wire with a uniform crosssection will radiate heat fr
A thin wire with a uniform cross-section will radiate heat from its sides according to Newtonian Cooling - that is, the rate of loss of heat is proportional to the difference in temperature between the object and its surroundings. If the temperature at every point in the wire remains constant, then it satisfies the second-order ODE kd^2t/dx^2 = h(T - T_e) where k is the thermal diffusivity, h is the thermal conductivity of the interface between the object and the environment, and T_e is the temperature of the environment. We can approximate the second derivative using a Prime central difference formula Prime: d^2T/dx^2_T(x + d) - 2T(x) + T(x - d)/d^2 If we apply this to a series of points in the wire, we can write down a series of equations of the form k T_n + 1 - 2 T_n + T_n + 1/d^2= h T_- h T_e Suppose that we require that T(0) = 0 and T(1) = 0. That is, the temperature at both ends is held at 0degree C. We can let d = 1/N, and this allows us to write down the matrix equation (a b 0 0 mldr 0 0 0 b a b 0 mldr 0 0 0 0 b a b mldr 0 0 0 0 0 b a mldr 0 0 0 0 0 0 0 mldr a b 0 0 0 0 0 0 0 0 mldr b a b 0 0 0 0 0 0 0 mldr 0 b a) (T_1 T_2 T_3 T_4 T_N - 3 T_N - 2 T_N - 1) = (hT_e hT_e hT_e hT_e hT_e hT_e hT_e) where a = h + 2KN^2 and b = -k N^2. Your task is to write a MATLAB function that will do the following: Take in N, k, h, and T_e as input variables, Generate the relevant matrices and/or vectors (see below), Solve the system (using chosen approach, see below), and Plot the resulting solution T against position x. This matrix system can be solved by Gaussian Elimination. When this is done, no zero value in the matrix will become non-zero. As such, we can store the values in this matrix in three vectors. Think of the matrix in this form: (D_1 U_1 0 0 mldr 0 0 0 L_2 D_2 U_2 0 mldr 0 0 0 0 L_3 D_3U_3 mldr 0 0 0 0 0 L_4 D_4 mldr0 0 0 0 0 0 0 mldrD_N - 3 U_N - 3 0 0 0 0 0 mldr L_N - 2 D_N-2 U_N - 2 0 0 0 0 mldr 0 L_N - 1 D_N -1) Express the matrix in the form of the three vectors (L, D, and U), and perform the appropriate operations on those three vectors (plus the b vector). Note that L_1can be taken to be zero, as can U_N - 1 The vectors will be length N - 1.
Solution
Matlab Code
function [ Temperature ] = Untitled( N,k,h,Te )
a = h+2*k*N^2;
b = -k*N^2;
A = zeros(N);
for i=1:length(A)
for j=1:length(A)
A(i,i) = a;
if(j==(i-1))
A(i,j)=b;
A(j,i)=b;
end
end
end
for i=1:N
B(i,1)=h*Te;
end
temperature = A\\B;
end
