Matlab'矩阵尺寸必须一致'ode23s

问题描述 投票:0回答:1

以下是我的代码。我尝试使用ode23在Matlab中为PFR建模。它与一种成分的不可逆反应效果很好。但是,当扩展更多因变量时,“矩阵维数必须一致”问题显示出来。不知道如何解决它。是否可以使用其他软件来解决类似的问题?谢谢。

function PFR_MA_length
    clear all; clc; close all;
    function dCdt = df(t,C)  
        dCdt = zeros(N,2);
        dCddt = [0; -vo*diff(C(:,1))./diff(V)-(-kM*C(2:end,1).*C(2:end,2)-kS*C(2:end,1))];
        dCmdt = [0; -vo*diff(C(:,2))./diff(V)-(-kM*C(2:end,1).*C(2:end,2))];
        dCdt(:,1) = dCddt;
        dCdt(:,2) = dCmdt;
    end
    kM = 1;
    kS = 0.5;                           % assumptions of the rate constants
    C0 = [2, 2];                        % assumptions of the entering concentration
    vo = 2;                             % volumetric flow rate
    volume = 20;                        % total volume of reactor, spacetime = 10

    N = 100;                            % number of points to discretize the reactor volume on

    init = zeros(N,2);                  % Concentration in reactor at t = 0
    init(1,:) = C0;                      % concentration at entrance

    V = linspace(0,volume,N)';          % discretized volume elements, in column form

    tspan = [0 20];
    [t,C] = ode23s(@(t,C) df(t,C),tspan,init);
end

'''

matlab ode
1个回答
0
投票

您可以在计算dCddt的线上放置一个断点,并观察到矩阵CV的大小不同。

>> size(C)
 ans =
  200     1

>> size(V)
 ans =
  100     1
© www.soinside.com 2019 - 2024. All rights reserved.