Why do I get "Array indices must be positive integers or logical values"

3 ビュー (過去 30 日間)
I am trying to solve the following differential equation ode3. Tc_p is a cfit that I change to a symfun so I can susbtitute inside my differential equation and solve the whole thing. I can`t understand why I am getting the error "Array indices must be positive integers or logical values.". Thx in advanace.
clear all
datos_TH;
syms Tfav(t) Tcav(t) Tm(t)
cond1=Tfav(0)==(Tf0-Tm0)/(Tf0-Tm0);
cond2=Tcav(0)==(Tc0-Tm0)/(Tf0-Tm0);
%cond3=Tm(0)==Tm0;
conds=[cond1; cond2];
ode1=diff(Tfav)==-2*Bigf*(Tfav-Tcav)/Rf0 + 100;
ode2=diff(Tcav)==2*K*(Bigc*Rci*(Tfav-Tcav)-Bi(1)*Tcav)/(1-Rci^2);
%ode3=diff(Tm)==(Sc*hi(1)*(Tc-Tm)-2*m*cp*(Tm-Tm0))/(Mc*cp);
odes=[ode1;ode2];
[TcavSol(t), TfavSol(t)]=dsolve(odes, conds);
Tf=[];
Tc=[];
n=1;
t_0=25;
time_ad=t_0*kf/(Rhof*cf*rc0^2);
for i=0:0.01:time_ad
Tf(n)=double(TfavSol(i))*(Tf0-Tm0) + Tm0;
Tc(n)=double(TcavSol(i))*(Tf0-Tm0) + Tm0;
n=n+1;
m=n+1;
end
%Moderator Temperature ODE
save('Tc','Tc');
t=linspace(0,t_0,m-2);
t=transpose(t);
Tc=transpose(Tc);
Tc_p=fit(t,Tc,'poly8');
Tc_p=subs(str2sym(formula(Tc_p)),coeffnames(Tc_p),num2cell(coeffvalues(Tc_p).'));
Tc_p=subs(Tc_p,'t');
cond3=Tm(0)==Tm0;
ode3=diff(Tm,'t')==(Sc*hi(1)*(Tc_p-Tm)-2*m*cp*(Tm-Tm0))/(Mc*cp);
odes=ode3;
TmSol(t)=dsolve(ode3,cond3);
And the complete error is:
Array indices must be positive integers or logical values.
Error in sym/privsubsasgn (line 1311)
L_tilde2 = builtin('subsasgn',L_tilde,struct('type','()','subs',{varargin}),R_tilde);
Error in indexing (line 1142)
C = privsubsasgn(L,R,inds{:});
Error in Sim_TH (line 41)
TmSol(t)=dsolve(ode3,cond3);

採用された回答

Steven Lord
Steven Lord 2023 年 4 月 27 日
You use Tm in your code but nowhere do you define it. My suspicion is that you've defined it as a numeric vector like you did Tf and Tc. But vector indices cannot be 0.
  3 件のコメント
Steven Lord
Steven Lord 2023 年 4 月 27 日
t=linspace(0,t_0,m-2);
% snip intervening lines of code
TmSol(t)=dsolve(ode3,cond3);
The first element of t is 0. 0 is not a valid index into an array in MATLAB. Remove the indexing on that last line.
Diego Mondaray Muñoz
Diego Mondaray Muñoz 2023 年 4 月 28 日
Thank you!!!

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

その他の回答 (1 件)

Image Analyst
Image Analyst 2023 年 4 月 27 日

カテゴリ

Help Center および File ExchangeSymbolic Math Toolbox についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by