Jump to content
  • Advertisement
Sign in to follow this  
ThunderSoul

Mathematical graphing

This topic is 4028 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi... I am looking to find a formula for 2 unknown inputs. Does anyone know of a program that if given a set of empirical data can develop an approximate mathematical formula? For example, Input: Output: (5,5) 5 (5,10) 10 (5,15) 16 (5,20) 24 (10, 5) 9 (10, 10) 10 (15, 20) 70 (20, 5) 19 etc... Any help would be appreciated... Thank you...

Share this post


Link to post
Share on other sites
Advertisement
Typically you first pick an equation class you want to use to model the relationship (i.e. Ax + By = C) and then regress the curve to your data. Excel can co do this using linear equations, quadratic equations, exponential equations, etc.

This should also probably be moved to M&P.

Share this post


Link to post
Share on other sites
Try gnuplot. It can do curve fitting via the "fit" command. Documentation is available at the gnuplot site. They made a good attempt at it but, as with most open source projects, it is kind of crappy. I think it can do 3D plotting but I'm not sure. MATLAB might be able to, as well.

Here's a gnuplot example:

Make a file called data.dat:

0 5
-2 9
5 30

The first column was X and the second was Y (the output.) We guess that the equation will be a parabola of the form f(x)=a*x**2 + b

Here's the gnuplot .plt file to use:


set term windows

set xlabel "X"
set ylabel "Y"
set title "Bart's Kickass Example"

#
# Perform curve fit
#

f(x) = a*x**2+b # format of the equation to fit to
a = 0.5 # provide initial guesses for fitting parameters
b = 1.0
FIT_LIMIT = 1e-6 # internal variable controlling limit of convergence

fit f(x) 'data.dat' using ($1):($2) via a,b # $1,$2 are columns

#
# Plot and Output to File
#

plot [-7:7] 'data.dat' using ($1):($2) lt 1 t 'Data' # plot data
replot f(x) lt -1 t 'Fitted Curve' # overlay fitted curve

set term png enhanced # enhanced mode (mixed fonts, etc.), color, force solid lines
set output 'comparison_unstrained.png'
replot
set term windows



I didn't test it but it should work okay.

Share this post


Link to post
Share on other sites
Lagrange's interpolation polynomial (google for it) will fit a polynomial to any set of points you choose. However, if the degree is too high or the whole graph looks wrong you will want to fit a best fit lower order polynomial or something to the data.

EDIT: That only applies to a function though, and it looks like you have inputs mapping to multiple outputs. So you will want least squares regression for sure.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!