|
From: 3snoW <vas...@gm...> - 2011-06-16 10:54:25
|
Daniel J Sebald wrote: > > On 06/15/2011 07:35 PM, 3snoW wrote: >> >> Hello, >> I'm not sure if this qualifies as "Dev", If it doesn't I'm sorry. > [snip] >> Let me know if you have any ideas to make it better or if you find any >> bug >> using it! I hope this was helpful! > > Very creative. Of course, this is straightforward rectangular > approximation to integration. It will have problems with functions that > change quickly near discontinuities and so on so won't have the > precision of, say, adaptive integral techniques. Nonetheless, it works > (sort of, see note at end), assuming the initial condition is that the > integral passes through zero at a. > > [snip] > > Notice how accuracy is lost moving outward. So you might want to > experiment with making h another parameter in the function. Generalizing, > > intf(a,x,N)=x>a?intfAux1(a,x-(x-a)/N/2,(x-a)/N)*(x-a)/N:intfAux2(a,x+(a-x)/N/2,(a-x)/N)*(x-a)/N; > > I can't push N high enough to get good resolution before a stack > overflow occurs. > > An internal integration feature is probably the only good way to address > this sort of thing. > > Dan > Hi Dan, The reason I was using f(x)-f(a) in the intfAux functions and then add f(a)*(x-a) is because I originally was using a fixed small step h instead of dividing the interval in 90 small parts. That way, if f(a) was not 0, the integral would have a discontinuity every time x was a multiple of h, so, as a workaround to this problem, I set it to integrate f(x)-f(a), and compensated adding f(a)*(x-a). But since I switched to dividing into 90 equal parts, this is no longer a problem. I didn't make the integration method more sophisticated because of the 'stack overflow' issue. Adaptive integral techniques would most likely consume 'stacks' at a much higher rate, and in the end you would have a worse integration because of the lack of resolution. I'm thinking of maybe upgrading this to the trapezoidal integration or even a superior order technique, but for now I think this works fine for any 'well behaved' function. Lastly, the generalized function that includes N as a parameter is a good idea, but I'll call it Nintf instead of intf, because that way I can have both functions. Thank you for your contribution, it was really constructive! I'll update the config.ini file with your changes. 3snoW -- View this message in context: http://old.nabble.com/Integration-in-gnuplot-IS-possible%21-tp31856137p31859432.html Sent from the Gnuplot - Dev mailing list archive at Nabble.com. |