Roots of Polynomial in for Loop
Mostrar comentarios más antiguos
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 comentarios
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
el 2 de En. de 2022
Editada: MarshallSc
el 2 de En. de 2022
MarshallSc
el 2 de En. de 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.
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Solver Outputs and Iterative Display en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!