Error:'Assignment has more non-singleton rhs dimensions than non-singleton subscripts' in ODE parameter estimation
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello All,
I'm trying to estimate parameters for an ODE system and I'm getting these errors:
'Assignment has more non-singleton rhs dimensions than non-singleton subscripts'
'Error in fminsearch (line 200) fv(:,1) = funfcn(x,varargin{:})';
'Error in kest (line 17) k_est = fminsearch(@estimation, k0)';
Here the function
function kest
k0=[1 5.6 21 4 0.1 5 1.5 2 0.1 5.5 0.0001];
y0h=[10 10 0.1025 0.15 0.15 0.1 0.01];
Time=[0.0020 0.0270 0.0460 0.1810 0.2210 0.3480 0.3640 0.3920 0.3920 0.4093];
tspan = [0 1];
%experimental data
ydataC=[9.75,10,1.0252,0.15,0.102522,0.102522,0.014752;8.6,15.33,1.567,0.23,0.10219,0.10219,0.01482;8.30,20.97,2.145,0.23,0.10230,0.1023,0.01108;6.8,97.33,9.905,0.41,0.10176,0.101761,0.00426;5,114.67,11.7344,0.50,0.1023,0.1023,0.00436;0.80,202.66,21.111,0.65,0.1042,0.1042,0.0032;1.030,198,20.669,0.65,0.104,0.104,0.00327;1.030,196.66,20.5302,0.65,0.104,0.104,0.00327;1.030,196.66,20.530,0.65,0.104,0.104,0.0033;1.03,190.66,19.90,0.65,0.104,0.104,0.00329];
k_est = fminsearch(@estimation, k0);
function e = estimation(k0)
sol = ode15s(@model, tspan, y0h,[],k0);
y_hat = deval(sol, Time);
e = sum((y_hat' - ydataC).^2);
end
end
function dydt = model(~,y,k)
dydt(1) = -k(1)*(y(1))*y(2)/(k(2)+y(1)+0.01*y(6)^1.2);
dydt(2) = k(3)*y(1)*y(2)/(k(2)+y(1)+0.1*y(6)^4)+0.02*0.26*y(5)*y(2)*y(1);
dydt(3) = (k(4)*y(1)*y(2)/(k(5)+0.9*y(1))-2*k(6)*y(3)*y(4)*y(2)/(k(7)+y(3)*y(4)))*heaviside(y(3)-1e-4);
dydt(4) = k(10)*y(1)*y(2)/(k(11)+y(1))- 2*k(8)*y(3)*y(4)*y(2)/(k(9)+y(3)*y(4))-0.023*y(5)*y(2)*y(1);
if (y(1)>0.3)
dydt(5)= 2000*y(3)/y(2);
else
dydt(5)= -500*y(5);
end
if (y(1)>0.3)
dydt(6)= 600*y(3)/y(2);
else
dydt(6)= -10*y(6);
end
dydt(7)= 1*y(5)*y(2)-0.2*y(7)*y(2);
end
The function @model runs well with ode15s, and it calculates 'e' for the first run, but I don't understand why it's giving the error message.
Any suggestions?
Thank you,
0 comentarios
Respuestas (1)
Torsten
el 24 de Sept. de 2018
1. The number of elements in yDataC and yhat must be the same.
2. In model, dydt must be a column vector, not a row vector.
Best wishes
Torsten.
0 comentarios
Ver también
Categorías
Más información sobre Numerical Integration and Differential Equations en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!