search minimum of a parameter function with the constrain that one parameter must be integer
조회 수: 4 (최근 30일)
이전 댓글 표시
Hi,
I'm looking for the minimum of sum((f(x)-data(x))^2), where f(x)= (sum(exp(1i .* x .* jz))).^2 where jz = 1,2,...nz and nz is my integer parameter and data(x). So f is function of x while (sum(f(x)-data(x)))^2 is function of nz.
I think I have to use fmincon, but I don't find the syntax to tell MatLab that the constrain is nz = integer.
I'm using this approach beacuse I wasn't able to use lsqcurvefit because when I run the summation to evaluate f(x) matlab doesn't understand tha f is function of x and gives an indexes error.
Many thanks
Gianluca
댓글 수: 0
채택된 답변
Andrew Newell
2011년 5월 31일
This is an integer programming problem, and MATLAB does not have a function for that (although the FEX does have code for solving linear or quadratic mixed integer problems). However, you could cheat. Since your sum is equal to (a^(p+1)-a)/(a-1), where a = exp(1i*x), you could treat p as a real variable, fit it, then round off the answer.
Given the way you formulated the minimum (your f(x) being the square of a function g(x), and minimizing sum(g(x)^2-data^2), you are fitting the modulus of g(x) to the data, where g(x) is your sum of exponentials. I will generate some sample data assuming the integer is 6:
xdata = rand(100,1); n = 6;
a = cos(xdata);
ydata = abs((a.^(n+1)-a)./(a-1)) + 0.1*randn(size(xdata)); %Add some noise
Now define the function to fit
fun = @(p,x) abs((x.^(p+1)-x)./(x-1));
Fit to the data:
p0 = 3;
p = lsqcurvefit(fun,p0,cos(xdata),ydata);
p = round(p)
p =
6
If you want to put some constraints on your parameters, see the fields lb and ub in the structure options in the documentation for lsqcurvefit.
Note: revised to take into account new information.
댓글 수: 0
추가 답변 (1개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Least Squares에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!