I want to creat a VB Code for brent method (a numerical method) which can takes an analytic function and find the root. How can I do this in VB 2010? the function Brent method takes is like:
Function W_Bazin_Rect_h(ByVal Q As Double,
ByVal w As Double,
ByVal a As Double,
ByVal S As Double) As Double
Dim tempstr As String
If w < 0 Or a <= 0 Then
tempstr = "Error on input"
ShowMessageBox(tempstr)
Exit Function
End If
If Q <= 0 Then
Return 0
End If
g = 9.81
u = (0.405 + 0.003 / h) * (1 + 0.55 * (h / (h + a)) ^ 2)
Q = ((2 * g) ^ 0.5 * u * w * h ^ (3 / 2)) * (1 - (S / h) ^ 1.5) ^ 0.385
End Function
Should i define brent methode as a class or a function?
I want to initialize the function (i.e Q=1,a=1,w=1,S=1) and then pass the function to the Brent method which could return the value of h. What is the best way to do this in VB.NET? I want to make a general Brent method where I can pass any single valued function and find roots.
I have just started using VB, and from what I have found so far it seems like the tools you have is - to us a delegate for the function - to use a lambda expression for the function - send a pointer/adressOf - to create a function class/structure and submit this to the function
As for now I am most inclined to create a function-class. But I am not really sure how. F.ex. I make different classes for each "uniqe function" I want to integrate, but how can I pass them to the integration function when I need to specify the argument type in the integration-function-call?
This seems like a basic problem which applies to many Math operations, so I think it would be very useful to clarify this.