# Solving ODE using discretization and Euler's method

22 views (last 30 days)
Abdulrahman Odhah on 15 Jan 2021
Edited: Abdulrahman Odhah on 15 Jan 2021
Hello there,
I have solved a PDE for a tank with heater using Euler's method as per the code below, I believe it is true and I got the expected results.
% mm model for the tank with heater
% Given
v_tank=2;%1 L
%v_in=1;v_out=1; 1liter / minute
v_in=0.0166667;v_out=1; %1liter / sec
T1in0=15;% 15 c degrees at t =0
%rho=1000; density kg/m^3
rho=1;%density kg/L
CS=4200;%J/kg*c
%assumption of integration step h=0.1
h=0.1;
T10=(T1in0+(p/(v_in*rho*CS))); %f(x,y) function, where dy/dx=f(x,y), x(x0)=y0.
n=1500;
T1in=T1in0;
Tvect=ones(n/h);
i=1;
for t=0:h:n
if t>=300
T1in=20;% 20 c degrees at t=5
end
if t>=900
p=1500;% 1500 watt at t=15
end
%Eurl's integral equation
T=T10+h*((v_in/v_tank)*(T1in-T10)+(p/(v_tank*rho*CS)));
T10=T;
Tvect(i)=T10;
i=i+1;
end
hold on;
t=(0.1:0.1:n);
plot(t,Tvect)
%axis([0,25,0,25])
grid on;
title('Tank with heater'); xlabel('Time [sec]'); ylabel('Temp ℃ ');
But now the second step is to solve PDE using the discretization and then Euler's method, the concept is quit clear, which is having two loops one for space discretization and the other for time (Euler's method) but I am stuck at this point. It should be two for loops (discretization loops) inside one loop (time loop). I am confused to how set the equations up inside the loops. The set of equations are attached and this is my try, it should look something like this
%time loop
for
%space loop to find ds value
for
end
%space loop to find the S value
for
end
end ### Categories

Find more on Ordinary Differential Equations in Help Center and File Exchange

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!