How can I run a parametric sweep of an ODE using sys & dsolve?
I’m trying to solve a basic ODE (transient energy balance in a stirred tank). I can easily solve my equation using this code below (simplified).
However, I need to automate a parametric sweep so I can vary things like the size of the tank or the heater duty etc and plot all the curves on a single graph. I’ve looked around this forum and the support docs but can’t really find a solution. I would like to stick to the symbolic toolbox if possible, since it’s much neater and elegant than definiting separate functions the old way, but if that’s the only solution, then happy to do that.
Is there a simple way to do this? I’ve attempted to use a for loop but I get index errors pop up.
I haven’t used matlab since undergrad (10 years ago), so am a bit rusty.
syms T(t)
ode = m_w * Cp_w * (diff(T,t) – T_ref) == (m_in * Cp_w * (T_in – T_ref)) – (m_out * Cp_w * (T(t) – T_ref)) + Q_heater – (R_tot * (T(t) – T_amb) * A_ins);
cond = T(0) == T_amb;
TSol(t) = dsolve(ode,cond);
fplot(TSol,[0 3600]);I’m trying to solve a basic ODE (transient energy balance in a stirred tank). I can easily solve my equation using this code below (simplified).
However, I need to automate a parametric sweep so I can vary things like the size of the tank or the heater duty etc and plot all the curves on a single graph. I’ve looked around this forum and the support docs but can’t really find a solution. I would like to stick to the symbolic toolbox if possible, since it’s much neater and elegant than definiting separate functions the old way, but if that’s the only solution, then happy to do that.
Is there a simple way to do this? I’ve attempted to use a for loop but I get index errors pop up.
I haven’t used matlab since undergrad (10 years ago), so am a bit rusty.
syms T(t)
ode = m_w * Cp_w * (diff(T,t) – T_ref) == (m_in * Cp_w * (T_in – T_ref)) – (m_out * Cp_w * (T(t) – T_ref)) + Q_heater – (R_tot * (T(t) – T_amb) * A_ins);
cond = T(0) == T_amb;
TSol(t) = dsolve(ode,cond);
fplot(TSol,[0 3600]); I’m trying to solve a basic ODE (transient energy balance in a stirred tank). I can easily solve my equation using this code below (simplified).
However, I need to automate a parametric sweep so I can vary things like the size of the tank or the heater duty etc and plot all the curves on a single graph. I’ve looked around this forum and the support docs but can’t really find a solution. I would like to stick to the symbolic toolbox if possible, since it’s much neater and elegant than definiting separate functions the old way, but if that’s the only solution, then happy to do that.
Is there a simple way to do this? I’ve attempted to use a for loop but I get index errors pop up.
I haven’t used matlab since undergrad (10 years ago), so am a bit rusty.
syms T(t)
ode = m_w * Cp_w * (diff(T,t) – T_ref) == (m_in * Cp_w * (T_in – T_ref)) – (m_out * Cp_w * (T(t) – T_ref)) + Q_heater – (R_tot * (T(t) – T_amb) * A_ins);
cond = T(0) == T_amb;
TSol(t) = dsolve(ode,cond);
fplot(TSol,[0 3600]); ode, differential equations, symbolic, parametric, dsolve MATLAB Answers — New Questions