How can I solve an ODE with changing variable over time ?
12 views (last 30 days)
Show older comments
I want to solve a sytem of ODE, with the following paramiters and initioal conditions.
in the 4th equation of the ODE, Tset(t) is a variable which is changing over time, however in this code I have made it as an constant value over time and my code is working.
I have the values for Tset(t) as well as the corresponding time of these values in a mat file : (TsetTime, TsetValue)
how can I solve the ODE if the value of Tset (in the 4th equation of the ODE) is changing over time.
% Paramiters
Xb = 16;
Xw = 0.4;
Rg = 8.314;
pT = 101325;
g = 0.042;
mue = 4e7;
NumBubbles = 2e11;
R0 = 5e-5;
Temp0 = 303;
n0 = 0;
C0 = 0;
q0 = 0.0015;
tt = 1/30;
nN2 = 4/3*pi*R0^3*(pT+2*g/R0)/Rg/Temp0;
VD = 1-R0.^3*4/3*pi*NumBubbles;
init = [R0; n0; C0;Temp0; q0];
%sysytem of ODE
OdeSys = @(t,y) [
1/4/mue*(3*Rg*y(4)/4/pi/y(1)^2*(y(2)+nN2)-pT*y(1)-2*g);
4*pi*(1.77e-9*Xw*y(4)/298)*y(1)*(y(3)-((pT/(100*(y(4)-273)+1200)*(1-(R0/y(1))^3)+2*g/(100*(y(4)-273)+1200)/y(1)*(1-(R0/y(1))^2))));
Xb*y(5)-NumBubbles*4*pi*(1.77e-9*Xw*y(4)/298)*y(1)*(y(3)-((pT/(100*(y(4)-273)+1200)*(1-(R0/y(1))^3)+2*g/(100*(y(4)-273)+1200)/y(1)*(1-(R0/y(1))^2)))); % dc_CO2/dt -> CO2 concentration in (liquid) dough
tt*(Tset(t) - y(4));
0
];
[T,S] = ode45(OdeSys, [0 3000], init);
%Plot the results
figure('Position', [0 0 1600 500]);
for i = 1:4
subplot(1,4,i);
plot(T,S(:,i))
xlim([0, T(end)]); grid on; box off
xlabel('time $/s$','interpreter','Latex');
ylabel('value $/units$','interpreter','Latex');
title(titles{i},'interpreter','latex');
end
% this function is used to make Tset(t) constatnt over time, however I want
% to change this with TsetValue at TsetTime
function Ts = Tset(t)
Ts = 303;
end
%load TsetTime
%load TsetValue
0 Comments
Accepted Answer
Stephen23
on 4 Jul 2021
Replace your Tset function with this:
P = 'absolute or relative path to where the mat file is saved';
F = 'name of the mat file';
S = load(fullfile(P,F));
Tset = @(t) interp1(S.TsetTime, S.TsetValue,t);
0 Comments
More Answers (0)
See Also
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!