Roots of Polynomial in for Loop

5 ビュー (過去 30 日間)
MarshallSc
MarshallSc 2022 年 1 月 2 日
コメント済み: Matt J 2022 年 1 月 2 日
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 件のコメント
MarshallSc
MarshallSc 2022 年 1 月 2 日
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 2022 年 1 月 2 日
編集済み: Matt J 2022 年 1 月 2 日
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.

サインインしてコメントする。

採用された回答

Matt J
Matt J 2022 年 1 月 2 日
編集済み: Matt J 2022 年 1 月 2 日
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 件のコメント
MarshallSc
MarshallSc 2022 年 1 月 2 日
Can we write a code that would minimizes the solutions of overdetermined system of equations with 256 equations and 4 unknowns?
Matt J
Matt J 2022 年 1 月 2 日
The set of solutions of an overdetermined system will typically be empty. If so, there are no solutions to minimize over.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by