Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Curve fitting
#1
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?
quote="Bruce Raeman"]Anatomy (n): something everyone has, but which looks better on a girl[/quote]
Reply
#2
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~
Reply
#3
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:
Kevin (x.t.r.GRAPHICS)

[Image: 11895-r.png]
Reply
#4
Quote: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.
Ralph, using QuickBASIC 4.5 and Windows XP Home Edition and Service Pack 2, with HP LaserJet 4L printer.
Reply
#5
Quote:My program, saved as text, is 46KB long, and is not something I would want to try to paste here.
Fileanchor the bastard. 8)
[Image: freebasic.png]
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)