Click here to see the figure.当我运行并绘制X
和解决方案时,似乎数据未排序。关于下标维度不匹配的先前错误现在已经消失。以下是我的主要代码:
clear all
y0 = 20000; % initial conditions
iter = 0;
years = 5;
solution = [];
X = [];
for p = 1:1:years
iter = iter+1;
display(iter)
ll = 273;
ul = 273 + 91;
wl = (ul-ll).*rand(1,1) + ll;
yearlength = wl+0.1;
finaltime = p*yearlength;
t = 0:finaltime;
mugen;
Kgen;
d1gen;
n = 2;
deltat = 1;
tspan = 0:deltat:finaltime;
options = odeset('RelTol',1e-10,'AbsTol',1e-10);
sol = ode23s(@(t,y)para_1d(t,y,n,mug,Kg,d1g),tspan,y0,options);
X = [X sol.x];
Y = (sol.y)';
ny = length(Y);
Ytrans = Y';
solution = [solution Ytrans(1,:)] ;
%display(Ytrans(1,end))
clearvars -except solution solution1 iter X
y0 = solution(end,end);
display(y0)
end
plot(x, solution)
这是我的颂歌所在的功能:
function dy = para_1d(t, y,n, mug, Kg, d1g)
count = ceil(t)+1;
dy(1,1) = (mug(count).*(y(1).^n)/(Kg(count).^n+y(1).^n)) - d1g(count).*y(1);
,参数文件为:
x1 = [0 91.25 91.26 182.5 182.51 273.75 273.76 wl];
clear x
for n = 1:p;
x(n,:) = (n-1)*(wl+0.1) + x1;
end
counter = 0;
for j=1:p
for i=1:8
counter = counter+1;
xnew(counter) = x(j,i);
end
end
y1 = [500 500 1500 1500 500 500 0 0];
clear y
for n = 1:p;
y(n,:) = y1;
end
counter = 0;
for j = 1:p
for i = 1:8
counter = counter+1;
ynew(counter) = y(j,i);
end
end
w = y(1,:);
for l = 2:p
w = [w y(l,:)];
end
v = x(1,:);
for q = 2:p
v = [v x(q,:)];
end
mug = pchip(v,w,t);
参数K
是:
x1 = [0 91.25 91.26 182.5 182.51 273.75 273.76 wl];
clear x
for n = 1:p;
x(n,:) = (n-1)*(wl + 0.1) + x1;
end
counter = 0;
for j = 1:p
for i = 1:8
counter = counter + 1;
xnew(counter) = x(j,i);
end
end
%y1 = [8000 8000 27000 27000 8000 8000 6000 6000 ];
%y1 = [8000 8000 12000 12000 8000 8000 6000 6000 ];
y1 = [6000 6000 8000 8000 6000 6000 6000 6000 ];
clear y
for n = 1:p;
y(n,:) = y1;
end
counter = 0;
for j = 1:p
for i = 1:8
counter = counter+1;
ynew(counter) = y(j,i);
end
end
w = y(1,:);
for l = 2:p
w = [w y(l,:)];
end
v = x(1,:);
for q = 2:p
v = [v x(q,:)];
end
Kg = pchip(v,w,t);
,最后一个参数是:
x1 = [0 91.25 91.26 182.5 182.51 273.75 273.76 wl];
clear x
for n=1:p;
x(n,:) = (n-1)*(wl + 0.1) + x1;
end
counter=0;
for j=1:p
for i=1:8
counter=counter+1;
xnew(counter) = x(j,i);
end
end
y1 = [ 0.02272 0.02272 0.04 0.04 0.02272 0.02272 0.005263 0.005263 ];
clear y
for n=1:p;
y(n,:) = y1;
end
counter=0;
for j=1:p
for i=1:8
counter=counter+1;
ynew(counter) = y(j,i);
end
end
w=y(1,:);
for l=2:p
w=[w y(l,:)];
end
v=x(1,:);
for q=2:p
v=[v x(q,:)];
end
d1g = pchip(v,w,t);
您只需查看主要代码并建议我在哪里犯错误。参数代码和ode文件仅适用于希望运行代码以获得更清晰视图的用户。非常感谢你的时间!