search minimum of a parameter function with the constrain that one parameter must be integer

3 visualizaciones (últimos 30 días)
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

Respuesta aceptada

Andrew Newell
Andrew Newell el 31 de Mayo de 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.

Más respuestas (1)

gianluca messina
gianluca messina el 31 de Mayo de 2011
You are right. The only problem now is that I have a second parameter inside the exponential and matlab find it negative, that hasn't any physical meaning. Using lsqcurvefit I don't see a method to superimpose the constrain: parameter > 0.
ps my function is real because i'm taking the square modulus of the summation.
Thank you Gianluca

Categorías

Más información sobre Least Squares en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by