Roots of Polynomial in for Loop

10 visualizaciones (últimos 30 días)
MarshallSc el 2 de En. de 2022
Comentada: Matt J el 2 de En. de 2022
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)
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
Matt J
Matt J el 2 de En. de 2022
Editada: Matt J 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.

Iniciar sesión para comentar.

Respuesta aceptada

Matt J
Matt J el 2 de En. de 2022
Editada: Matt J el 2 de En. de 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];
x=fmincon(objective,A,b,Aeq,beq,lb,ub,@(x) nonlcon(x,R,H) , options)
function [c,ceq]=nonlcon(x,H,R)
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);
  6 comentarios
Matt J
Matt J el 2 de En. de 2022
The set of solutions of an overdetermined system will typically be empty. If so, there are no solutions to minimize over.

Iniciar sesión para comentar.

Más respuestas (0)


Más información sobre Systems of Nonlinear Equations 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