Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

in Wire Problemm 3 of 4 A thin wire with a uniform cross-section will radiate he

ID: 3402662 • Letter: I

Question

in Wire Problemm 3 of 4 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 d T where k is the thermal diffusivity, h is the thermal conductivity of the interface be- tween the object and the environment, and Te is the temperature of the environ- We can approximate the second derivative using a "central difference formula If we apply this to a series of points in the wire, we can write down a series of equations of the form N+1 Suppose that we require that T(0) = 0 and T(1) 0, That is, the temperature at both ends is held at 0° C. We can let d = 1/N, and this allows us to write down the matrix equation Ti T2 Ts hT. hTe hT. hT. hT. hT. hT. where a = h + 2kN2 and b =-kN2. Your task is to write a MATLAB function that will do the following Take in N, k, h, and Te 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 r

Explanation / Answer

function u = heat(k, x, t, init, bdry)

% solve the 1D heat equation on the rectangle described by

% vectors x and t with u(x, t(1)) = init and Dirichlet boundary

% conditions u(x(1), t) = bdry(1), u(x(end), t) = bdry(2).

J = length(x);

N = length(t);

dx = mean(diff(x));

dt = mean(diff(t));

s = k*dt/dx^2;

u = zeros(N,J);

u(1, :) = init;

for n = 1:N-1

u(n+1, 2:J-1) = s*(u(n, 3:J) + u(n, 1:J-2)) + (1 - 2*s)*u(n, 2:J-1);

u(n+1, 1) = bdry(1);

u(n+1, J) = bdry(2);

end

plot (t,x)

The function heat takes as inputs the value of k, vectors of t and x values, a vector init of initial values (which is assumed to have the same length as x), and a vector bdry containing a pair of boundary values. Its output is a matrix of u values. Notice that since indices of arrays in MATLAB must start at 1, not 0, we have deviated slightly from our earlier notation by letting n=1 represent the initial time and j=1 represent the left endpoint. Notice also that in the first line following the for statement, we compute an entire row of u, except for the first and last values, in one line; each term is a vector of length J-2, with the index jincreased by 1 in the term u(n,3:J) and decreased by 1 in the term u(n,1:J-2).