Approval and optimisation
11 02 2009Slowly detaching myself from the need to gain approval from others and losing the arbitrary restrictions I have placed on myself is an enjoyable process.
Now, optimisation. Initially I wanted something like “What is the optimum quadratic ax2 + bx + c to model the cubic px3 + qx2 + rx + s on the interval [x0, x1]?” but realised that this was rather ambitious.
I tried a crippled version of this, which was kind of fun. Say I have a function f(x) and want to approximate it with a straight line g(x) = mx on [0, t] (mx because I want g(x) to be strictly of the form m*h(x)… you’ll see why later).
The integral of f(x) - g(x) dx from 0 to t will give, in some sense, the “error” between the two - the distance. Unfortunately, the distance of one line below the other cancels out with the distance of that one above the other. In order to skip out integrals of |f(x)| (…), I’ll go for int[0, t]{(f(x)-g(x))2}dx. The integrand is a quadratic in m, as is the integral. If I call this integral sigma e2 (”sum of infinitesimal square errors” in a handwavy way), … nothing. That naming was pointless. Anyway, I now rewrite the evaluated definite integral by completing the square with respect to m. From this I can see the value m must take to set the newly-created (m - k)2 term to 0 and thus minimise the expression. Thus I have my line y = mx.
I understand that I just botched the explanation, so I’ll give an example with f(x) = sqrt(x).
You can evaluate the integral term by term by multiplying it out (it’s just polynomial in x) but I used The Integrator (I’LL BE BACK!!) to speed this along.
sigma e2 = int[0 to t]{(sqrt[x] - mx)2} = (1/30)t2(10tm2 - 24m.sqrt(t) + 15)
I don’t even need to fully complete the square… just take that 10t outside the bracket: (10/3)t3(m2 - (12/5)m/sqrt(t) + 3/(2t)) and then we know the (m - k)^2 bit is (m - 6/(5sqrt(t)))2 so to zero that term, m = 6/(5sqrt(t))…
…so in conclusion, the line y = 6x/(5sqrt(t)) best approximates y = sqrt(x) on [0, t]. Try it in Autograph. Lulz.
Yes, it’s useless, but it… is something that should work and it… does (?). It highlights the interpretation of the integral as an infinitesimal sum rather than “the area under a graph” or whatever. Eh.
Pax






Nice work - it seems to work from what I gather from random Excel trials - however perhaps for this to really work it should be more in the form of y = mx + c? e.g. if you give it y = 1 on the interval [0, 3] you’ll get out y = 0.5x from your method!
It’s interesting - I went through the integral method with that example I gave (and other constant functions) and I thought it would come out y = (2/3)*x (that the y=mx line would cut the y=a line at the half-way point) and kept trying to find a mistake in my working… Turns out it’s at the 2/3 mark.
Anyway I tried doing this mx+c thing but ended up with partial differential stuff which I don’t much like and which didn’t seem to really work because I had things like ?y/?m(… + mc + …) = ?y/?c(… + mc + …) = 0 which I don’t know how to handle. but I did work out some relationships between m and c which Excel agreed with so I can’t be far off…
Meh looks like I should actually learn partial differentials properly rather than relying on rumours and hearsay and stuff OLCT randomly says in class…
Yeah… I don’t know how to do it with more than one parameter … … hence the uselessness remarks, lol
Damn my curly partial differential ‘d’s didn’t come out!
I’ll look into it as well.
[...] may remember Approval and Optimisation, in which I minimised the error between a function and a candidate function, linearly parameterised [...]