for loop not working correctly
Hi,
Please, can someone explain to me why matlab is not varying the input data (Snh4o=50; Sno2o=55) for the below function? in the function, i have specified the input for different days but all it does is use the initial values throughout!
Script:
%initial conditions
y0=[10;10;10;10;10;10;10;1;2;1;0;0;0.5];
t0=0;
tEnd=282;
h=0.0006944444;
N=ceil((tEnd-t0)/h);
%initilising solution
T=t0:h:tEnd;
Y=zeros(13,N+1);
Y(:,1)=y0;
T0=t0;
%boundaries
for i=1:N
T(i+1)=T(i)+h;
%update y
Y(Y<0)=0;
yi=Y(:,i);
a1=MBBRFun1(T(i), yi);
a2=MBBRFun1(T(i)+0.5*h, yi+0.5*a1*h);
a3=MBBRFun1(T(i)+0.5*h, yi+0.5*a2*h);
a4=MBBRFun1(T(i)+ h, yi+ a3*h);
yNew=yi+(h/6)*(a1+2*a2+2*a3+a4);
end
function: (m file attached)
function fval=MBBRFun1(~,y)
%Define the three variables
Xaob=y(1);
Xnb=y(2);
Xnsp=y(3);
Xcmx=y(4);
Xamx=y(5);
Xhan=y(6);
Xhaer=y(7);
Xs=y(8);
Sse=y(9);
Sno3=y(10);
Sno2=y(11);
Snh4=y(12);
So2=y(13);
%parameters
Xo=0; Xe=Xo; Xso=0;
for t=0:46
Snh4o=50; Sno2o=55; So2G=0.5;So2o=3; V=0.0038; Qo=0.000864; Qe=Qo;
end
for t=47:65
Snh4o=60.4; Sno2o=25.3; So2G=0.5;So2o=8.5; V=0.0038; Qo=0.000864; Qe=Qo;
end
for t=66:67
Snh4o=60.4; Sno2o=25.3; So2G=0.5; So2o=8.5; V=0.0038; Qo=0.000864; Qe=Qo;
end
for t=68:74
Snh4o=76.72; Sno2o=45.25; So2G=0.5;So2o=8.5; V=0.0038; Qo=0.002016; Qe=Qo;
end
for t=75:79
Snh4o=76.72; Sno2o=45.25; So2G=0.5; So2o=8.5; V=0.0038; Qo=0.002592; Qe=Qo;
end
for t=80:86
Snh4o=76.72; Sno2o=45.25; So2o=8.5; V=0.005; Qo=0.002592; Qe=Qo; So2G=14.65-0.41*35+7.99*(10^-3)*(35^2)-7.78*(10^-5)*35^3;
end
for t=87
Snh4o=76.72; Sno2o=45.25; So2G=0.1;So2o=8.5; V=0.005; Qo= 0.002736; Qe=Qo;
end
for t=88:102
Snh4o=84.9; Sno2o=50.9; So2G=0.1;So2o=0.8; V=0.005; Qo=0.002736; Qe=Qo;
end
for t=103:108
Snh4o=76.72; Sno2o=45.25; So2G=0.1;So2o=0.8; V=0.005; Qo=0.003168; Qe=Qo;
end
for t=109:120
Snh4o=76.72; Sno2o=45.25; So2G=0.1;So2o=0.8; V=0.005; Qo=0.004176; Qe=Qo;
end
for t=121:134
Snh4o=75.1; Sno2o=62.8; So2G=0.1;So2o=0.8; V=0.005; Qo=0.0054; Qe=Qo;
end
for t=135:137
Snh4o=61.2; Sno2o=45.7; So2G=0.1;So2o=0.8; V=0.005; Qo=0.0054; Qe=Qo;
end
for t=138:151
Snh4o=61.2; Sno2o=45.7; So2G=0.1;So2o=0.8; V=0.005; Qo=0.006120; Qe=Qo;
end
for t=152:159
Snh4o=61.2; Sno2o=45.7; So2G=0.1;So2o=0.8; V=0.005; Qo=0.007056; Qe=Qo;
end
for t=160:176
Snh4o=68.7; Sno2o=49.7; So2G=0.1;So2o=0.8; V=0.005; Qo=0.007920; Qe=Qo;
end
for t=177
Snh4o=68.7; Sno2o=49.7; So2G=0.1;So2o=0.8; V=0.005; Qo=0.006120; Qe=Qo;
end
for t=178:180
Snh4o=68.7; Sno2o=49.7; So2G=0.1;So2o=0.8; V=0.005; Qo=0.006120; Qe=Qo;
end
for t=181:197
Snh4o=50.4; Sno2o=42; So2G=0.1;So2o=0.8; V=0.0038; Qo=0.006120; Qe=Qo;
end
for t=198:208
Snh4o=59.3; Sno2o=58.2; So2G=0.1;So2o=0.8; V=0.005; Qo=0.006120; Qe=Qo;
end
for t=209:212
Snh4o=59.3; Sno2o=58.2; So2G=0.1;So2o=0.8; V=0.005; Qo=0.007920; Qe=Qo;
end
for t=213:214
Snh4o=59.3; Sno2o=58.2; So2G=0.1;So2o=0.8; V=0.005; Qo=0.007920; Qe=Qo;
end
for t=215:221
Snh4o=65; Sno2o=75; So2G=0.1;So2o=0.8; V=0.005; Qo=0.007920; Qe=Qo;
end
for t=222:225
Snh4o=65; Sno2o=75; So2G=0.1;So2o=0.8; V=0.005; Qo=0.007056; Qe=Qo;
end
for t=226:228
Snh4o=65; Sno2o=75; So2G=0.1;So2o=0.8; V=0.005; Qo=0.007920; Qe=Qo;
end
for t=229:237
Snh4o=72.8; Sno2o=89.6; So2G=0.1;So2o=0.8; V=0.005; Qo=0.007920; Qe=Qo;
end
for t=238:245
Snh4o=99.7; Sno2o=116.3; So2G=0.1;So2o=0.8; V=0.005; Qo=0.007920; Qe=Qo;
end
for t=246:253
Snh4o=99.7; Sno2o=116.3; So2G=0.1;So2o=0.8; V=0.005; Qo=0.007920; Qe=Qo;
end
for t=254
Snh4o=99.7; Sno2o=116.3; So2G=0.1;So2o=0.8; V=0.005; Qo=0.01872; Qe=Qo;
end
for t=255:256
Snh4o=99.7; Sno2o=116.3; So2G=0.1;So2o=0.8; V=0.005; Qo=0.007920; Qe=Qo;
end
for t=257:267
Snh4o=99.7; Sno2o=116.3; So2G=0.1;So2o=0.8; V=0.005; Qo=0.007920; Qe=Qo;
end
for t=268:282
Snh4o=99.7; Sno2o=116.3; So2G=0.1;So2o=0.8; V=0.005; Qo=0.007920; Qe=Qo;
end
fval (1,1)=.....
fval (2,1)=...
.
.
fval (13,1)=...
end
Thanks in advance
Antworten (0)
Kategorien
Mehr zu Problem-Based Global Optimization Setup finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!