1
votes

I am trying to fit function F to experimental data. x_tem and yd are both vectors of size (12,1). The function should find the best fitting value y_tau of the function to the experimental data. I just can't find the mistake - matlab is showing me the error :

Error in lsqcurvefit (line 199)
initVals.F = feval(funfcn_x_xdata{3},xCurrent,XDATA,varargin{:});

Caused by: Failure in initial user-supplied objective function evaluation. LSQCURVEFIT cannot continue.

The code is:

x_tem=Temp_aero_korrektur(:,1);
yd=Temp_aero_korrektur(:,2);

F = @(y_tau,x_tem)((-1)*((273.15-x_tem)*(273.15-y_tau(1))*8.314*    (((17.62*x_tem)/(243.12+x_tem))-((17.62*y_tau(1))/(243.12+y_tau(1)))))/(40714.53)); 

yd_tau = lsqcurvefit(F,-40,x_tem,yd);
1

1 Answers

1
votes

There are two possibilities here. One is that you do actually want to use matrix operations in your objective function (so that, for example, x_tem/x_tem gives a single scalar value using mrdivide). If this is the case then you should be calling lsqcurvefit with the transpose of x_tem

yd_tau = lsqcurvefit(F,-40,x_tem',yd);

The other option is that you actually meant to calculate your objective function on each value of x_tem (so, for example, using x_tem./x_tem to give a vector the same length as x_tem). If this is the case then your objective function should be

F = @(y_tau,x_tem)((-1)*((273.15-x_tem).*(273.15-y_tau(1)).*8.314.*    (((17.62*x_tem)./(243.12+x_tem))-((17.62*y_tau(1))/(243.12+y_tau(1)))))/(40714.53))

(See documentation for times and rdivide for element-wise operations)