1

I am trying to fit a curve using the create fit option. I am using teh NonlinearLeastSquares method I have attached the code below. I am trying to call the create fit using a function as mentioned below.

Here z_f1 and y_f1 are matrices of order 1x101, p has a value of 0.0080. When I run the code it throws an error:

Complex value computed by model function, fitting cannot continue.
Try using or tightening upper and lower bounds on coefficients.

function [fitresult, gof] = createFit_zk_u20_20141113(z_f1, y_f1, p)
[xData, yData] = prepareCurveData( z_f1, y_f1 );
fnc = ['f_ort+sqrt(x_sch^2-l_ort^2)*tan(alpha_ort)+' num2str(p)    
'*asin(l_ort/x_sch)'];
ft = fittype( fnc, 'independent', 'x_sch', 'dependent', 'z_sch' );
opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
opts.Display = 'Off';
opts.StartPoint = [0.0357116785741896 0.000849129305868777 
0.000933993247757551];
% Fit model to data.
[fitresult, gof] = fit( xData, yData, ft, opts );
Cœur
  • 37,241
  • 25
  • 195
  • 267

0 Answers0