Welcome to Gaia! ::


I've got a graph, and I want to put a best-fit line to it. A quadratic best line - not linear.
I've seen a number of modules and functions that can find a y=mx+b equation, but not a y=ax^2+bx+c line.

Any suggestions on how I could do it myself? Or anywhere with a function to do it for me?

I'm thinking that eval() might come in handy...

Edit:
Whoops.

I have a set of data points (no more than 30). I want to find a quadratic best-fit for them, then graph it on the same picture.
I can do the graphing - I just need to find the right numbers first.
Doesn't eval evaluate text as PHP code?If PHP can't do it, eval() can't do it >.>
You're trying to do a parabola, but are you trying to do a graphic, or just output numbers?
Yeah, but the point is it lets me put together a PHP string step by step, then it can be evaluated.
Anyways, the end result is a graph of it, but I can do that easily enough if I have the numbers.
gonk I forgot to say the important bit...

Another edit:
I'll be back in a couple hours to check this...
How could there be a line of best fit for a parabola?

Are you talking about y = -2b/c for the center line?
That's -b/2a if I'm not mistaken.
[-b(+-)sqrt(b^2-4.a.c)]/2a to get the places where it touches X axis (X1, X2)
(x1+x2)/2 OR -b/2a to get the Yv and replace Yv as the X in the ax^2+bx+c equation to get Xv.
same effect.. sometimes razz
Wesker99
How could there be a line of best fit for a parabola?

(Sorry about the late reply)
I want a method to find a quadratic equation that minimizes the difference between the calculated y given an x (what the equation would give) and the actual value of y (the data point).

I can find a simple way to calculate the linear equation, but I want a quadratic. And it has to be possible in PHP - that means no derivatives, no limits, and not even basic algebra.

It has to be possible: MS Excel can find them even to a fifth-order equation, and in very little time too.
Eh, that's how it goes...

I just tried searching for something slightly different than I've been trying, and now I have the solution. Without actually giving the solutions for a, b, and c (it's long sweatdrop ), it was this that "gave" me the answer (I still had to solve those last three equations).

Plus, the answer is so simple, I feel stupid for not figuring it out myself (behind computers, math is my best subject) redface

Quick Reply

Submit
Manage Your Items
Other Stuff
Get GCash
Offers
Get Items
More Items
Where Everyone Hangs Out
Other Community Areas
Virtual Spaces
Fun Stuff
Gaia's Games
Mini-Games
Play with GCash
Play with Platinum