Unrecognized function or variable 'MBBR_Fun5'.

1 回表示 (過去 30 日間)
KIPROTICH KOSGEY
KIPROTICH KOSGEY 2021 年 5 月 3 日
コメント済み: KIPROTICH KOSGEY 2021 年 5 月 3 日
Hi
I keep getting the above error when i run the below code and i can't figure out why.
%%
mo=4*10^-11; %initial particle mass in gCOD
Mx=7.2*10^-11; %maximum particle biomass
rho=32000; %maximum density of particles in gCOD/cubic metre of particles
Rp=(3*mo/(4*pi*rho))^1/3;
Rn=Rp;
%%
r=0:7.5;
l=0:14;
c=0:109.8232;
dn=zeros(numel(r),numel(l),numel(c));
deltaxj=zeros(size(dn));
x1=zeros(size(dn));
x1(1,1,1)=1;
h=1; %change later to 0.000694
t0=0;
tEnd=535;
y01=0.5*18.16; y02=0.5*0.52; y03=0.5*25.64; y04=0.5*3.6; y05=0.5*172.6; y06=0.5*179.48; y07=0.0005; y08=2;
y09=0.0005; y10=55; y11=50; y12=0.5;
N=(tEnd-t0)/h; T=(t0:h:tEnd);
Y=zeros(12,N+1);
Y(:,1)=[y01;y02;y03;y04;y05;y06;y07;y08;y09;y10;y11;y12];
for i=1:size(dn,1)
for ii=1:size(dn,2)
for iii=1:size(dn,3)
for iv=1:size(T)
k1=MBBR_Fun5(T(iv), Y(:,iv));
k2=MBBR_Fun5(T(iv)+0.5*h, Y(:,iv)+0.5*k1*h);
k3=MBBR_Fun5(T(iv)+0.5*h, Y(:,iv)+0.5*k2*h);
k4=MBBR_Fun5(T(iv)+ h, Y(:,iv)+ k3*h);
Y(:,iv+1)=MBBR_Fun5(:,iv)+(h/6)*(k1+2*k2+2*k3+k4);
end
end
end
end
Function
function fval=MBBR_Fun5(t,Y,~)
%Define the three variables
Xaob=Y(1);
Xnb=Y(2);
Xnsp=Y(3);
Xcmx=Y(4);
Xamx=Y(5);
Xhan=Y(6);
Xs=Y(7);
Sse=Y(8);
Sno3=Y(9);
Sno2=Y(10);
Snh4=Y(11);
So2=Y(12);
%parameters
Xo=0; Xe=Xo; Xso=0;
%parameters
Xo=0; Xe=Xo; Xso=0;
%aob
O1=68/(0.00831*293*303); u1=1.443*exp(O1*15); Ko2aob=0.8*0.594; Knh4aob=0.55*2.4; Yaob=3*0.15; Kno3aob=0.5;
%nb
O2=44/(0.00831*293*303); u2=1.8*0.48*exp(O2*15); Ko2nb=0.98*0.435; Kno2nb=0.5*1.375; Ynb=1.0*0.13;Kno3nb=0.5;
%nsp
O3=44/(0.00831*293*303); u3=1.2*0.69*exp(O3*15); Ko2nsp=0.85*0.435; Kno2nsp=1.0*0.76; Ynsp=1.0*0.14;Kno3nsp=0.5;
%cmx
O4=44/(0.00831*293*303); u4=0.6*0.72*exp(O4*15); Ko2cmx=0.98*0.43; Kno2cmx=0.15*6.29;Knh4cmx=70*0.011; Ycmx=0.1*0.47;YcmxNo2=2*Ycmx;Kno3cmx=0.5;
%amx
O5=71/(0.00831*293*303); u5=0.8*0.0664*exp(O5*15); Kno2amx=1.5*0.175; Kno3amx=0.5; Knh4amx=3*0.185; Yamx=1.2*0.159; Ko2amx=0.01; Kno3amx=0.5;
%han
u6=7.2*exp(15*0.069); KSsehan=0.5*2; Kno2han=0.5*0.5; YNo2han=2*0.49; Ko2han=0.2;
YNo3han=1.0*0.79; Kno3han=0.5*0.32;Yhaer=1*0.37;
%other constants
baob=0.1296*exp(0.11*15); bnb=0.069*exp(0.11*15);bnsp=0.06*exp(0.11*15);
bcmx=0.06*exp(0.11*15); bamx=1.5*0.00312*exp(0.11*15); bhaer=0.5*0.192*exp(15*0.11);
bhan=0.5*0.192*exp(0.11*15);
INBM=0.0583; fI=0.08; namx=0.5; nhan=0.6;naob=0.5; nnb=0.5;nhaer=0.5;nnsp=0.5;ncmx=0.5;
KX=0.03; KH=3*exp(0.069*15); INXI=0.02;
% input parameters
Sseo=2; Sno3o=0;
%oxygen transfer
KaL=222*(1.02^-5);
if le (t,46)
Snh4o=50; Sno2o=55; So2G=2;So2o=2; V=0.0038; Qo=0.000864; Qe=Qo;
else if and (gt (t,46),le (t,65))
Snh4o=60.4; Sno2o=25.3; So2G=2;So2o=8.5; V=0.0038; Qo=0.000864; Qe=Qo;
else if and (gt (t,65) , le (t,67))
Snh4o=60.4; Sno2o=25.3; So2G=2; So2o=8.5; V=0.0038; Qo=0.000864; Qe=Qo;
else if and (gt (t,67) , le (t,74))
Snh4o=76.72; Sno2o=45.25; So2G=1.5;So2o=8.5; V=0.0038; Qo=0.002016; Qe=Qo;
else if and (gt (t,74) , le (t,79))
Snh4o=76.72; Sno2o=45.25; So2G=1.5; So2o=8.5; V=0.0038; Qo=0.002592; Qe=Qo;
else if and (gt (t,80) , le (t,86))
Snh4o=76.72; Sno2o=45.25; So2o=8.5; V=0.005; Qo=0.002592; Qe=Qo; So2G=1.5; %So2G=14.65-0.41*35+7.99*(10^-3)*(35^2)-7.78*(10^-5)*35^3;
else if and (gt (t,86) , le (t,87))
Snh4o=76.72; Sno2o=45.25; So2G=1.5;So2o=2; V=0.005; Qo= 0.002736; Qe=Qo;
else if and (gt (t,87) , le (t,102))
Snh4o=84.9; Sno2o=50.9; So2G=1.5;So2o=2; V=0.005; Qo=0.002736; Qe=Qo;
else if and (gt (t,102) , le (t,108))
Snh4o=76.72; Sno2o=45.25; So2G=1.5;So2o=2; V=0.005; Qo=0.003168; Qe=Qo;
else if and (gt (t,108) , le (t,120))
Snh4o=76.72; Sno2o=45.25; So2G=1.5;So2o=2; V=0.005; Qo=0.004176; Qe=Qo;
else if and (gt (t,121) , le (t,134))
Snh4o=75.1; Sno2o=62.8; So2G=1.5;So2o=2; V=0.005; Qo=0.0054; Qe=Qo;
else if and (gt (t,134) , le (t,137))
Snh4o=61.2; Sno2o=45.7; So2G=1.5;So2o=2; V=0.005; Qo=0.0054; Qe=Qo;
else if and (gt (t,137) , le (t,151))
Snh4o=61.2; Sno2o=45.7; So2G=1.5;So2o=2; V=0.005; Qo=0.006120; Qe=Qo;
else if and (gt (t,151) , le (t,159))
Snh4o=61.2; Sno2o=45.7; So2G=1.5;So2o=2; V=0.005; Qo=0.007056; Qe=Qo;
else if and (gt (t,159) , le (t,176))
Snh4o=68.7; Sno2o=49.7; So2G=1.5;So2o=2; V=0.005; Qo=0.007920; Qe=Qo;
else if and (gt (t,176) , le (t,177))
Snh4o=68.7; Sno2o=49.7; So2G=1.5;So2o=2; V=0.005; Qo=0.006120; Qe=Qo;
else if and (gt (t,177) , le (t,180))
Snh4o=68.7; Sno2o=49.7; So2G=1.5;So2o=2; V=0.005; Qo=0.006120; Qe=Qo;
else if and (gt (t,180) , le (t,197))
Snh4o=50.4; Sno2o=42; So2G=1.5;So2o=2; V=0.0038; Qo=0.006120; Qe=Qo;
else if and (gt (t,197) , le (t,208))
Snh4o=59.3; Sno2o=58.2; So2G=1.5;So2o=2; V=0.005; Qo=0.006120; Qe=Qo;
else if and (gt (t,208) , le (t,212))
Snh4o=59.3; Sno2o=58.2; So2G=1.5;So2o=2; V=0.005; Qo=0.007920; Qe=Qo;
else if and (gt (t,212) , le (t,214))
Snh4o=59.3; Sno2o=58.2; So2G=1.5;So2o=2; V=0.005; Qo=0.007920; Qe=Qo;
else if and (gt (t,214) , le (t,221))
Snh4o=65; Sno2o=75; So2G=1.5;So2o=2; V=0.005; Qo=0.007920; Qe=Qo;
else if and (gt (t,221) , le (t,225))
Snh4o=65; Sno2o=75; So2G=1.5;So2o=2; V=0.005; Qo=0.007056; Qe=Qo;
else if and (gt (t,225) , le (t,228))
Snh4o=65; Sno2o=75; So2G=1.5;So2o=2; V=0.005; Qo=0.007920; Qe=Qo;
else if and (gt (t,228) , le (t,237))
Snh4o=72.8; Sno2o=89.6; So2G=1.5;So2o=2; V=0.005; Qo=0.007920; Qe=Qo;
else if and (gt (t,237) , le (t,245))
Snh4o=99.7; Sno2o=116.3; So2G=1.5;So2o=2; V=0.005; Qo=0.007920; Qe=Qo;
else if and (gt (t,245) , lt (t,250))
Snh4o=99.7; Sno2o=116.3; So2G=1.5;So2o=2; V=0.005; Qo=0.007920; Qe=Qo;
else if eq(t,250)
Snh4o=99.7; Sno2o=116.3; So2G=1.5;So2o=2; V=0.005; Qo=0.007920; Qe=Qo;
else if and (gt (t,250) , le (t,254))
Snh4o=112.19; Sno2o=145.38; So2G=1.5;So2o=2; V=0.005; Qo=0.01872; Qe=Qo;
else if and (gt (t,254) , le (t,256))
Snh4o=112.19; Sno2o=145.38; So2G=1.5;So2o=2; V=0.005; Qo=0.007920; Qe=Qo;
else if and (gt (t,256) , le (t,264))
Snh4o=112.19; Sno2o=145.38; So2G=1.5;So2o=2; V=0.005; Qo=0.006588; Qe=Qo;
else if and (gt (t,264) , le (t,278))
Snh4o=112.19; Sno2o=145.38; So2G=1.5;So2o=2; V=0.005; Qo=0.007056; Qe=Qo;
else if and (gt (t,278) , le (t,288))
Snh4o=108.43; Sno2o=140.786; So2G=1.5;So2o=0.8; V=0.005; Qo=0.007056; Qe=Qo;
else if and (gt (t,288) , le (t,295))
Snh4o=108.43; Sno2o=140.786; So2G=1.5;So2o=2; V=0.005; Qo=0.007920; Qe=Qo;
else if and (gt (t,295) , le (t,302))
Snh4o=140.43; Sno2o=196.4; So2G=1.5;So2o=2; V=0.005; Qo=0.007920; Qe=Qo;
else if and (gt (t,302) , le (t,311))
Snh4o=160; Sno2o=223.85; So2G=1.5;So2o=2; V=0.005; Qo=0.007920; Qe=Qo;
else if and (gt (t,311) , le (t,313))
Snh4o=180.64; Sno2o=252.08; So2G=1.5;So2o=2; V=0.005; Qo=0.007920; Qe=Qo;
else if and (gt (t,313) , le (t,322))
Snh4o=180.64; Sno2o=252.08; So2G=1.5;So2o=2; V=0.005; Qo=0.01; Qe=Qo;
else if and (gt (t,322) , le (t,327))
Snh4o=200; Sno2o=280; So2G=1.5;So2o=2; V=0.005; Qo=0.01; Qe=Qo;
else if and (gt (t,327) , le (t,355))
Snh4o=220; Sno2o=308; So2G=1.5;So2o=2; V=0.005; Qo=0.01; Qe=Qo;
else if and (gt (t,355) , le (t,425))
Snh4o=200; Sno2o=264; So2G=1.5;So2o=2; V=0.005; Qo=0.01; Qe=Qo;
else if and (gt (t,425) , le (t,434))
Snh4o=110; Sno2o=145; So2G=1.5;So2o=2; V=0.005; Qo=0.0166667; Qe=Qo;
else if and (gt (t,434) , le (t,475))
Snh4o=200; Sno2o=264; So2G=1.5;So2o=2; V=0.005; Qo=0.005; Qe=Qo;
else if and (gt (t,475) , le (t,491))
Snh4o=200; Sno2o=264; So2G=1.5;So2o=2; V=0.005; Qo=0.00667; Qe=Qo;
else
Snh4o=200; Sno2o=264; So2G=1.5;So2o=2; V=0.005; Qo=0.01; Qe=Qo;
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
% main functions CSTR 1
fval(1)=u1*(So2/(Ko2aob+So2))*(Snh4/(Knh4aob+Snh4))*Xaob - baob*(So2/(Ko2aob+So2))*Xaob - baob*naob*((Ko2aob/(Ko2aob+So2))*(Sno2+Sno3)/(Kno3aob+Sno2+Sno3))*Xaob;
fval(2)=u2*(Sno2/(Kno2nb+Sno2))*(So2/(Ko2nb+So2))*Xnb - bnb*(So2/(Ko2nb+So2))*Xnb - bnb*nnb*((Ko2nb/(Ko2nb+So2))*(Sno2+Sno3)/(Kno3nb+Sno2+Sno3))*Xnb;
fval(3)=u3*(Sno2/(Kno2nsp+Sno2))*(So2/(Ko2nsp+So2))*Xnsp - bnsp*(So2/(Ko2nsp+So2))*Xnsp - bnsp*nnsp*((Ko2nsp/(Ko2nsp+So2))*(Sno2+Sno3)/(Kno3nsp+Sno2+Sno3))*Xnsp;
fval(4)=u4*((Sno2/(Kno2cmx+Sno2))*(So2/(Ko2cmx+So2)) + u4*(So2/(Ko2cmx+So2))*(Snh4/(Knh4cmx+Snh4)))*Xcmx - bcmx*(So2/(Ko2cmx+So2))*Xcmx - bcmx*ncmx*((Ko2cmx/(Ko2cmx+So2))*(Sno2+Sno3)/(Kno3cmx+Sno2+Sno3))*Xcmx;
fval(5)=u5*((Snh4/(Knh4amx+Snh4))*(Sno2/(Kno2amx+Sno2))*(Ko2amx/(Ko2amx+So2)))*Xamx-bamx*(So2/(Ko2amx+So2))*Xamx - bamx*namx*((Ko2amx/(Ko2amx+So2))*(Sno2+Sno3)/(Kno3amx+Sno2+Sno3))*Xamx;
fval(6)=(u6*(Sse/(KSsehan+Sse))*(Sno2/(Kno2han+Sno2))*(Ko2han/(Ko2han+So2)) + u6*(Sse/(KSsehan+Sse))*(Sno3/(Kno3han+Sno3))*(Ko2han/(Ko2han+So2))+u6*((Sse/(KSsehan+Sse))*(So2/(Ko2han+So2)))*Xhan)- bhan*(So2/(Ko2han+So2))*Xhan - bhan*nhan*((Ko2han/(Ko2han+So2))*(Sno2+Sno3)/(Kno3han+Sno2+Sno3))*Xhan;
fval(7)=- KH*((Xs/Xhan)/(KX+(Xs/Xhan)))*Xhan + (1-fI)*(baob*Xaob+bnb*Xnb+bnsp*Xnsp+bcmx*Xcmx+bamx*Xamx+bhan*Xhan);
fval(8)=-(u6*nhan*(1/YNo2han)*(Sse/(KSsehan+Sse))*(Sno2/(Kno2han+Sno2))*(Ko2han/(Ko2han+So2)))*Xhan -(u6*nhan*(1/YNo3han)*(Sse/(KSsehan+Sse))*(Sno3/(Kno3han+Sno3))*(Ko2han/(Ko2han+So2)))*Xhan - ((u6/Yhaer)*(Sse/(KSsehan+Sse))*(So2/(Ko2han+So2))*Xhan) + KH*(Xs/(Xhan))/(KX+(Xs\(Xhan)))*(Xhan);
fval(9)=- (u6*nhan*((1-YNo3han)/(2.86*YNo3han))*(Sse/(KSsehan+Sse))*(Sno3/(Kno3han+Sno3))*(Ko2han/(Ko2han+So2)))*Xhan + (u5/1.14)*(Snh4/(Knh4amx+Snh4))*(Sno2/(Kno2amx+Sno2))*(Ko2amx/(Ko2amx+So2))*Xamx + (u2/Ynb*(Sno2/(Kno2nb+Sno2))*(So2/(Ko2nb+So2))*Xnb) + ((u3/Ynsp)*(Sno2/(Kno2nsp+Sno2))*(So2/(Ko2nsp+So2))*Xnsp) + ((u4/YcmxNo2)*(Sno2/(Kno2cmx+Sno2))*(So2/(Ko2cmx+So2))*Xcmx)+((u4/Ycmx)*(Snh4/(Knh4cmx+Snh4))*(So2/(Ko2cmx+So2))*Xcmx) - ((1-fI)/2.86)*baob*naob*(Ko2aob/(Ko2aob+So2))*(Sno2+Sno3)/(Kno3aob+Sno2+Sno3)*Xaob - ((1-fI)/2.86)*bnb*nnb*(Ko2nb/(Ko2nb+So2))*(Sno2+Sno3)/(Kno3nb+Sno2+Sno3)*Xnb - ((1-fI)/2.86)*bnsp*nnsp*(Ko2nsp/(Ko2nsp+So2))*(Sno2+Sno3)/(Kno3nsp+Sno2+Sno3)*Xnsp - ((1-fI)/2.86)*bcmx*ncmx*(Ko2cmx/(Ko2cmx+So2))*(Sno2+Sno3)/(Kno3cmx+Sno2+Sno3)*Xcmx - ((1-fI)/2.86)*bamx*namx*(Ko2amx/(Ko2amx+So2))*(Sno2+Sno3)/(Kno3amx+Sno2+Sno3)*Xamx-((1-fI)/2.86)*bhan*nhan*(Ko2han/(Ko2han+So2))*(Sno2+Sno3)/(Kno3han+Sno2+Sno3)*Xhan;
fval(10)=- (((1-YNo2han)/(1.71*YNo2han))*u6*nhan*(Sse/(KSsehan+Sse))*(Sno2/(Kno2han+Sno2))*(Ko2han/(Ko2han+So2))*Xhan) - (((u5/Yamx)+u5/1.14)*(Snh4/(Knh4amx+Snh4))*(Sno2/(Kno2amx+Sno2))*(Ko2amx/(Ko2amx+So2)))*Xamx + ((u1/Yaob)*(So2/(Ko2aob+So2))*(Snh4/(Knh4aob+Snh4)))*Xaob - ((u2/Ynb)*(Sno2/(Kno2nb+Sno2))*(So2/(Ko2nb+So2))*Xnb) - ((u3/Ynsp)*(Sno2/(Kno2nsp+Sno2))*(So2/(Ko2nsp+So2)))*Xnsp - ((u4/YcmxNo2)*(Sno2/(Kno2cmx+Sno2))*(So2/(Ko2cmx+So2)))*Xcmx;
fval(11)= - (u1*(INBM+1/Yaob)*(So2/(Ko2aob+So2))*(Snh4/(Knh4aob+Snh4)))*Xaob - (u4*(INBM+1/Ycmx)*(So2/(Ko2cmx+So2))*(Snh4/(Knh4cmx+Snh4)))*Xcmx -(u5*(INBM+1/Yamx)*(Snh4/(Knh4amx+Snh4))*(Sno2/(Kno2amx+Sno2))*(Ko2amx/(Ko2amx+So2)))*Xamx - (u2*INBM*(Sno2/(Kno2nb+Sno2))*(So2/(Ko2nb+So2)))*Xnb -(u3*INBM*(Sno2/(Kno2nsp+Sno2))*(So2/(Ko2nsp+So2)))*Xnsp - INBM*u6*nhan*((Sse/(KSsehan+Sse))*(Sno2/(Kno2han+Sno2))*(Ko2han/(Ko2han+So2)))*Xhan - u6*INBM*nhan*((Sse/(KSsehan+Sse))*(Sno3/(Kno3han+Sno3))*(Ko2han/(Ko2han+So2)))*Xhan - u6*INBM*((Sse/(KSsehan+Sse))*(So2/(Ko2han+So2)))*Xhan + (INBM-(fI*INXI))*baob*naob*((Ko2aob/(Ko2aob+So2))*(Sno2+Sno3)/(Kno3aob+Sno2+Sno3))*Xaob + (INBM-(fI*INXI))*bnb*nnb*((Ko2nb/(Ko2nb+So2))*(Sno2+Sno3)/(Kno3nsp+Sno2+Sno3))*Xnb +(INBM-(fI*INXI))*bnsp*nnsp*((Ko2nsp/(Ko2nsp+So2))*(Sno2+Sno3)/(Kno3nsp+Sno2+Sno3))*Xnsp + (INBM-(fI*INXI))*(bcmx*ncmx*(Ko2cmx/(Ko2cmx+So2))*(Sno2+Sno3)/(Kno3cmx+Sno2+Sno3))*Xcmx +(INBM-(fI*INXI))*bamx*namx*((Ko2amx/(Ko2amx+So2))*(Sno2+Sno3)/(Kno3amx+Sno2+Sno3))*Xamx + (INBM-(fI*INXI))*bhan*nhan*((Ko2han/(Ko2han+So2))*(Sno2+Sno3)/(Kno3han+Sno2+Sno3))*Xhan +(INBM-(fI*INXI))*baob*(So2/(Ko2aob+So2))*Xaob + (INBM-(fI*INXI))*bnb*(So2/(Ko2nb+So2))*Xnb +(INBM-(fI*INXI))*bnsp*(So2/(Ko2nsp+So2))*Xnsp + (INBM-(fI*INXI))*bcmx*(So2/(Ko2cmx+So2))*Xcmx + (INBM-(fI*INXI))*bamx*(So2/(Ko2amx+So2))*Xamx + (INBM-(fI*INXI))*bhan*(So2/(Ko2han+So2))*Xhan;
fval(12)=((Qo*So2o-Qo*So2 + 50*Qo)/V -(((1-Yhaer)/Yhaer)*u6*(Sse/(KSsehan+Sse))*(So2/(Ko2han+So2)))*Xhan -(((3.43-Yaob)/Yaob)*u1*(So2/(Ko2aob+So2))*(Snh4/(Knh4aob+Snh4)))*Xaob - (((1.14-Ynb)/Ynb)*u2*(Sno2/(Kno2nb+Sno2))*(So2/(Ko2nb+So2)))*Xnb - (((1.14-Ynsp)/Ynsp)*u3*(Sno2/(Kno2nsp+Sno2))*(So2/(Ko2nsp+So2)))*Xnsp - (((4.57-Ycmx)/Ycmx)*u4*(So2/(Ko2cmx+So2))*(Snh4/(Knh4cmx+Snh4)))*Xcmx -(((1.14-YcmxNo2)/YcmxNo2)*u4*(Sno2/(Kno2cmx+Sno2))*(So2/(Ko2cmx+So2)))*Xcmx- (1-fI)*baob*(So2/(Ko2aob+So2))*Xaob - (1-fI)*bnb*(So2/(Ko2nb+So2))*Xnb -(1-fI)*bnsp*(So2/(Ko2nsp+So2))*Xnsp - (1-fI)*bcmx*(So2/(Ko2cmx+So2))*Xcmx - (1-fI)*bamx*(So2/(Ko2amx+So2))*Xamx - (1-fI)*bhan*(So2/(Ko2han+So2))*Xhan);
fval=[fval(1);fval(2);fval(3);fval(4);fval(5);fval(6);fval(7);fval(8);fval(9);fval(10);fval(11);fval(12)];
end
Thanks in advance.
  1 件のコメント
Stephen23
Stephen23 2021 年 5 月 3 日
編集済み: Stephen23 2021 年 5 月 3 日
Writing out all of those separate IF ELSE END statements must have been quite tedious (best avoided).
A simpler approach would just use one IF ELSEIF ELSEIF ELSEIF ... END (no nesting).
Or even simpler, using a matrix (or a few vectors) and basic MATLAB indexing (less buggy and much easier to maintain)

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

回答 (1 件)

DGM
DGM 2021 年 5 月 3 日
This error is pretty misleading, but there are clues. The error makes it sound like it can't find the function file -- but notice that it doesn't occur until after it's already executed other lines utilizing the function. The problem isn't that it can't find the file, it's that you're treating it like it's a variable instead of a function:
MBBR_Fun5(:,iv)
Just what is the colon operator here supposed to expand to since MBBR_Fun5 isn't an array? You'll need to figure out what this argument actually needs to be.
  4 件のコメント
DGM
DGM 2021 年 5 月 3 日
編集済み: DGM 2021 年 5 月 3 日
That still makes no sense. How does it account for 12 variables? Even if it magically knew what 12 numbers you meant, you're passing them as the wrong argument anyway.
The function accepts 2 arguments
  • t - a scalar
  • Y - a 12-element vector
Not only are you trying to pass an undefined vector in place of t, you're trying to pass iv (a scalar) in place of Y. None of this would work even if : expanded to something unambiguous.
If you were intending to use : as a placeholder, implying that you wanted to just ignore the first argument, then you need to make the function be able to do that, and you would need to use valid syntax. It has no means of providing default values or otherwise working without error if its inputs are missing.
Like I said, the error is misleading. If you had written this as a local function in a script file, instead of making it a separate function file, the error is more descriptive:
b = myfun(:)
function aaa=myfun(t)
aaa=t;
end
gives
Error: File: untitled9 Line: 2 Column: 5
Invalid syntax for calling function 'myfun' on the path.
Use a valid syntax or explicitly initialize 'myfun' to make it a variable.
In other words, its telling you to decide whether you want it to be a function or a variable, because you can't pretend it's both.
KIPROTICH KOSGEY
KIPROTICH KOSGEY 2021 年 5 月 3 日
Guys, thanks for the suggestions.
I should have stated that i am a basic user of MATLAB. I am not saying my coding is right, because it surely isn't!.
If you have an idea on how i should edit it then i will greatly appreciate.
My thinking was by writing "Y(:,iv)", I would be able to iterate for each of the 12 Ys at time t(iv).
Thanks and regards

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by