1

I am trying to solve an equation like below in Matlab the series (equation) to be solved for x

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');
 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 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 time 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.

Behnam
  • 41
  • 2
  • 1
    Don't solve it symbolically, solve it numerically. Unless you want to solve it symbolically with `a`, `b` and `c` being symbols that you can then substitute by numbers to get your `x`. – Cris Luengo Oct 02 '20 at 16:49
  • have you considered to write a [function handle](https://www.mathworks.com/help/matlab/matlab_prog/creating-a-function-handle.html) to the function and use the [fzero](https://www.mathworks.com/help/matlab/ref/fzero.html) or [fsolve](https://www.mathworks.com/help/optim/ug/fsolve.html) functions to solve it? I would start with the fzero function, as this is a univariate function, but the fsolve function [has some more options](https://stackoverflow.com/questions/5846939/difference-between-fzero-and-fsolve-for-one-variable) you can try to change in the code. – Thales Oct 03 '20 at 00:26
  • as far as I know, fzero and fsolve converge to one root based on the initial guess. I need all roots of the equation in a specified range. All of the roots must be analyzed next to choose from. – Behnam Oct 03 '20 at 07:02

0 Answers0