Which solver can be used for a non linear curve fitting with some variables being constrained to integers?

1 次查看(过去 30 天)
I have a non linear curve fitting problem, say e^(x1+x2)-y=0, where x1,x2 are variables and y is the data against which fitting is done. Here x1 should be an integer and x2 can be a non integer. Which solver can handle such problems?

采纳的回答

Alan Weiss
Alan Weiss 2016-8-23
If you really have the equation you gave as an example, then I would use
x = x1 + x2
meaning just fit a continuous x variable, and afterwards take
x1 = floor(x);
x2 = x - x1;
If, however, you have a general nonlinear fit with a variable constrained to be integer-valued, then the first thing that I would try is to fit it using any method you like, such as lsqcurvefit, but with no integer constraint. Then I would solve a set of problems with the integer variable set to various values close to the continuous solution.
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation
  7 个评论
Walter Roberson
Walter Roberson 2016-8-27
Why is x(2)=3 a better solution than x(2)=1 or x(2)=2 ? All three of those lead to the same basic x(1) = 2 * log(5) - x(2) which meets the constraint on x(1) provided x(2) is no more than 3. There is no way for ga to tell the solutions apart.
If you are wanting to minimize x(1) such that exp(x(1)+ z(x(2)))-25=0 then you should be using gamultiobj and using x(1) as one of the objectives and (exp(x(1)+ z(x(2)))-25).^2 as your other objective.
Thanigaivel Raja T
Thanigaivel Raja T 2016-8-28
编辑:Thanigaivel Raja T 2016-8-28
Thanks you very much Walter. I just gave one of the possible solutions x(1)=.21887,x(2)=3, it was not a necessary solution for me. Sorry for being unclear on my part. As you suggested, upon squaring the objective function I get Fval in order e^-21.
I actually want to do a non linear curve fitting, as I mentioned in my first question. So how to use ga, to fit an array of values i.e, from previous example, if:
z=[1,2,3,4,5,6,7,8,9];
y=[25,50,75,100,125,150,175,200,225];
fn=@(x)[(exp(x(1)+z(1:x(2)))-y(1:x(2)))^2;(exp(z(x(2):9))-y(x(2):9))^2]
[P1,Fval,exitFlag,Output]=ga(fn,2,[],[],[],[],[0,1],[Inf,9],[],2)
How to use ga for such a problem? I get errors when I solve this. Thanks in advance.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Solver Outputs and Iterative Display 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by