Multivariate Horner scheme implementation in MATLAB
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Mohammad Shojaei Arani
el 6 de Mzo. de 2022
Comentada: Mohammad Shojaei Arani
el 7 de Mzo. de 2022
Hello friends!
I have very long symbolic expressions (mainly polynomials or rational types) and I need to evaluate them many many times. Therefore,
in order to reduce the computational time I would like to re-write my expressions by their equivalent horner form. For instance, the expression
needs f=2*x^3-3*x^2+6*x-5 requires 8 multiplications and 3 additions while its following horner equivalent requires only 3 multiplications and 3 additions:
>> horner(f,x)
ans =
x*(x*(2*x - 3) + 6) - 5
Unfortunately, matlab only supports a univariate horner scheme. But, my expressions are multivariate and I need a multivariate Horner scheme
to simplify my long multivariate expressions. For instance, consider the following bi-variate expression:
syms x y
f = x^2+2*x*y+y^2;
If I go for a uni-variate Horner scheme then I get
>> horner(f,x)
ans =
x*(x + 2*y) + y^2
which requires less multiplications. This is, of course, an improvement. But, this is not the best improvement. A bi-variate Horner scheme
should give us (x+y)^2 as the best representation which needs only 2 arithmatics!
So, in sum, I need a matlab code which can implement a multivariate Horner scheme. I could find a python code but nothing in matlab. Unfortunately, I do not know python very well and really need a matlab code.
Any help is GREATLY appreciated!
Thanks in advance,
Babak
7 comentarios
Torsten
el 6 de Mzo. de 2022
A multivariate Horner scheme under MATLAB does not exist.
And the package under Python also will not be useful for your purpose because it can only handle very basic cases. But you have unstructured and very long expressions as you wrote.
So I think you will have to be satisfied with what MATLAB can offer, namely "matlabFunction". Or you can completely restructure your code to numerical, not symbolic computation (which I would recommend).
Respuestas (0)
Ver también
Categorías
Más información sobre Data Type Conversion en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!