Solve ODE with function dependent parameters
Show older comments
Hi,
I consider my self a relative novice with MATLAB, but am trying to use it to solve a coupled heat and mass transfer problem using the method of lines, to model drying processes - I expect that as the solution progresses - the "crust" will have different propoerties to the "core" but this isn't happening.
IWhat I hoped would happed is that the physical property functions (which do vary significantly over the course of the solution), would be continuously re-evaluated during the course of the solution (eg varying as the solution progresses), but some basic diagnostics suggest that this is not the case - can you help me see where I'm going wrong?
Many Thanks
Simon
Extract from the ODE function that I'm solving using ode15s - the code runs d=fine, but the solution is suspect.
for i=n:-1:1
% Symmetry Boundary Conditions
if(i==1)
Tt(i) = 2*(T(i+1) - T(i)) * dx2; % HT Boundary condition at x=xl, central symmetry
CWat(i)= 2*(CWa(i+1) - CWa(i)) * dx2; % MT boundary condition free water at x=xl, central symmetry
% Surface Boundary Conditions
elseif(i==n) % add sorption isotherm here Xgamma as a function of moisture in solid
Aw = GAB_solve(CWa(n),T(n));
PSat = AntoineW(T(n)); % Calculate water vapour pressure
%Mass fluxes at the interface
Jwat = (-kmWat * (18.01 / R)) * ( ( (Aw * PSat) / (T(n) - 273.15) ) - (RH / (Tinf - 273.15)) ) ;
% Boundary condition at x=xu, convective heat transfer at the surface
Tt(i) = ((-(h /(lambda(CWa(i-1),T(i-1)))) * (T(i)- Tinf)) - (lambdaW * Jwat) ) * dx2; % heat transfer boundary condition
CWat(i) = Jwat; % Boundary condition at x=xu, convective heat transfer t=at the surface % MT boundary condition at x=xu, convective mass transfer at the surface
% Body terms
else
kpot(i) = lambda(CWa(i-1),T(i-1)); % Thermal conductivity as function of composition and Temperature
rho(i) = density(CWa(i-1),T(i-1)); % Density as function of composition of composition and temperature
CP(i) = Cp(CWa(i-1),T(i-1)); % Specific Heat Capacity as function of composition and temperature
alphaT = kpot ./ (rho .* CP); % Thermal diffusivity as function of composition and temperature
Tt(i) = alphaT(i) * (T(i+1) - 2 * T(i) + T(i-1)) * dx2; % Diffusive heat transfer
D = Diffusivity(CWa(i-1),T(i)); % Moisture diffusivity as function of composition and temperature
CWat(i) = (D * (CWa(i+1) - 2.0 * CWa(i) + CWa(i-1)) * dx2 ); % Diffusive Mass transfer and starch gelatinisation
end
6 Comments
darova
on 3 May 2020
Can you attach something more?
Simon Lawton
on 4 May 2020
darova
on 4 May 2020
Can you show original formulas?
Simon Lawton
on 4 May 2020
darova
on 4 May 2020
Where is
boundary condition (initial)
Simon Lawton
on 5 May 2020
Answers (1)
darova
on 5 May 2020
Try this simple example
a = 1/pi^2;
x = linspace(0,1,50)';
T0 = 1-(1/2-x).^2; % initial condition t=0 (start time)
dx = x(2)-x(1);
% left boundary T=0
% right boundary T=0
f = @(t,T) [0; a*diff(T(1:50),2)/dx^2; 0];
[t,T] = ode45(f,[0 3], T0);
[xx,tt] = meshgrid(x,t);
surf(tt,xx,T,'edgecolor','none')
axis vis3d

Categories
Find more on Structural Mechanics 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!