Keep getting error message on my ODE function

1 回表示 (過去 30 日間)
Kristin Cynthia Hansel
Kristin Cynthia Hansel 2019 年 11 月 27 日
回答済み: Kristin Cynthia Hansel 2019 年 12 月 2 日
I am currently working on coding polymerization of PLA in a batch reactor keep getting error message. My professor helped my group get to this point but eveytime we run it we get,
Error using horzcat
Dimensions of arrays being concatenated are not consistent.
We have tried everything we can think of to fix this problem but we arent sure why this is happening or how to fix it.
Error in sad_girl_Project (line 46)
u0=[P0 zeros(N,1) 0] ;
function sad_girl_Project
T = 180+273.15; %Temperature [K]
Keq=10;
%% Calculations
lk1=-(6810.3/T)+6.1928
k1=exp(lk1) %rate constant for Polymerization (L/mol*s)
km1=k1/Keq %rate constant for depolymerization (L/mol*s)
P0=10;
N=100; %degree of polimerzation
% u=[P1, P2, .... PN, W]
function dudt=deq(t,u)
P= u(1:N);
W= u(N-1);
sum3= sum(P);
sum4=0;
for ii=1:N
sum1 = 0;
for jj=1:ii-1
sum1= sum1 + P(ii-jj)*P(jj);
end % for jj
%disp([ii, P(1:2), sum1])
sum2= sum(P(ii+1:N));
dudt(ii)= k1*sum1 + 2*km1*W*sum2 - ...
2*k1*P(ii)*sum3 - km1*W*(ii-1)*P(ii);
sum4 = sum4 + (ii-1)*P(ii);
%disp([ii, sum1, sum2 sum3])
end % for ii
dudt(N+1)= k1*sum3^2 - km1*W*sum4;
dwdt(N+1)=0;
dudt=[dudt; dwdt];
end % deq
m=[0 24*3600] ;
u0=[P0 zeros(N,1) 0] ;
[t,u]=ode15(@deq,m,u0) ;
%% Plot
figure(1)
plot(t,u)
title('Time Vs. Molecular Weight')
xlabel('Time []')
ylabel('Concentration []')
end
  2 件のコメント
darova
darova 2019 年 11 月 27 日
DId you try to change the name of a function?
function happy_girl_Project
How do you want u0 vector should looks like?
u0=[P0 zeros(N,1) 0] ;
% P0 = 10;
% zeros(N,1) - column vector
% 0 = 0
Jan
Jan 2019 年 11 月 28 日
I've formatted the text and the code to improve the readability.

サインインしてコメントする。

採用された回答

Jan
Jan 2019 年 11 月 28 日
u0 = [P0, zeros(1, N + 1)];
  1 件のコメント
darova
darova 2019 年 11 月 28 日
it works

サインインしてコメントする。

その他の回答 (1 件)

Kristin Cynthia Hansel
Kristin Cynthia Hansel 2019 年 12 月 2 日
Thank you!

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by