How to solve mass transfer equation with array input

My bass balance equation for the energy loss of a water tank exposed to the sun is the following: M*c_p*dT/dt = Q, where Q is the sum of the energy loss through convection, evaporation and radiation:
Q_conv = h_c*A*(T_w-T)
Q_evap = m*c_p*(100-T_w)*1000/24/3600
Q_rad = sigma*T_w^4*eps_lent*A+G*eps_lent*A;
Where dT/dt, T and G are arrays. I tried to solve the mass balance for T_w (water temperature) using solve(eqn,T_w) but I only get a symbolic 0x1 matrix as an answer with no content. How do I solve this correctly so that I get an array for T_w?
Best regards

回答(1 个)

You appear to have a system of differential equations. You need to correctly cast your system as a set of differential equations (see the documentation on ode45 to begin with), then solve them numerically using one of the ODE solvers, or (if it has an analytic solution), the Symbolic Math Toolbox dsolve function.
It’s not obvious to me what the variables-of-interest are, so I leave the coding to you.

3 个评论

Thank you for your answer! To be clear, it is just one one equation with one unknown (T_w), the other variables are all known. The values for dT/dt, T and G are given in arrays, the others are constant values - so I figured I wouldn't need differential equations, just solve this one for an array T_w.
M*c_p*dT/dt = Q_conv + Q_evap + Q_rad
M*c_p*dT/dt = h_c*A*(T_w-T) + m*c_p*(100-T_w)*1000/24/3600 + sigma*T_w^4*eps_lent*A+G*eps_lent*A
This is how I have tried it so far:
syms T_w
eqn = M*cp_w.*dTdt == h_c*A*(T_w-T) + 1*cp_w*(100-T_w)*1000/24/3600 + sigma.*T_w^4*eps_lent*A+G.*eps_lent*A;
sol = solve(eqn,T_w)
Unfortunately the solution so far is the following:
sol = Empty sym: 0-by-1
If you already have the vectors for your variables and just want to calculate the result, that should be straightforward, with a little algebra.
Use the element-wise multiplication and division ‘dot operator’, ‘.*’ and ‘./’ unless you want to do matrix calculations. See Array vs. Matrix Operations (link) for details. The Symbolic Math Toolbox is likely not necessary.

请先登录,再进行评论。

类别

在 帮助中心 和 File Exchange 中查找有关 Programming 的更多信息

产品

提问:

2017-9-18

Community Treasure Hunt

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

Start Hunting!

Translated by