I want to solve heat balance in discrete time within 2 or 3 offices using system of differential equations in Matlab. Therefore, I set up following equations:

C1*(dT1/dt)=U12*A1*(T1(t)-T2(t))+U13*A2*(T1(t)-T3(t))+H1(t);
C2*(dT2/dt)=U21*A1*(T1(t)-T2(t))+U23*A2*(T2(t)-T3(t))+H2(t)

C,U,A are parameters and T3(t),H1(t) and H2(t) are functions which vary over time. I want to calculate T1 and T2 in discrete time. Beside that, I want to involve thermostat control in equations.

I already tried to solve this but only with one equation and I obtained linear graph. Could somebody give me some instructions or suggestions how I need to set up this and solve it? I really appreciate your help!

Thanks!

有帮助吗?

解决方案

I would use a finite difference for the derivatives.

dT/dt =~ (T(n) - T(n-1))/(dt)

Where T(n) is the temperature at time step n and dt is the time between samples.

C1*((T1(n) - T1(n-1))/dt)=U12*A1*(T1(n)-T2(n))+U13*A2*(T1(n)-T3(n))+H1(n)
C2*((T2(n) - T2(n-1))/dt)=U21*A1*(T1(n)-T2(n))+U23*A2*(T2(n)-T3(n))+H2(n)

Now, just solve the system of equations for T1(n) and T2(n). I use sympy for simple, but tedious algebra like this. Then just initialize all your parameters and simulate the equations for N steps like so:

function [T1,T2] = simHeatEqns(N)
  dt = ..
  U12 = ..
  .
  .
  .
  % simulate for N steps
  for n=2:N
    T1(n) = (A1*A2*T3(n)*U12*U23*dt^2 - A1*A2*T3(n)*U13*U21*dt^2 + A1*C1*T1(n-1)*U21*dt - A1*C2*T2(n-1)*U12*dt + A1*H1n*U21*dt^2 - A1*H2n*U12*dt^2 + A2^2*T3(n)*U13*U23*dt^2 - A2*C1*T1(n-1)*U23*dt - A2*C2*T3(n)*U13*dt - A2*H1n*U23*dt^2 + C1*C2*T1(n-1) + C2*H1n*dt)/(A1*A2*U12*U23*dt^2 - A1*A2*U13*U21*dt^2 + A1*C1*U21*dt - A1*C2*U12*dt + A2^2*U13*U23*dt^2 - A2*C1*U23*dt - A2*C2*U13*dt + C1*C2)
    T2(n) = (A1*U21*(-A2*T3(n)*U13*dt + C1*T1(n-1) + H1n*dt)/(A1*U12*dt + A2*U13*dt - C1) - (-A2*T3(n)*U23*dt + C2*T2(n-1) + H2n*dt)/dt)/(A1^2*U12*U21*dt/(A1*U12*dt + A2*U13*dt - C1) + (-A1*U21*dt + A2*U23*dt - C2)/dt)
  end
end
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top