ClubEnsayos.com - Ensayos de Calidad, Tareas y Monografias
Buscar

MÉTODO BUSCA Ejercicio 1


Enviado por   •  6 de Octubre de 2021  •  Tareas  •  8.072 Palabras (33 Páginas)  •  83 Visitas

Página 1 de 33

MÉTODO BUSCA

Ejercicio 1

Module Module1

        Function f(ByVal x As Single) As Single

        Return x * x + 2 * x - 4

        End Function

 

        Sub Buscartodas(ByVal a As Single, ByVal b As Single, ByVal h As Single)

        Dim x, x1 As Single

        x = a

        x1 = x + h

        Do

            If (f(x) * f(x1) < 0) Then

                    Console.WriteLine("raiz esta en {0}  y {1} ", x, x1)

                End If

            x = x1

            x1 = x + h

        Loop While (x1 <= b)

        End Sub

        Sub Main()

        Dim a As Single = -4, b As Single = 3

        Dim h As Single = 0.001

        Buscartodas(a, b, h)

        Console.ReadLine()

        End Sub

End Module 

Ejercicio 2

Module Module1

            Function f1(ByVal x As Single) As Single

            Return x * x + 1 * x - 2

        End Function

            Sub Buscartodas1(ByVal a As Single, ByVal b As Single, ByVal h As Single)

                Dim x, x1 As Single

                x = a

                x1 = x + h

                Do

                    If (f1(x) * f1(x1) < 0) Then

                        Console.WriteLine("raiz esta en {0}  y {1} ", x, x1)

                    End If

                    x = x1

                    x1 = x + h

                Loop While (x1 <= b)

            End Sub

            Sub Main()

                Dim a As Single = -4, b As Single = 3

                Dim h As Single = 0.001

                Buscartodas1(a, b, h)

                Console.ReadLine()

            End Sub

        End Module

MÉTODO BISECCIÓN

Ejercicio 1

Function f(ByVal x As Single) As Single

            Return x * x + 2 * x - 4

        End Function

        Function biseccion(ByVal a As Single, ByVal b As Single, ByVal h As Single) As Single

            Dim pr As Single

            Dim c As Single = CSng((a + b) / 2.0)

            While ((b - a) > h)

                c = (a + b) / 2

                pr = f(a) * f(c)

                If (pr > 0) Then

                    a = c

                Else : b = c

                End If

            End While

            Return (a + b) / 2

        End Function

        Sub Main()

            Dim a As Single = -0, b As Single = 10

            Dim h As Single = 0.001

 

            Console.BackgroundColor = ConsoleColor.DarkGreen

            Console.Clear()

            Console.ForegroundColor = ConsoleColor.Blue

            Console.WriteLine("|||||||||   METODO DE LA BISECCIÓN   |||||||")

            Console.ForegroundColor = ConsoleColor.White

            Console.WriteLine("La raíz positiva por el metodo de bisección es : {0}  ", biseccion(a, b, h))

...

Descargar como (para miembros actualizados)  txt (17.1 Kb)   pdf (153.2 Kb)   docx (104.6 Kb)  
Leer 32 páginas más »
Disponible sólo en Clubensayos.com