MATLAB: How to solve to get temperature profile of T_go and T_pousing ode45 solver

MATLABsymbolicSymbolic Math Toolbox

A*(dT_go/dt)==(B*T_go)+(C*T_po)+(D*(T_po^4-T_go^4))——-(1)
E*(dT_po/dt)==(F*T_po)+(G*T_go)+(D*(T_go^4-T_po^4))——-(1)

Best Answer

% Write the system symbolic
syms A B C D E F G T_go(t) T_po(t)
eq(1) = A * diff(T_go,t) == (B*T_go)+(C*T_po)+(D*(T_po^4-T_go^4));
eq(2) = E * diff(T_po,t) == (F*T_po)+(G*T_go)+(D*(T_go^4-T_po^4));
% Get a function suitable for ode45
[V,S] = odeToVectorField(eq)
fun = matlabFunction(V,'Vars',{'t','Y','A','B','C','D','E','F','G'});
% cleanup
clearvars -except fun
%% solve ode numerical
tspan = [0 1];
y0 = [2 1]; % T_po(0)=2 and T_go(0)=1
A = 1;
B = 2;
C = 1;
D = 2;
E = 4;
F = 1;
G = 3;
[t,y] = ode45(@(t,Y)fun(t,Y,A,B,C,D,E,F,G),tspan,y0);
% plot results
plot(t,y)