Error using lsqcurvefit (line 271) Function value and YDATA sizes are not equal.

5 Ansichten (letzte 30 Tage)
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 Kommentare
Matt J
Matt J am 18 Sep. 2021
@srcn The error is thrown by lsqcurvefit, but you haven't posted the code where lsqcurvefit is called - we can't see how it's being used.
srcn
srcn am 18 Sep. 2021
so sorry. I wrote it in the comments below but forgot to add it here.
You can find corrected code : updated code

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Star Strider
Star Strider am 15 Sep. 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 Kommentare
srcn
srcn am 22 Sep. 2021
Hi Star Strider,
It took me a long time to answer because I was doing experiments to use in this analysis.
I made a few additions and modified the code. Now it is working somehow.
I really do appreciate your wisdom on all of this. Thank you for all you have done.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by