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

조회 수: 1 (최근 30일)
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?

채택된 답변

Matt J
Matt J 2019년 2월 8일
Evaluate fun(X_0') adn make sure that its output has the same size as V_data.
  댓글 수: 7
Matt J
Matt J 2019년 2월 8일
What did you do differently from when it was working?
Matthew Hunt
Matthew Hunt 2019년 2월 8일
It never worked. There was just one error after another.
Mat

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Downloads에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by