使用ODE在Matlab中表示热模型

时间:2018-10-06 11:02:30

标签: matlab ode

我正在像本link所示模拟AC。 通过翻转一些方程式并重新初始化一些值,我设法将其转换为AC。现在,我需要在Matlab中创建它,以使我的系统能够平稳快速地运行,而不必为每次迭代运行simulink。我对ODE45进行了一些阅读并决定使用它,首先,我将网页中的模型转换为以下函数:

    function dTroom_dt = odes_thermal(Troom,Tout)
    TinIC = 26;
    r2d = 180/pi;
    % -------------------------------
    % Define the house geometry
    % -------------------------------
    % House length = 30 m
    lenHouse = 30;
    % House width = 10 m
    widHouse = 10;
    % House height = 4 m
    htHouse = 4;
    % Roof pitch = 40 deg
    pitRoof = 40/r2d;
    % Number of windows = 6
    numWindows = 6;
    % Height of windows = 1 m
    htWindows = 1;
    % Width of windows = 1 m
    widWindows = 1;
    windowArea = numWindows*htWindows*widWindows;
    wallArea = 2*lenHouse*htHouse + 2*widHouse*htHouse + ...
        2*(1/cos(pitRoof/2))*widHouse*lenHouse + ...
        tan(pitRoof)*widHouse - windowArea;
    % -------------------------------
    % Define the type of insulation used
    % -------------------------------
    % Glass wool in the walls, 0.2 m thick
    % k is in units of J/sec/m/C - convert to J/hr/m/C multiplying by 3600
    kWall = 0.038*3600;   % hour is the time unit
    LWall = .2;
    RWall = LWall/(kWall*wallArea);
    % Glass windows, 0.01 m thick
    kWindow = 0.78*3600;  % hour is the time unit
    LWindow = .01;
    RWindow = LWindow/(kWindow*windowArea);
    % -------------------------------
    % Determine the equivalent thermal resistance for the whole building
    % -------------------------------
    Req = RWall*RWindow/(RWall + RWindow);
    % c = cp of air (273 K) = 1005.4 J/kg-K
    c = 1005.4;
    % -------------------------------
    % Enter the temperature of the heated air
    % -------------------------------
    % The air exiting the heater has a constant temperature which is a heater
    % property. THeater =20 deg C
    THeater = 20;
    % Air flow rate Mdot = 1 kg/sec = 3600 kg/hr
    Mdot = 3600;  % hour is the time unit
    % -------------------------------
    % Determine total internal air mass = M
    % -------------------------------
    % Density of air at sea level = 1.2250 kg/m^3
    densAir = 1.2250;
    M = (lenHouse*widHouse*htHouse+tan(pitRoof)*widHouse*lenHouse)*densAir;
    %%

    dQlosses_dt= (THeater-Troom)*Mdot*c;

    dQlosses_dt=(Troom-Tout)/Req;

    dTroom_dt=(1/(M*c))*(dQlosses_dt);

    end

然后我只是使用以下几行来调用它:

    clear;
    t=1:1:1440;
    Troom_0=25;
    [t,Troom] = ode45('odes_thermal',[t(1) t(3)],Troom_0);
    figure(1);
    plot(t,Troom);

当我运行它时,我得到的是: enter image description here

我的问题是,如何将状态或开关功能纳入其中。在simulink中,他们使用的继电器将根据温度产生状态信号,该状态信号将为1或0,这是他们的操作方式:

enter image description here

我知道这可以用“ dQlosses_dt =(玩家房间) Mdot c * status;”表示。但是我不知道如何在每个时间段更新状态,因为无法在每个时间段检查Troom。您能以此或至少从哪里开始指导我吗?

编辑:按照Pacta的评论,我试图使其成为具有两个输出Troom和Qlosses的多变量系统。这是新功能,但出现错误(在odes_thermal2中输入参数过多)

    clear;
    t=1:1:1440;
    Troom_0=25;Qlosses_0=10;
    X0=[Troom_0;Qlosses_0];
    [t,X] = ode45('odes_thermal2',[t(1) t(end)],X0);
    Troom=X(1);
    Qlosses=X(2);
    figure(1);
    plot(t,Troom);
    ylabel('Troom');
    xlabel('t');

ODE函数具有以下更改:

    function dX_dt = odes_thermal2(X)
    TinIC = 26;
    r2d = 180/pi;

    X(2)= (THeater-Troom)*Mdot*c;

    dQlosses_dt=(Troom-Tout)/Req;

    X(1)=(1/(M*c))*(dQlosses_dt);

谢谢

0 个答案:

没有答案