![]() |
Integration/area under a curve VBA code?
Hi
I have built a spreadsheet that can calculate the area under a curve of a set of data but I would like to have this in VBA for Excel, in say Integral(C1,C2) format or a button on the toolbar. Can anyone point me in the right direction for acquiring the code? Cheers WayneL |
Integration/area under a curve VBA code?
Thanks Gregory Vainberg (http://www.vbnumericalmethods.com) for this perfect
solution. I have tested it with FlexPro and the value correlates. Cheers WayneL Hey Wayne, I have a number of different methods that you can use, but the easiest technique is trapezoidal integration. On the website I have a version that takes the function name as a parameter, but it can be easily adapted to use 2 vectors as parameters as follows: Public Function TRAPnumint(x, y) As Double n = Application.Count(x) TRAPnumint = 0 For t = 2 To n TRAPnumint = TRAPnumint + 0.5 * (x(t) - x(t - 1)) * (y(t - 1) + y(t)) Next End Function Where x is the column of x values and y is the column of f(x) values. Hope this helps, Gregory Vainberg http://www.vbnumericalmethods.com "WayneL" wrote in message ... Hi I have built a spreadsheet that can calculate the area under a curve of a set of data but I would like to have this in VBA for Excel, in say Integral(C1,C2) format or a button on the toolbar. Can anyone point me in the right direction for acquiring the code? Cheers WayneL "WayneL" wrote in message ... Hi I have built a spreadsheet that can calculate the area under a curve of a set of data but I would like to have this in VBA for Excel, in say Integral(C1,C2) format or a button on the toolbar. Can anyone point me in the right direction for acquiring the code? Cheers WayneL |
All times are GMT +1. The time now is 06:22 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com