Looking for a very fast root finding method in Matlab
Show older comments
I am trying to solve an equation like below in Matlab

ai, bi, and ci are vectors of length 10 and these vectors change through the code. this code has to be executed more than 1 million times. So, the method for finding x must be very fast. I tried the following codes:
method 1:
s=tf('s');%transfer function
sys=0;
for i=1:10
sys =sys+a(i)/(s*b(i)+c(i));
end
[roots1] = zpkdata(sys,'v');
In this case, the for loop takes 0.1 second to be completed on my PC and [roots] = zpkdata(sys,'v');executes in less than 0.005 seconds. So, preparing the equation sys before being solved by zpkdata takes a long time for a million times run in the real case. Seemingly vectorized operation does not work for 'tf' argument type.
Next, I checked the following method: method 2:
syms x
sys=sum(a./(x*b+c));
[roots1]=vpasolve(sys,x)
This symbolic method was again slow and took 0.13 seconds to get executed. Do you know any fast method suitable for my case? Or, do you know a way to prepare sys more quickly in method 1?
Many tnx.
Accepted Answer
More Answers (1)
John D'Errico
on 2 Oct 2020
Edited: John D'Errico
on 2 Oct 2020
Symbolic methods (vpasolve) are NEVER efficient.
But all you have is a rational polynomial. The roots of a rational polynomial are the roots of the numerator polynomial. So compute that, or actually the coefficients of that polynomial. Then call roots. You won't be able to do it more quickly than that.
n = 10;
a = rand(1,n);
b = rand(1,n);
c = rand(1,n);
drop = @(V,ind) V(setdiff(1:length(V),ind));
tic
P = sym(0);
syms x
for i = 1:n;
P = P + a(i) * prod(x*drop(b,i) + drop(c,i));
end
toc
roots(sym2poly(P))
ans =
-2.8076
-2.0032
-1.3514
-1.2919
-1.0956
-0.86728
-0.40917
-0.29335
-0.029945
But again, this uses symbolic computations. Instead, we should build the coefficients directly.
Categories
Find more on Stability Analysis in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!