5 views (last 30 days)

SK
on 29 Oct 2014

Edited: SK
on 30 Oct 2014

Since A is non-singular, we can write (warning: below is math, not code)

M = A + s*D

=> M/A = I + sD/A (where D/A stands for D*inv(A))

=> lambda*M/A = lambda*I - D/A (where lambda = -1/s)

Therefore you need to solve the eigenvalue problem:

(lambda*I - D/A)*v = 0

for lambda. You can find lambda using:

lambda = eig(D/A)

setting s = -1./lambda, you have n solutions (with multiplicity) for d = 0, where n is the size of A.

NOTE: Don't try to find eigen vectors (you dont need them here anyway) using Matlab's eig(), since it wont work if eigenvalues are repeated.

Now for non-zero d, we want:

d/det(A) = det(I + s*D/A)

since det(D/A) = product(lambda), we have to choose s so that

product_over_i(1 + s*lambda(i)) = d/det(A)

So your "short-cut" procedure is:

1. Find vector of eigenvalues, lambda, of D/A

2. Solve prod(1 + s*lambda) = d/det(A)

(1) should not be a problem even for very large matrices.

I'm not sure about (2) unless n is not too large. You could try the roots() or fzero() functions in Matlab. Note that if you use roots(), you will have to compute the coefficients of the polynomial first from the product in (2) and you may lose a lot of precision in computing the coefficients themselves. I think it would be better to use fzero().

Also note that there are n solutions in general, so you'll have to find a way to choose the solution based on your needs and also make an appropriate initial guess.

[edited to correct sign error].

SK
on 31 Oct 2014

OK. I guess you mean:

r = roots( [-d/det(A),zeros(1,size(A,1))] + poly(D*inv(A)) );

D = rand(5);

A = rand(5);

d = 1;

lambda = eig(D/A);

c = d/det(A);

hcx2vec = @(F) [real(F); imag(F)];

hfunc = @(s) hcx2vec(prod(1 + complex(s(1), s(2))*lambda) - c);

s_init = -1/lambda(1);

s = fsolve(hfunc, hcx2vec(s_init));

Check:

det(A + complex(s(1), s(2))*D)

You could also choose s_init to be say -1/lambda(i) for any i.

I just mention it because as the matrix A gets larger, its determinant can become huge or tiny resulting in unacceptable loss of precision very quickly. For example, with A = rand(50), you still get acceptable results, but with A = rand(100), you have no chance. With fsolve you can tweak the tolerances - so it may help. Perhaps it is also possible to scale/normalize the problem in some way.

Regards.

Roger Stafford
on 30 Oct 2014

If d is real and only real roots are being sought for s, you can simply write a function that accepts a scalar value s and computes det(A+s*D)-d, and then call on matlab's 'fzero' to adjust s to seek a zero value.

If d is complex or you are also seeking complex roots, you can instead call on 'fsolve', calling on your function with the separate real and imaginary parts of s and giving the separate real and imaginary parts of det(A+s*D)-d as a result.

Note that in general there will be n solutions to your equation where your matrices are n-by-n in size, since your equation is actually an nth-degree polynomial equation in s. However, it does not look easy to compute the coefficients of such a polynomial, so it would be difficult to use the 'roots' function.

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

Start Hunting!
## 9 Comments

## Direct link to this comment

https://la.mathworks.com/matlabcentral/answers/160481-find-s-such-that-det-a-s-d-d#comment_246271

⋮## Direct link to this comment

https://la.mathworks.com/matlabcentral/answers/160481-find-s-such-that-det-a-s-d-d#comment_246271

## Direct link to this comment

https://la.mathworks.com/matlabcentral/answers/160481-find-s-such-that-det-a-s-d-d#comment_246505

⋮## Direct link to this comment

https://la.mathworks.com/matlabcentral/answers/160481-find-s-such-that-det-a-s-d-d#comment_246505

## Direct link to this comment

https://la.mathworks.com/matlabcentral/answers/160481-find-s-such-that-det-a-s-d-d#comment_246528

⋮## Direct link to this comment

https://la.mathworks.com/matlabcentral/answers/160481-find-s-such-that-det-a-s-d-d#comment_246528

## Direct link to this comment

https://la.mathworks.com/matlabcentral/answers/160481-find-s-such-that-det-a-s-d-d#comment_246533

⋮## Direct link to this comment

https://la.mathworks.com/matlabcentral/answers/160481-find-s-such-that-det-a-s-d-d#comment_246533

## Direct link to this comment

https://la.mathworks.com/matlabcentral/answers/160481-find-s-such-that-det-a-s-d-d#comment_246609

⋮## Direct link to this comment

https://la.mathworks.com/matlabcentral/answers/160481-find-s-such-that-det-a-s-d-d#comment_246609

## Direct link to this comment

https://la.mathworks.com/matlabcentral/answers/160481-find-s-such-that-det-a-s-d-d#comment_246656

⋮## Direct link to this comment

https://la.mathworks.com/matlabcentral/answers/160481-find-s-such-that-det-a-s-d-d#comment_246656

## Direct link to this comment

https://la.mathworks.com/matlabcentral/answers/160481-find-s-such-that-det-a-s-d-d#comment_246701

⋮## Direct link to this comment

https://la.mathworks.com/matlabcentral/answers/160481-find-s-such-that-det-a-s-d-d#comment_246701

## Direct link to this comment

https://la.mathworks.com/matlabcentral/answers/160481-find-s-such-that-det-a-s-d-d#comment_246717

⋮## Direct link to this comment

https://la.mathworks.com/matlabcentral/answers/160481-find-s-such-that-det-a-s-d-d#comment_246717

## Direct link to this comment

https://la.mathworks.com/matlabcentral/answers/160481-find-s-such-that-det-a-s-d-d#comment_246856

⋮## Direct link to this comment

https://la.mathworks.com/matlabcentral/answers/160481-find-s-such-that-det-a-s-d-d#comment_246856

Sign in to comment.