Error using lsqcurvefit (line 271) Function value and YDATA sizes are not equal.
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
srcn
el 14 de Sept. de 2021
Comentada: Star Strider
el 22 de Sept. de 2021
Hello everybody. I am new to MATLAB and I'm trying to find the parameters to best fit a model function having experimental points as ti and yi. The main code and functions are:
data = xlsread("Re-analyze.xlsx");
ti = data(:,6);
yi = data(:,7);
R = data(1,1);
T = data(2,1);
Me = data(3,1);
Mn0i = data(4,1);
Vs0 = data(6,1);
Mse = data(7,1);
V0 = data(8,1);
A=((36*pi)^(1/3))*((V0)^(2/3));
X0=[0.72; 28.876; 6568.86;1;1];
save variables_LpPsVb R T A Me V0 A Me Mn0i Vs0 Mse X0
function:
function X = Lp_Ps_Vb (b,t)
load variables_LpPsVb R T A V0 Me Mn0i Vs0 Mse
% % % b(1:3) = Parameters, b(4:5) = Initial Conditions
% % % MAPPING: x(1) = x, x(2) = y, b(1) = Lp, b(2) = Ps, b(3) = Vb
Ddv_Div = @(t,x,b)[((-b(1)*x(1)*A*R*T*Me*Vs0)+ b(1)*x(2)*R*T*A+b(1)*A*R*T*Mn0i*V0*Vs0-b(1)*b(3)*A*R*T*Mn0i*Vs0)/(Vs0*x(1));
(b(2)*x(1)*A*Vs0*Mse*Vs0-b(2)*x(2)*A*Vs0)/(Vs0*x(1))];
[~,X] = ode45(@(t,x) Ddv_Div(t,x,b(1:3)), t, b(4:5));
end
I get this error message:
Error using lsqcurvefit (line 271) Function value and YDATA sizes are not equal.
Unfortunately, I can not see my mistake. What should I try to solve it?
Thank you in advance!
3 comentarios
Respuesta aceptada
Star Strider
el 15 de Sept. de 2021
The ‘Lp_Ps_Vb’ function is going to return ‘X’ that is going to be a (numel(t) x 2) matrix, so lsqcurvefit needs to have a matching matrix of data to compare to it. (The error that was thrown can also occur when rows of data are compared to columns returned by the objective function, or the reverse, however I doubt that is the problem here.)
I am not certain what you are doing, however if you want to fit the system of differential equations to your data, the approach in Coefficient estimation for a system of coupled ODEs will likely work.
It will be necessary to adapt that code to your system. That should not be difficult.
.
12 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Solver Outputs and Iterative Display 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!