Roots of Polynomial in for Loop

I have these two vectors that are the 2nd and zero order coefficients:
R = [0.0068 0.0036 0.000299 0.0151];
H = [0.0086 0.00453 0.0016 0.00872];
For the equation:
func = @(x) (R - (x * x) * H);
My first question is how can I index each of the elements in the equation such that I have something like this:
func = @(x) (R(i) - (x(j) * x(k)) * H(l)) % i,j,k,l = 1:4
So for one index, the equation would be (with many roots):
f1 = @(x) 0.0068 - (x(2)*x(3) * 0.00872); % R(1) - x(2)*x(3) * H(4);
x0 = [0,0];
solve = fzero(f1,x0)
So writing all the equations, and using quadratic optimization for the simultaneous equations, the roots can be found.
But obviously this function handle would not work when indexing is needed. Is there any way to express the equation so that even the independent variable can be indexed? I know there is a way to index other components than the independent such:
for i = 1:4
for j = 1:4
f = sprintf('@(x) %f- (x*x)*%f;', R(i), H(i));
r = str2func(f)
end
end
But I'm looking to index the variables too so that I can finally get the minimum roots of this quadratic equation:
(x(j)*x(k)) * H(l) + (x(i)*x(l)) * H(k) + (x(k)*x(j)) * H(j) + (x(l)*x(i)) * H(i) = ...
R(i) + R(j) + R(k) + R(l)
My objective is to find the roots that minimizes the above equation, by having the coefficient of the quadratic equation that run through a loop (H(i) & R(j) are given). There is not speicifc constraint rather than interchanging the indices of the equation elements to conserve the symmetry and momentum.
I tried to use fmincon but I don't know how to assign the indexed function handle into the function and using random intial complex roots, get all the possible roots.
I posted a similar question but I think I was not very clear in my statement.

5 Comments

Matt J
Matt J on 2 Jan 2022
Edited: Matt J on 2 Jan 2022
But I'm looking to index the variables too so that I can finally optimize this quadratic equation:
All very unclear, I'm afraid. The "equation" that you've shown is, in fact, an inequality. Also, neither equations nor inequalities are something that you optimize. You optimize an objective function, while equalities and inequalities can be your constraints.
I think you should probably reformulate your question, telling us what the objective is, whether you are minimizing or maximizing it, and what the desired constraints are.
MarshallSc
MarshallSc on 2 Jan 2022
Edited: MarshallSc on 2 Jan 2022
Thanks Matt for your answer. Sorry if I was not very clear. I updated my question to be a little bit more clear. I want to find the minimum value of the roots that is shown in the final equation in my post. The information that I have is the coefficients of my polynomial (2nd and zero order) in each dimension and equation, and I want to find the minimum using a proper method.
Matt J
Matt J on 2 Jan 2022
Edited: Matt J on 2 Jan 2022
But I'm looking to index the variables too so that I can finally get the minimum roots of this quadratic equation:
But you have 4 unknown x(i), so the roots of the equation are non-scalar. What does it mean to minimize a non-scalar?
Well, because the roots will give me information about the curvature in the system and my goal was to solve it in a way that gives me the optimum value.
Let's forget about the minimum, sorry if it made confusion, can the roots be found by having such a constraint - which is the (i;j) and (k;l) pair must be exchangeable?
Matt J
Matt J on 2 Jan 2022
Edited: Matt J on 2 Jan 2022
Let's forget about the minimum, sorry if it made confusion, can the roots be found by having such a constraint - which is the (i;j) and (k;l) pair must be exchangeable?
If you mean that you want to solve the simultaneous equations,
then the answer is no. This is an overdetermined system of 256 equations in 4 unknowns, so it will probably not have an exact solution. You could seek a least squares solution, but that would require that you minimize something.

Sign in to comment.

 Accepted Answer

Matt J
Matt J on 2 Jan 2022
Edited: Matt J on 2 Jan 2022
I don't understand your description of the objective function. The roots of a multivariable function are not scalars, and therefore are not something you can "minimize". However, the nonlinear constraint fucntion to fmincon would look like this:
R = [0.0068 0.0036 0.000299 0.0151];
H = [0.0086 0.00453 0.0016 0.00872];
objective=____;
x=fmincon(objective,A,b,Aeq,beq,lb,ub,@(x) nonlcon(x,R,H) , options)
function [c,ceq]=nonlcon(x,H,R)
c=[];
[i,j,k,l]=ndgrid(1:4);
ceq=(x(j).*x(k)) .* H(l) + (x(i).*x(l)) .* H(k) + (x(k).*x(j)) .* H(j) +...
(x(l).*x(i)) ,* H(i) - R(i) + R(j) + R(k) + R(l);
end

6 Comments

Thanks Matt for the answer. This is very helpful but not exactly what I'm looking for. My objective function changes based on the indices. For example, choosing i = 1, j = 2, k = 3 and l = 4. the objective function would be:
f = @(x) R(1) - x(2) * x(3) * H(4); %or f = @(x) 0.0068 - 0.00872 * x(2) * x(3);
So obviously it cannot have an explicit solution and will change based on the chosen initial value. As the indices change, the function will change itself. I'm not sure fmincon is the best tool for such an objective, I wanted to know others opinion to see what they suggest that can be the best solution.
I think that you are using abusing terminology, which is making it hard to know what you want. An "objective function" is something you are minimizing, so if you are minimzing,
f = @(x) 0.0068 - 0.00872 * x(2) * x(3)
then the solution is explicit. The explicit solution is any x with x(2)*x(3)=inf, since that will push f to -inf. Very trivial.
If instead you mean you are trying to find the root of f, that also has an explicit, trivial solution which is x(2)*x(3)=0.0068/0.00872. Since you have 2 unknowns in a single equation, the root is not defined any better than this.
Perhaps you mean that you are trying to solve the simultaneous system of equations,
(R(i) - (x(j) * x(k)) * H(l)) = 0 i,j,k,l=1...4
To convert this system of equations to a minimization problem, you would normally propose to minimize the objective function,
but note that this would not be a quadratic minimization problem, as you described it in your post. The objective function here is a degree 4 polynomial, not a quadratic.
Finally, there is this equation,
(x(j)*x(k)) * H(l) + (x(i)*x(l)) * H(k) + (x(k)*x(j)) * H(j) + (x(l)*x(i)) * H(i) = ...
R(i) + R(j) + R(k) + R(l)
Because you do not distinguish clearly between minimization and root-finding in your terminology, I am not sure what you are trying to do with it. Perhaps you thought that solving this equation is equivalent to solving the original simultaneous system,
(R(i) - (x(j) * x(k)) * H(l)) = 0 i,j,k,l=1...4
but that is not the case.
Thanks a lot Matt for your thorough feedback. Sorry if it caused confusion. Yes, the two equations are different, but I wanted to note that to say where this equation comes from (translated version of the original one) which is the one that I'm trying to solve:
(x(j)*x(k)) * H(l) + (x(i)*x(l)) * H(k) + (x(k)*x(j)) * H(j) + (x(l)*x(i)) * H(i) = ...
R(i) + R(j) + R(k) + R(l)
This equation comes from:
(R(i) - (x(j) * x(k)) * H(l)) = 0 i,j,k,l=1...4
By applying the symmetry requirements and basically interchanging (i;j) and (k;l) pair; the components are the same only the indices change. It essentially says that the only allowable roots are the ones that conserve the symmetry requirement that's why it gets translated into the bigger equation.
What I'm looking to do is to, as you mentioned, is to minimize the roots of this equations (translated version), that's why I was looking at optimization methods to minimze the roots of the function. Is there any method that can be used to solve this equation? This equation has 2^dimsize number of roots (2^4 = 16) in each dimension - 8 are complex and 8 are complex conjugate.
For example, if we choose an arbitrary index for each component, it will be something like this:
(x(2)*x(3)) * H(4) + (x(1)*x(4)) * H(3) + (x(3)*x(2)) * H(2) + (x(4)*x(1)) * H(1) = ...
R(1) + R(2) + R(3) + R(4)
Or:
(x(2)*x(3)) * H(4) + (x(1)*x(4)) * H(3) + (x(3)*x(2)) * H(2) + (x(4)*x(1)) * H(1) - ( R(1) + R(2) + R(3) + R(4))=0
Basically, i,j,k,l float from 1 to 4 in each sequence. Is there a way that I can find the roots for this equation?
Matt J
Matt J on 2 Jan 2022
Edited: Matt J on 2 Jan 2022
Similar to my comment above,
this appears to be a system of 256 equations in 4 unknowns. It will likely have no exact simultaneous roots.
Can we write a code that would minimizes the solutions of overdetermined system of equations with 256 equations and 4 unknowns?
The set of solutions of an overdetermined system will typically be empty. If so, there are no solutions to minimize over.

Sign in to comment.

More Answers (0)

Asked:

on 2 Jan 2022

Commented:

on 2 Jan 2022

Community Treasure Hunt

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

Start Hunting!