Qbasicnews.com October 18, 2019, 10:14:48 AM Welcome, Guest. Please login or register. 1 Hour 1 Day 1 Week 1 Month Forever Login with username, password and session length Home Help Search Login Register
 Pages: Author Topic: Curve fitting  (Read 2163 times)
jakeman922
Member Posts: 74  « on: September 13, 2005, 08:46:49 PM »

Don't tell me curve fitting can't be done, I've seen it. How do you fit a curve to a series of points? Logged

quote="Bruce Raeman"]Anatomy (n): something everyone has, but which looks better on a girl[/quote]
Oz
I hold this place together     Posts: 923  « Reply #1 on: September 14, 2005, 09:03:26 AM »

what type of curve?
biezer (sp?)

if so, you should research it - google "Biezer Curve forumlae" and i'm sure you'll find something worth using

oz~ Logged
Rattrapmax6
__/--\__     Posts: 2577   « Reply #2 on: September 14, 2005, 12:41:04 PM »

You can do a sinus curve for along the X axis:

Code:
SCREEN 13
amp = 1
DO
LINE (0,0)-(320, 200), 0, BF
LINE (0,100)-(320, 100), 9
FOR x = 1 TO 320
y! = amp * SIN(ang * 3.24/180)
PSET (x, 100 - y!), 10
ang = ang + 1
NEXT
WAIT &H3DA, 8
amp = (amp + 1) MOD 100
LOOP UNTIL INKEY\$ <> ""
SLEEP

Or a cosine curve if you need one on the Y axis:

Code:
SCREEN 13
amp = 1
DO
LINE (0,0)-(320, 200), 0, BF
LINE (160,0)-(160, 200), 9
FOR y = 1 TO 320
x! = amp * COS(ang * 3.24/180)
PSET (160 + x!, y), 10
ang = ang + 1
NEXT
WAIT &H3DA, 8
amp = (amp + 1) MOD 100
LOOP UNTIL INKEY\$ <> ""
SLEEP

Might be some good ways to do it,.. dunno, I'd look into what Oz suggested first...  :wink: Logged

Ralph
Ancient Guru    Posts: 544 « Reply #3 on: September 14, 2005, 06:05:35 PM »

Quote from: "jakeman922"
Don't tell me curve fitting can't be done, I've seen it. How do you fit a curve to a series of points?

To answr the question properly would take a very long explanation.  Briefly, one assumes that a certain type of curve will describe all the points reasonably well.  Then, one calculates the parameters for that curve, so it fits the data as best as possible.  The usual method followed it to assume that, for a given curve, say, a straight line, y = mx +b, the best-fit curve will be one whose errors will be a minimum.  And, this means using the Least-Squares method to obtain simultaneous equations which, for the straight line, would be:

A11m + A12b = A10
A21m + A22b = A20

Solving for m and b, we get the equation of the "best-fit" straight line, y = mx + b.

One then can try for a higher-order degree curve, until one gets what looks like a reasonable fit, without having to go too high in the complexity of the curve.  Usually, we are trying to obtain curves of low degree, say between the 1st degree and up to the 3rd of 4th, but, we might require very high degrees, if we can justify it.

I have written a QuickBASIC program for this, which I call CurveFit.  Here is, in a few nutshells, what it can do:

1. Read as many as 100 points (x,y values) from a data file.
2. Process the x,y values via the Least-Squares Method
3. Obtain the coefficients of a polynomial curve with any degree , up to 16, as long as the numer of points, n, and the degree chosen, d, are in the relationship, n>=d+1
4. Show the resultng equation,
y = A0 + A1x + A2x^2 + A3x^3 +...+ Adx^d
(Notice that, using only the first two terms on the right side will give a "best-fit" straight line, y = A1x + A0, or, y = mx + b)
5. Show all the input points on a graph, together with the "best-fit curve", so one can judge the curves, one by one, to select which has the best fit.

My program, saved as text, is 46KB long, and is not something I would want to try to paste here. Logged

Ralph, using QuickBASIC 4.5 and Windows XP Home Edition and Service Pack 2, with HP LaserJet 4L printer.
Deleter
Na_th_an     Posts: 1292   « Reply #4 on: September 14, 2005, 08:31:29 PM »

Quote from: "Ralph"
My program, saved as text, is 46KB long, and is not something I would want to try to paste here.

Fileanchor the bastard.  Logged

 Pages: