J
JustSomeGuy
I have a routine that evaluates a polynomial equation that have 3 variables
x,y,z of orders 1,2,3 the coefficients of the polynomial are in an array.
This routine is quite slow and I'd like to optimize it.
Any suggestions?
simply put pts is a vector of
typdef struct
double x;
double y;
double z;
double val;
} vect
xorder, yorder and zorder are the maximum polynomial exponents for an
equation
like val = fn(x,y,z).
void EvaluatePoly(Vector<vect> & pts, int xorder, int yorder, int
zorder)
{
for (int pn=0; pn < pts.length(); ++pn)
{
int cn=0;
for (int k=0; k <= zorder; ++k)
{
float zexp = pow(pts[pn].z, k);
for (int j=0; j <= yorder; ++j)
{
float zyexp = zexp * pow(pts[pn].y, j);
for (int i=0; i <= xorder; ++i)
{
pts[pn].val = c[cn++] * pow(pts[pn].x, i) * zyexp;
}
}
}
}
}
x,y,z of orders 1,2,3 the coefficients of the polynomial are in an array.
This routine is quite slow and I'd like to optimize it.
Any suggestions?
simply put pts is a vector of
typdef struct
double x;
double y;
double z;
double val;
} vect
xorder, yorder and zorder are the maximum polynomial exponents for an
equation
like val = fn(x,y,z).
void EvaluatePoly(Vector<vect> & pts, int xorder, int yorder, int
zorder)
{
for (int pn=0; pn < pts.length(); ++pn)
{
int cn=0;
for (int k=0; k <= zorder; ++k)
{
float zexp = pow(pts[pn].z, k);
for (int j=0; j <= yorder; ++j)
{
float zyexp = zexp * pow(pts[pn].y, j);
for (int i=0; i <= xorder; ++i)
{
pts[pn].val = c[cn++] * pow(pts[pn].x, i) * zyexp;
}
}
}
}
}