search minimum of a parameter function with the constrain that one parameter must be integer
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Akzeptierte Antwort
Andrew Newell
am 31 Mai 2011
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 Kommentare
Weitere Antworten (1)
Siehe auch
Kategorien
Mehr zu Least Squares finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!