필터 지우기
필터 지우기

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.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Image Analyst
Image Analyst 2023년 4월 27일

카테고리

Help CenterFile Exchange에서 Equation Solving에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by