fminsearch for complex input for curve fitting
10 views (last 30 days)
Show older comments
Dear all, I would like to fit experimental data with custom equations. I aim for the best fit of the theoretical curve to the experimental data by minimizing the residuals and use fminsearch to find minimal error.
The attached code works well for the real inputs
[R, fval] = fminsearch(err, 2.11)% finds the minimum of err But it fails for the
[R, fval] = fminsearch(err, 2.0-0.064i)
Help for fminsearch suggests to input split into real, imaginary parts and work to obtain the best fit. I have a little idea of doing this.
Could somebody help me with this problem? Thanks all.
Answers (2)
Matt J
on 23 Oct 2014
Edited: Matt J
on 23 Oct 2014
Assuming your err function is real-valued,
[R, fval] = fminsearch(@(x) err( complex( x(1),x(2) ) ), [2.0,0.064])
4 Comments
Matt J
on 28 Oct 2014
The objective function must be a mapping from reals to reals. The initial guess x0 must also be real. So, complex(2.11,-0.064) is not legal as an initial point.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!