Can integer GA + lsqlin be used to solve an equation, when results provided by integer GA alone is not reliable?

2 views (last 30 days)
Below is a linear equation(A1) with two variables(z(1),z(2)). Of the two variables, one variable(z(1)) being an index is constrained to integers.
A1= @(z) sum(([-y(1:z(1)-1).'*z(2)/Mo-d2y_dt2e(1:z(1)-1).';
-y(z(1):z(1)+Ts-1-Tc).'*z(2)/Mo-F(Tc:Ts-1).'/Mo-d2y_dt2e(z(1):z(1)+Ts-1-Tc).';
-y(z(1)+Ts-Tc:130).'*z(2)/Mo-d2y_dt2e(z(1)+Ts-Tc:130).']).^2);
Method1:
I have used integer ga to solve the equation.
[B1,fval,exitflag]=ga(A1,2,[],[],[],[],[30,0],[60,Inf],[],1,optimset('TolFun',1e-6,'TolCon',1e-3,'Display','off'));
But using GA, only bounds for the variables could be set and but the start point for the variables cannot be set. Especially with bounds for second variable being 0 to Inf, I get a undesirable value as solution for the second variable.
Hence I thought to solve the equation in two parts.
Method2:
First find only z(1) using integer ga, with value of z(2) being supplied with its start point value.
Then solve for z(2) using lsqlin.
But I'm puzzled if it is right to solve this way. And whether it will be inaccurate. So I want to know whether I can go with method 2?

Answers (3)

Alan Weiss
Alan Weiss on 22 Sep 2016
Why do you think that "start point for the variables cannot be set?" ga has an option called InitialPopulation (or in the latest versions InitialPopulationMatrix) that allows you to set the "start point" (initial population for ga).
Then again, I am not sure why you are solving things this way. Why use ga at all? Simply run through the possible values of z(1), solving for z(2) using lsqlin or any other solver. I'm sure that the result will be faster and more reliable than what you'd get using ga.
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation

John D'Errico
John D'Errico on 22 Sep 2016
Edited: John D'Errico on 22 Sep 2016
This is NOT a linear equation. lsqlin requires linearity. But once you make it conditional on the value of z(1), it appears to be linear in z(2).
LSQLIN does not allow integer constraints.
Anyway, why would you bother to use a solver here? Just use a loop on the value of z(1). Choose the value for z(1) that yields the best result. WTP?
As well, GA is wild overkill for one integer variable (that probably will never be too large.) Or use some simple scheme like a bisection to find the best z(1).
Then, conditional on your choice of z(1), this appears to generate a linear problem in z(2). Since you claim that the only constraint on z(2) is positivity, then just use lsqnonneg.
help lsqnonneg
It seems like you are making your problem overly complex, trying to use sophisticated tools where simpler ones are far better employed.

Matt J
Matt J on 22 Sep 2016
Edited: Matt J on 22 Sep 2016
You can set the InitialPopulationRange option to specify bounds on the initial population.
Like the others have been saying, I think this can be solved by exhaustive search over z(1), but I would not even use lsqnonneg or lsqlin to eliminate z(2). For fixed z(1), the function reduces to a 1D quadratic in z(2) on the interval [0,inf]. So, the minimizing value has to be either at z(2)=0 or the unconstrained solution of z(2) which is easy to calculate analytically. Evaluate the function at both points and take the best one.

Community Treasure Hunt

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

Start Hunting!