Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: lsqcurvefit using multistart
Replies: 3   Last Post: Jun 5, 2014 12:09 PM

 Messages: [ Previous | Next ]
 James Posts: 2 Registered: 7/30/13
lsqcurvefit using multistart
Posted: Jul 30, 2013 2:32 PM

I'm not sure if this is a misunderstanding on my end, but I had a frustrating morning getting lsqcurvefit working with the multistart function.

I'm doing an inverse FE analysis to fit some material constants to experimental data. To do the fit, I'm using lsqcurvefit and calling my external finite element code in the fit function.

Everything seems to be working correctly, I can accurately fit the simulated data to the experimental data. However, I want to use the multistart function to reduce the dependence on the initial guess.

I have created the code below to run the analysis with the lsqcurvefit algorithm:

[param,resnorm] = lsqcurvefit(@fit_function,initial_guess,xdata,ydata,lb,ub,options);

%%% fit function
function ydata = fit_function(x,xdata)

write_input_file(x);
system('./mainexe 1>NULL');
ydata = get_input_file();
%%% fit function

I change the code to use the multistart function:
problem = createOptimProblem('lsqcurvefit','x0',initial_guess,'objective',@fit_function...
,'xdata',xdata','ydata',ydata,'options',options);
ms=MultiStart;
[param,resnorm] = run(ms,problem,5);

Running the code, I get the following error after the first step:
??? Error using ==> lsqcurvefit at 253
Function value and YDATA sizes are incommensurate.

A little detective work shows that the while xdata is a 1xn vector, ydata is a nx1 vector. I need to add the following line to the end of my fit function to get the code to work correctly:
ydata=ydata';

Why does the code work without this change when using the lsqcurvefit function but not when using the multistart algorithm?

Date Subject Author
7/30/13 James
7/30/13 Marc
7/31/13 James
6/5/14 Maik