The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

This is probably more of a maths question than a programming one, but I can't find a more suitable category.

I'm drawing best fit lines on graphs, and using the information here:

http://misc.connectfree.co.uk/graphs/

That page shows how to calculate the variables for the following lines:

y = a + bx

y = a + bx + cx^2

I've implemented them, and everything works fine. However, now I nee to do the same thing for these lines:

y = a + bx + cx^2 + dx^3

y = a + bx + cx^2 + dx^3 + ex^4

y = ab^x

But I can't find similar equations for calculating the replacements for a-e in those equations. I've found some stuff on the web, but nothing in that kind of format (the "first format" shown - which I can understand, and implement!).

Does anyone know how to calculate these?

I'm drawing best fit lines on graphs, and using the information here:

http://misc.connectfree.co.uk/graphs/

That page shows how to calculate the variables for the following lines:

y = a + bx

y = a + bx + cx^2

I've implemented them, and everything works fine. However, now I nee to do the same thing for these lines:

y = a + bx + cx^2 + dx^3

y = a + bx + cx^2 + dx^3 + ex^4

y = ab^x

But I can't find similar equations for calculating the replacements for a-e in those equations. I've found some stuff on the web, but nothing in that kind of format (the "first format" shown - which I can understand, and implement!).

Does anyone know how to calculate these?

log(y) = x Log(b) + log(a)

As for the other polynomial forms:

http://mathworld.wolfram.com/LeastSquaresFittingPolynomial.html

or

http://www.efunda.com/math/leastsquares/lstsqrmdcurve.cfm

AW

I'm looking for the derived equations, in the format of the first two I have, for calculating a/b/c/d/e for the specific equations listed (similar to the page I noted for the first two). While these pages are more flexible (allowing me to go to the nth degree), I have set requirements, and don't really understand everything on those pages!

Do you know where I can find these already calculated? (I assume the first few must be fairly common?)

log(y) = x Log(b) + log(a)

in Actionscript, but I'm confused by the whole E/natural log thing, and the fact that there doesn't seem to be an "inverse log" method?

The Actionscript Math object is documented here:

http://livedocs.macromedia.com/labs/1/flex20beta3/langref/Math.html

Any ideas how to get y (not log(y)) given x, b and a in:

log(y) = x Log(b) + log(a)

?

I've tried ever combination of Math.log and Math.exp multiplying and dividing by the log constants there too!

if Natural Log (ln (x)) then e^Ln(x)

if Log base 10, then 10^Log(x)

Take the Log of the X's and Y's, then fit the least squares to the Logs, that will give you M and B in the equation Log(y) = M*Log(x) + B

then to get back to the a and b in y = ax^b===> b = 10^M, a = 10^B

AW

y = a + bx + cx^2 + dx^3 + ex^4

is NOT a line - it is a curve.

What you have are a system of polynomials.

As this system is non-linear you can't use linear algebraic techniques to solve it directly without transformations as discussed above.

However there are numerical methods for doing this.

foreach (Point p in points)

{

sumOfProducts += Math.Log(p.X) * Math.Log(p.Y);

sumOfX += Math.Log(p.X);

sumOfY += Math.Log(p.Y);

sumOfSquaresOfX += Math.Log(p.X) * Math.Log(p.X);

sumOfSquaresOfY += Math.Log(p.Y) * Math.Log(p.Y);

}

double count = emps.Count;

B =

((count * sumOfProducts) - (sumOfX * sumOfY))

/

((count * sumOfSquaresOfX) - (sumOfX * sumOfX));

A =

(sumOfY - (B * sumOfX))

/

count;

And then to get Y from X, I have:

return Math.pow(Math.LOG2E, Math.log(A + (B * Math.log(x))))

But the curve is way off (not within area of the graph I'm looking at!). I'm a little confused by the equation with M and B and A and B. Can you see something simple there I've done wrong?

And for the other equations, I don't really understand what your big calculation is for, because it contains a/b/c/d/e, and it's those values that I'm trying to calculate. Once I've got those, it's easy to put them into something like y = a + bx + cx^2 + dx^3 + ex^4 ?

http://misc.connectfree.co.uk/graphs/

That shows how I'm doing it for:

y = a + bx + cx^2

Which is also a curve. I just want to do the same thing for the other equations I gave

a = (sum(y) - b*sum(x) - c*sum(x^2) - d*sum(x^3))/n

b = (n*sum(xy) - sum(x) * sum(y) + c*(sum(x) * sum(x^2) - n*sum(x^3)) + d*(sum(x) * sum(x^3) - n*sum(x^4))/(n*sum(x^2) - (sum(x))^2)

and so on.. The rest is just a little applied algebra, and is actaully quite straight forward. You have already doe essentiall the same thing, in developing you formulae for the 2nd order case. Just apply the same algorithm here, and in the 4th order case.

AW

I don't understand how you got the equations for a and b that you just posted, but that's exactly what I want (a - d, and a - e for the 3rd and 4th order cases)!

n*a + Sum(x) * b + sum(x^2) *c + sum(x^3) * d = sum(y)

now divide both sides by n:

a + Sum(x) * b/n + sum(x^2) *c/n + sum(x^3) * d/n = sum(y)/n

now subtract from both sides leaving only a on the left:

a = (sum(y)- Sum(x) * b - sum(x^2) *c - sum(x^3) * d ) /n

and for the second equation:

sum(x)*a + Sum(x^2) * b + sum(x^3) *c + sum(x^4) * d = sum(xy)

divide both sides by Sum(X^2):

sum(x)*a/Sum(x^2) + b + (sum(x^3)/Sum(x^2)) *c + (sum(x^4)/Sum(x^2)) * d = sum(xy)/Sum(x^2)

now subtract from both sided, leaving the b on the left:

b = sum(xy)/Sum(x^2) -sum(x)*a/Sum(x^2) - (sum(x^3)/Sum(x^2)) *c - (sum(x^4)/Sum(x^2)) * d

and then substitute teh earlier equation for a, and rearrange the terms to get:

b = (n*sum(xy) - sum(x) * sum(y) + c*(sum(x) * sum(x^2) - n*sum(x^3)) + d*(sum(x) * sum(x^3) - n*sum(x^4))/(n*sum(x^2) - (sum(x))^2)

very elementary algebra.

AW

n*a + Sum(x) * b + sum(x^2) *c + sum(x^3) * d = sum(y)

sum(x)*a + Sum(x^2) * b + sum(x^3) *c + sum(x^4) * d = sum(xy)

sum(x^2)*a + Sum(x^3) * b + sum(x^4) *c + sum(x^5) * d = sum(x^2y)

sum(x^3)*a + Sum(x^4) * b + sum(x^5) *c + sum(x^6) * d = sum(x^3y)

as

n*a + A* b + B *c + C * d = Y1

A * a + B * b + C *c + D * d = Y2

B * a + C * b + D *c + E * d = Y3

C * a + D * b + E *c + F * d = Y4

where :

A = Sum(x)

B = Sum(x^2)

C = sum(x^3)

D = sum(x^4)

E = sum(x^5)

F = Sum(x^6)

and

Y1 = sum(y)

Y2 = Sum(x * y)

Y3 = sum(x^2 * y)

Y4 = sum(x^3 * y)

this might make the algebra a bit easier.

AW

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.

n*a + Sum(x) * b + sum(x^2) *c + sum(x^3) * d = sum(y)

sum(x)*a + Sum(x^2) * b + sum(x^3) *c + sum(x^4) * d = sum(xy)

sum(x^2)*a + Sum(x^3) * b + sum(x^4) *c + sum(x^5) * d = sum(x^2y)

sum(x^3)*a + Sum(x^4) * b + sum(x^5) *c + sum(x^6) * d = sum(x^3y)

and when these 4 LINEAR equations are soloved (algebraically), the result is the LEAST SQUARES cubic that best fits the set of data points

and for the 4th order:

n*a + Sum(x) * b + sum(x^2) *c + sum(x^3) * d + sum(x^4) * e= sum(y)

sum(x)*a + Sum(x^2) * b + sum(x^3) *c + sum(x^4) * d + sum(x^5) * e= sum(xy)

sum(x^2)*a + Sum(x^3) * b + sum(x^4) *c + sum(x^5) * d + sum(x^6) * e= sum(x^2y)

sum(x^3)*a + Sum(x^4) * b + sum(x^5) *c + sum(x^6) * d + sum(x^7) * e= sum(x^3y)

sum(x^4)*a + Sum(x^5) * b + sum(x^6) *c + sum(x^7) * d + sum(x^8) * e= sum(x^4y)

which is again a system of linear equations in the 5 unknowns a,b,c,d and e.

AW