MATLAB: I am trying to solve a 2nd order non linear differntial equation with 2 boundary conditions . Please help me write the code.

#radiative finnon linear differential equation

the differential equation is : – m * () = 0
boundary conditions are : 1st : at x=0 , T=Tb;
2nd: at x=L , at x=L
T is function of x only and m , k , L , To , h ,Tb are constants.

Best Answer

Here's one way of doing this (obviously, you need to replace my arbitrary constants with your proper values):
% Data (replace with your own values)
m = 10^-10;
k = 1;
h = 1;
L = 1;
To = 300;
Tb = 500;
dTdx0 = -100; % Initial guess for gradient at x = 0
% Use fzero to get best gradient at x = 0
% such that it produces right gradient at x = L
dTdx0 = fzero(@gradL,dTdx0,[],Tb,To,L,m,h,k);
% With best gradient at x = 0
% use ode45 to solve d^2T/dx^2 - m*(T^4 - To^4) = 0
IC = [Tb dTdx0];
xspan = [0 L];
[x, TT] = ode45(@fn,xspan,IC,[],m,To);
T = TT(:,1);
dTdx = TT(:,2);
% Compare gradient from T vs x at x = L with that from boundary condition
disp(' (1) ode (2) boundary condition')
disp([dTdx(end) -h*(T(end) - To)/k])
% Plot T vs x and dT/dx vs x')
subplot(2,1,1)
plot(x,T),grid
xlabel('x'),ylabel('T')
subplot(2,1,2)
plot(x,dTdx),grid
xlabel('x'),ylabel('dT/dx')
% Function gradL is called by fzero several times to solve the ode with different initial
% gradients (supplied by fzero) to find the gradient at x = L
function F = gradL(dTdx0,Tb,To,L,m,h,k)
IC = [Tb dTdx0];
xspan = [0 L];
[~, TT] = ode45(@fn,xspan,IC,[],m,To);
TL = TT(end,1);
dTdxL = TT(end,2);
gradL = -h*(TL - To)/k;
F = dTdxL - gradL;
end
% Function fn returns dTdx and d^2Tdx^2 when called by ode45
function dTTdx = fn(~,TT,m,To)
T = TT(1);
dTdx = TT(2);
dTTdx = [dTdx;
m*(T^4 - To^4)];
end