This project has moved and is read-only. For the latest updates, please go here.

FindZero() in metaNumerics

Dec 3, 2010 at 1:35 PM

Hi

 

i have some problem in using Findzero() of Metanumerics (Visual Basic). in fact i don't know how to define a simple function y=x^3 and find its root using findzer() 

anybody knows how to do that?

Dec 3, 2010 at 7:08 PM

Here is a simple example:

    Function MyFunction(ByVal x As Double) As Double
        Dim z As Double = x - 2.0
        Return (z * z * z)
    End Function

    Sub Main()
        Dim x As Double = FunctionMath.FindZero(AddressOf MyFunction, 1.0)
        Console.WriteLine(x)
        Console.ReadLine()
    End Sub

Basically: 1. Write a method to compute your function that takes a double and returns a double. 2. Give that method as the first argument to FindZero using AddressOf followed by the method name. 3. The second argument of FindZero can be either a first guess at the root or an interval known to contain the root.

Jun 28, 2012 at 7:26 PM
Edited Jun 28, 2012 at 7:36 PM
Public Sub FindCO()

        Dim CO_fun As Func(Of Double, Double) = AddressOf funCO

        OC = FunctionMath.FindZero(CO_fun, 20.0)

End Sub

Hello,

I am still relatively new to using Visual Basic 2010 and need some help.The above code works with a single function and unknown variable, but I am having a problem using the multidimensional version of FindZero. I have tried putting the functions in one function and then passing that functionto FindZero along with an array of initial guesses but that does not work. So I am still trying to figure out how to pass arguments to FindZero. This means I still have not figured out how to use FindZero on a system of equations. Can someone please explain how this can be done, if it is possible.

Jul 20, 2012 at 11:07 PM

Here's an example using the multi-dimensional FindZero. It finds the zeros of z^3 + 1 in the complex plane, treating the real and imaginary parts as x and y coordinates. These zeros as (0. 1) and (1/2. +/- Sqrt(3)/2), as you can easily verify.

    Function MyFunction(v As Double()) As Double()
        Dim z As Complex = New Complex(v(0), v(1))
        Dim f As Complex = ComplexMath.Pow(z, 3) + 1.0
        Return (New Double() {f.Re, f.Im})
    End Function

    Sub Main()
        Dim v As Double() = FunctionMath.FindZero(AddressOf MyFunction, New Double() {1.0, 1.0})
        Console.WriteLine("{0}, {1}", v(0), v(1))
        Console.ReadLine()
    End Sub

It prints out (1/2, Sqrt(3)/2), which is the zero closest to the (1,1) starting point.

By the way, while the code for the multidimensional FindZero has been checked in, it has not yet appeared in an official release. You are of course welcome to use it, but we do "reserve the right" to change the signature or even remove it before an official release.

Aug 16, 2012 at 11:32 AM

Thank you