Any math skilled can help me? [Solved]

The place to post your WML questions and answers.

Moderator: Forum Moderators

Forum rules
  • Please use [code] BBCode tags in your posts for embedding WML snippets.
  • To keep your code readable so that others can easily help you, make sure to indent it following our conventions.
Post Reply
User avatar
tekelili
Posts: 1039
Joined: August 19th, 2009, 9:28 pm

Any math skilled can help me? [Solved]

Post by tekelili »

I am using in a scenario this function. I have forgotten my math lessons about how interpolate a function from given points, but for calculate intermediate values and better working of code would help me a lot have a function with similar output rather than discrete values table. Can anyone do it for me? :)

(note that all values for f(x) x>1 are less than 1, they have a point before floating part)
f(1)=1
f(2)=.88
f(3)=.77
f(4)=.67
f(5)=.58
f(6)=.50
f(7)=.43
f(8)=.37
f(9)=.32
f(10)=.28
f(11)=.25
f(12)=.224
f(13)=.201
f(14)=.181
f(15)=.164
f(16)=.15
f(17)=.138
f(18)=.127
f(19)=.117
f(20)=.108
f(21)=.1
f(22)=.093
f(23)=.087
f(24)=.082
f(25)=.078
f(26)=.074
f(27)=.071
f(28)=.068
f(29)=.065
f(30)=.062
f(31)=.06
f(32)=.058
f(33)=.056
f(34)=.054
f(35)=.052
f(36)=.05
Last edited by tekelili on January 18th, 2012, 6:37 am, edited 1 time in total.
Be aware English is not my first language and I could have explained bad myself using wrong or just invented words.
World Conquest II
SlowThinker
Posts: 876
Joined: November 28th, 2008, 6:18 pm

Re: Any math skilled can help me? (function interpolation)

Post by SlowThinker »

There is one polynomial function of a maximal degree 35 that goes through points you listed. (http://en.wikipedia.org/wiki/Lagrange_polynomial)
You can use something like this: http://www.solvemymath.com/online_math_ ... lation.php

In case you want to calculate that function by WML/lua means: that is not a good idea, because it would be too slow. You should use rather "spline interpolation" for example.
I work on Conquest Minus • I use DFoolWide, Retro Terrain Package and the add-on 'High Contrast Water'
I moved to Nosebane's corner (Doc Paterson's signature); I am spending my time there, so PM me if I don't answer your post in forums
User avatar
Sapient
Inactive Developer
Posts: 4453
Joined: November 26th, 2005, 7:41 am
Contact:

Re: Any math skilled can help me? (function interpolation)

Post by Sapient »

If you don't want to use an array of results such as

Code: Select all

[f]
  value=1
[/f]
[f]
  value=.88
[/f]
Then another alternative would be

Code: Select all

[f]
  1=1
  2=.88
[/f]
For your data, it seems it would be simpler to use a lookup table than a 35th degree polynomial.
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
User avatar
tekelili
Posts: 1039
Joined: August 19th, 2009, 9:28 pm

Re: Any math skilled can help me? (function interpolation)

Post by tekelili »

Thanks for help guys. I have understood I was asking for something more complicated than I expected. My final solution was interpolate a function of grade 2 for values less than 12, where I need more precision, and use table for greater ones.

for x<12 i got this one: f(x)=1+(x^2-27x-26)/200 using the few I still remember about progressions :doh:
Be aware English is not my first language and I could have explained bad myself using wrong or just invented words.
World Conquest II
Scatha
Posts: 111
Joined: March 29th, 2008, 2:55 pm

Re: Any math skilled can help me? (function interpolation)

Post by Scatha »

I certainly wouldn't try to approximate something like this with a direct polynomial in x -- you'll basically be overfitting, and it won't extrapolate nicely.

However, eyeballing it and playing with a calculator a little, it looks like away from the beginning it's doing something like (?) f(x) ~ C.x^(-k), where C and k are constants (something roughly like C=5.5, k = 1.3) . You might try fiddling around with polynomials in x^(-1/4) or somesuch and see if you can find something which fits well.
User avatar
tekelili
Posts: 1039
Joined: August 19th, 2009, 9:28 pm

Re: Any math skilled can help me? (function interpolation)

Post by tekelili »

After experiment a lot with a function drawer, I finally had a function wich curve pretty much gives me what I really wanted:

f(x)=(5/6)^((x-1)/(x^(5/12)))

If neccessary, this thread can be locked.
Be aware English is not my first language and I could have explained bad myself using wrong or just invented words.
World Conquest II
Post Reply