2
votes

I need to be able to find the roots of a couple of polynomials that are almost characteristic functions, but not quite (rather than an eigenvalue, it's more like an eigen-block matrix). The function is defined as a function handle because I don't have analytic expressions for the coefficients on the equation (I could presumably find them but the algebra in my model is already quite messy).

The equations are

charA = @(k1,k2) det([k1*eye(N),zeros(N);zeros(N),k2*eye(N)]*Amatrix - eye(2*N));
charB = @(k1,k2) det([k1*eye(N),zeros(N);zeros(N),k2*eye(N)]*Bmatrix - eye(2*N));

and I need to find all of the roots of each one, since the solution of the system is the pair (k1,k2) that satisfies charA(k1,k2)=0 and charB(k1,k2)=0 (at the moment I'm just trusting that the derivations of these matrices are such that such a solution exists, but for the purpose of this question - finding all of the roots of a polynomial defined in this sort of way - this is unimportant).

Is there any way I can take this function handle and turn it into a matrix of coefficients, or is there a solver for polynomials defined as function handles in Matlab? If it changes anything, the matrices aren't massive but they are 84x84, that is, N=42.

1
Have you considered using roots() or fzero()?SecretAgentMan
@SecretAgentMan The issue with roots (if I understand it properly) is that its inputs are a vector holding the coefficients of the polynomial, which aren't easy to find, and the issue with fzero is that I need to get all of the roots of each function so that I can compare them, and without having a reasonable idea of where they each are, there isn't any guarantee that any reasonable number of multistarts will land me all of the roots rather than converging repeatedly to some subset of the roots.Ste Rose
Do you have the symbolic math toolbox available?Daniel
Thanks for the clarification. I was going to ask if you were open to a multistart approach using fminsearch(). I see your concern.SecretAgentMan
@daniel Are you thinking convert it into a symbolic function and using the root finder for that? I thought of that but I'm not aware of multivariable polynomial root finders for symbolic functions, but that could well just be ignorance.Ste Rose

1 Answers

2
votes

As said Daniel

  • use symbolic math toolbox to build the polynomials
  • Then use solve() to find the roots

The sample code is as follows with N = 2

rng(0)
%Unknowns
syms k1 k2
N = 2;
Amatrix = rand(2*N);
Bmatrix = rand(2*N);

charA = det([k1*eye(N),zeros(N);zeros(N),k2*eye(N)]*Amatrix - eye(2*N));
charB = det([k1*eye(N),zeros(N);zeros(N),k2*eye(N)]*Bmatrix - eye(2*N));

% solver 
solution = solve(charA == 0, charB == 0);

% Convert syms to numeric, specifying precision as 3 
k1_solution = vpa(solution.k1, 3)
k2_solution = vpa(solution.k2, 3)

% Only real solution
k1_solution_real = vpa(k1_solution(k1_solution == real(k1_solution)), 3)
k2_solution_real = vpa(k2_solution(k2_solution == real(k2_solution)), 3)

Solution

  • All
k1_solution =

          0.475
          -2.52
         0.0161
 - 1.58 + 1.79i
 - 1.6 - 1.79i
 - 2.0 - 0.863i
 - 2.0 + 0.865i
           11.2


k2_solution =

            0.345
           -0.869
            0.946
 - 1.37 + 0.0219i
 - 1.37 - 0.0219i
     1.69 + 3.24i
     1.69 - 3.24i
            -5.65
  • Real only
k1_solution_real =

  0.475
  -2.52
 0.0161
   11.2


k2_solution_real =

  0.345
 -0.869
  0.946
  -5.65
  • First root solution
k1 = 0.475 and k2 = 0.345