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

please solve problem 24.9 by using matlab only thanks An insulated heated rod wi

ID: 3781842 • Letter: P

Question

please solve problem 24.9 by using matlab only thanks

An insulated heated rod with a uniform heat source can be modeled with the Poisson equation: d^2 T/dx^2 = -f(x) Given a heat source f(x) = 25 degree C/m^2 and the boundary conditions T(x =0) = 40 degree C and T(x = 10) = 200 degree C, solve for the temperature distribution with the shooting method and the finite-difference method (Delta x = 2). Repeat Prob. 24.8, but for the following spatially varying heat source: f(x) = 0.12x^3 - 2.4x^2 + 12x.

Explanation / Answer

Matlab CODE For Shooting method using Euler method for solving IVP

clc;clear;
N = 10;
xini = 0; xend = 10;
x = linspace(xini,xend,N);
h = x(2)-x(1);
G = [100 150; 0 0];
u1 = zeros(1,N);
u2 = zeros(1,N);
u1(1) =40;r = 200;
ext =1;
while ext
% for ext = 1:4
    if(ext <3)
        u2(1) = G(1,ext);
    else
        u2(1) = G(1,2) - (G(1,2)-G(1,1))*(G(2,2)-r)/(G(2,2)-G(2,1));
    end
    for i = 2:N
        u1(i)=u1(i-1)+u2(i-1)*h;
        u2(i)=u2(i-1)+u2(i-1)+(-0.12*x(i-1)^3+2.4*x(i-1)^2-12*x(i-1))*h;
    end
    if(ext <3)
        G(2,ext) = u1(N);
    else
        G(:,1) = G(:,2);
        G(:,2) = [u2(1);u1(N)];
    end
    if(abs(u1(N)-r)<10^-5)
        ext = 0;
    else
        ext = ext+1;
    end
end

Value in u1

>> u1

u1 =

Columns 1 through 9

   40.0000   48.2272   64.6816   84.5842 104.4739 122.3053 137.6460 152.0697 169.9432

Column 10

200.0000

FINITE DIFF

xini = 0; xend = 10;
h =2;
x = xini:h:xend;
N = length(x);
u = [40 zeros(1,N-2) 200];
f = @(x) 0.12*x.^3-2.4*x.^2+12*x;
A = diag(-2*ones(1,N-2),0)+diag(ones(1,N-3),-1)+diag(ones(1,N-3),1);
b = -1* h^2*f(x(2:N-1));
b(1) = b(1)-u(1);
b(N-2) = b(N-2)-u(N);
u(2:N-1) = A';% Solution

Solution in u

>> u

u =

   40.0000 184.1280 266.8160 280.3840 247.8720 200.0000