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

I am using the following code:
%Import data as time and voltage:
load VoltageData.mat;
load('OCP_Cathode.mat'); %Load the OCP data for the cathode
load('OCP_aNODE.mat'); %Load OCP data for the anode;
SOC_a=OCP_Anode(:,1);
SOC_c=OCP_Cathode(:,1);
OCV_a=flip(OCP_Anode(:,2));
OCV_c=OCP_Cathode(:,2);
time=VoltageData(:,1);
voltage=VoltageData(:,2);
%Import the applied current data
%Set it to the correct value:
I_app=0.12*ones(1,10);
Time=time/time(end);
%Get the data to be used:
t_data=linspace(0,Time(end),10);
L=length(Time);
V_data=interp1(Time,voltage,t_data);
%Choose initial conditions for the parameters:
X_0=zeros(10,1);
X(1)=0.9;
X(2)=0.2;
X(3)=1;
X(4)=1.5;
X(5:end)=10^-6;
X_0=X;
lb=zeros(1,10);
ub=ones(1,10);
%Set up the function for lsqcurvefit:
fun = @(X,t)terminal_voltage(V_data,I_app,mu_n,t_data,X,SOC_a,SOC_c,OCV_c,OCV_a);
x = lsqcurvefit(fun,X_0',t_data,V_data,lb,ub);
The function terminal_voltage is given by:
function V=terminal_voltage(V_exp,I_app,mu_n,t,X,SOC_a,SOC_c,OCV_c,OCV_a)
gamma_plus=X(5);
gamma_minus=X(6);
nu_plus=X(9);
nu_minus=X(10);
SOC_cathode=cathode_c(I_app,mu_n,1,t,X);
SOC_anode=anode_c(I_app,mu_n,1,t,X);
O_plus=interp1(1-SOC_c,OCV_c,SOC_cathode);
O_minus=interp1(SOC_a,OCV_a,SOC_anode);
V=eta_plus(SOC_cathode,I_app,X)-eta_minus(SOC_anode,I_app,X)+O_plus-O_minus-V_exp';
I get the error:
Error using lsqcurvefit (line 262)
Function value and YDATA sizes are not equal.
Error in inverse_SPM (line 49)
x = lsqcurvefit(fun,X_0',t_data,V_data,lb,ub);
I'm not too sure what's going on. How do I check the size of the function value? How do I correct it, so lsqcurvefit works?

 Réponse acceptée

Evaluate fun(X_0') adn make sure that its output has the same size as V_data.

7 commentaires

Okay, now you might be on to something:
I did:
size(V_data)
size(fun(X_0))
and I got the following results:
ans =
1 10
ans =
10 1
Suggesting your suggestion is bang on. What do I change to make these two the same?
Did you figure it out? I assume so, since you accepted the answer.
I did, now I have the following error:
Local minimum possible.
lsqcurvefit stopped because the final change in the sum of squares relative to
its initial value is less than the default value of the function tolerance.
I presume I have to decrease the tolerances on something.
No, it looks like the optimization worked.
I get the following error:
<stopping criteria details>
Error=NaN
Undefined function or variable 't'.
Error in inverse_SPM (line 65)
SOC_anode=anode_c(I_app,mu_n,1,t,X);
How do I make the program continue?
What did you do differently from when it was working?
It never worked. There was just one error after another.
Mat

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

Community Treasure Hunt

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

Start Hunting!

Translated by