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:
%%% 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?