Jump to content

eldflaugamadur

Member
  • Posts

    5
  • Joined

  • Last visited

Everything posted by eldflaugamadur

  1. While reading CODE(Petzold) I just couldn't resist writing this in my book: http://imgur.com/YeVtctQ
  2. C'mon man, now you have to use Taylor Expansion. It would not achieve much, as it is already a polynomial. Tailor expansion around zero of a polynomial will give back that same polynomial. If it's not around zero, then I'm not sure what it will give, probably something at least as complicated. Oh... Sorry for posting it here I guess. Normally I wouldn't go around and jump scare people with math, there are more appropriate places to talk about that. It's just that the table from the video looked like a function and I thought, "Hey, I wonder what kind of function?", and I thought I'd share, normally I'd just keep things like that on my hard drive and keep quiet about it.
  3. Hilariously Unsuccessful Curve(Surface) Fitting Of The Pedestrian Weight To Impact Ratio Function I've recently learned a technique of fitting any random data to interpolating polynomials(using a Lagrangian method). It allows one to take some crazy complicated function and turn it into a nice and simple polynomial(in theory). The downside is that if function doesn't fit well into any polynomials you get a really crazy and wavy polynomial instead which can be even worse than original function or it's data. When you wield a hammer every finger is a nail(or however it goes), so when i saw that copy protection table in the video I just had to try this method. I wanted to know what polynomial can approximate that whole "Pedestrian Weight To Impact Ratio Table". It has total of 36*13=468 values, seemingly not a lot of data, so I was very optimistic and at first tried building that polynomial on a piece of paper. Very soon after running out of both paper and patience, I realized I underestimated the scope of the problem. Not inclined to give up so soon, I decided to write a program to do it. I chose Haskell as a language, mainly because I thought it would be faster to build this sort of thing in a functional programming language, and also because in the back of my mind I was suspecting I will need arbitrary precision arithmetic, little did I know I was right. The program performs a very simple algorithm based on symbolic manipulation, not unlike the one you've been accustomed to since school. It constructs a series of polynomials and then multiplies and adds them all together to create bigger expressions, finally producing a single polynomial, a function of two variables, weight and mph, or x and y. Graphically such a function can be represented by a surface in three dimensions. If anyone cares how I actually represented polynomials inside a program, 4yx^2+2x+5 would be seen encoded as [(4,[(1,1)(0,2)]), (2,[(0,1)]), (5,[])]. Here polynomial is a list of members. Each member is a tuple, consisting of coefficient on the left and a list of base/exponent pairs on the right. Variable names are encoded as numbers 0 for x, 1 for y. I will not explain here how Lagrangian method works, as it can be technical(yes more technical), and I'm still new to it, so I'm not the best person to explain, if you want to study it, it's from branch of mathematics called Numerical Analysis. The coefficients of this polynomial are extremely important, this is the area that requires the most numerical precision and where most of the precision can be lost. Originally in my infinite naiveness I chose to use a floating point number for coefficients. This is where I underestimated the problem again. Not only floating point numbers gave poor precision, they didn't produce anything that resembled a correct answer. The original unsimplified expression has over millions of terms! My computer with 4GB of memory couldn't even work with unsimplified expressions, it would crash. Even if those terms were correct from a single division that was performed on them, they would loose any resemblance to themselves after going through so many additions and subtractions while simplifying the terms. Here I almost gave up. Precision errors are hard to beat, but here I remembered that Haskell has another useful number type - rational numbers. By themselves rational numbers are still limited to maximum integer size, but in Haskell you get infinite integers too. And so parameterizing rational numbers over infinite integers gives a practically infinite precision alternative to floating point, at least for this type of problem. Finally after replacing all coefficients with rational numbers everything suddenly clicked, and program worked. The source code is here: https://gist.github.com/echolot/9cea3cb8ef08e34746a4 The resulting polynomial takes about 30 seconds to compute, it has 468 terms, features rational fractions with over 80 digits in either numerator, denominator or both, and maximum powers of x and y up to 12 and 35 respectively. None of it would be a problem and I would be happy, save for one thing, the fractions of the coefficients are way too precise for floating point representation and so this function cannot be computed on any ordinary calculator without support for rational arithmetic. Any attempts to use floating point will lead to garbage. This is very disappointing for me. Not only it is useless for computation, but any graph of such function would produce a waving mess. Nevertheless, it works, at least in Haskell with it's rationals. You can view it in your browser in it's full 468-termed glory: https://gist.githubusercontent.com/echolot/9cea3cb8ef08e34746a4/raw/4f848ed5a0f8ce0d925f20f65f1246c931288008/pwtir.hs Note that the percentage signs "%" here mean "/", this is just a way to represent rationals. It's NOT a modulus operator like in C. This is because "/" is already defined to mean floating point division. If anything useful came out of this attempt is the fact that I trascribed the entire table, it can be found at the top of polyfit.hs file, encoded as a list of tuples. Maybe someone will need it, I'm sure you'd be able to figure out which columns mean what. EDIT: I've just realized the polynomial has exactly as many terms as the table had entries: 468. Well, that was a waste of time.
  4. WEBMONEY, isn't that a russian/eropeanish payment system? Yeap.. looks like you got yourself a russian fan-impersonator
  5. I wonder what would happen to government if everyone quit their jobs and stopped paying taxes for some reason. Summons images of starving crowds of unshaven functionaries in dirty tattered suits, like rats leaving house devoid of food.
×
×
  • Create New...

This website uses cookies, as do most websites since the 90s. By using this site, you consent to cookies. We have to say this or we get in trouble. Learn more.