Public Class Trapecio
Private Sub Trapecio_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim tabla, tabla2 As List(Of Fila)
Dim valorA, valorB, NVeces, nuevovalorA, NRepeticiones, n As Double
valorA = Integer.Parse(InputBox("Ingrese el límite de Integración de 'a'", "Método del Trapecio", "Valor de 'a'", 100, 100))
valorB = Integer.Parse(InputBox("Ingrese el límite de Integración de 'b'", "Método del Trapecio", "Valor de 'b'", 100, 100))
NVeces = Integer.Parse(InputBox("Ingrese el valor de N Veces", "Método del Trapecio", "Valor de 'N Veces'", 100, 100))
NRepeticiones = Integer.Parse(InputBox("Ingrese el valor de Numero de Repeticiones para el programa", "Método del Trapecio", "Valor de 'N Repeticiones'", 100, 100))
Dim arrayNumeros(NVeces) As Double
Dim repetido As Boolean
Randomize()
For i = 1 To NVeces 'genero numeros aleatorios NVeces
repetido = False
nuevovalorA = (valorB - valorA) * Rnd() + valorA 'genero numeros aleatorios entre a, b
'arrayNumeros(i - 1) = nuevovalorA
While repetido = False
For j = 0 To i - 1 'verificar cada numero del arreglo para buscar repetido
If i > 1 Then
If nuevovalorA = arrayNumeros(j) Then
repetido = False
nuevovalorA = (valorB - valorA) * Rnd() + valorA 'genero numeros aleatorios entre el intervalo a, b
j = -1
ElseIf j = i - 1 Then
'arrayNumeros(i - 1) = nuevovalorA
repetido = True
End If
Else
repetido = True
End If
Next j
End While
arrayNumeros(i - 1) = nuevovalorA
Next i
arrayNumeros(0) = valorA
arrayNumeros(NVeces) = valorB
Array.Sort(arrayNumeros)
' En esta linea o lazo (loop) se asigna el número de orden de cada fila
tabla = arrayNumeros.Take(NVeces).Zip(arrayNumeros.Skip(1), Function(a, b) CalcularFila(a, b)).ToList()
For k As Integer = 1 To tabla.Count
tabla(k - 1).n = k
ListBox1.Items.Add(arrayNumeros(k))
Next
Dim arrayRepeticiones(NRepeticiones) As Double
'For r = 1 To NRepeticiones
' n = txtValorInt.Text
' arrayRepeticiones(r - 1) = n
'Next r
'tabla2 = arrayRepeticiones
'DataGridView2.DataSource = tabla2
'DataGridView2.Columns("Valor").DefaultCellStyle.Format = "N5"
DataGridView1.DataSource = tabla
DataGridView1.Columns("a").DefaultCellStyle.Format = "N5"
DataGridView1.Columns("b").DefaultCellStyle.Format = "N5"
DataGridView1.Columns("deltaX").DefaultCellStyle.Format = "N5"
DataGridView1.Columns("deltaX").HeaderText = "DeltaX"
DataGridView1.Columns("raizA").DefaultCellStyle.Format = "N4"
DataGridView1.Columns("raizA").HeaderText = "f(a)"
DataGridView1.Columns("raizB").DefaultCellStyle.Format = "N4"
DataGridView1.Columns("raizB").HeaderText = "f(b)"
DataGridView1.Columns("Area").DefaultCellStyle.Format = "N4"
DataGridView1.Columns("Area").HeaderText = "Area"
End Sub
Private Function CalcularFila(dato1 As Double, dato2 As Double) As Fila
Dim fila As New Fila
fila.a = dato1
fila.b = dato2
fila.deltaX = dato2 - dato1
fila.raizA = Math.Sqrt(4 + 7 * fila.a ^ 4)
fila.raizB = Math.Sqrt(4 + 7 * fila.b ^ 4)
fila.Area = ((fila.raizA + fila.raizB) / 2) * fila.deltaX
Return fila
End Function
Class Fila
Public Property n() As Integer
Public Property a() As Double
Public Property b() As Double
Public Property deltaX() As Double
Public Property raizA() As Double
Public Property raizB() As Double
Public Property Area() As Double
End Class
Private Sub btnValorInt_Click(sender As Object, e As EventArgs) Handles btnValorInt.Click
btnSiguiente.Enabled = True
Dim ValorIntegral As Double
Dim Col1 As Integer = DataGridView1.CurrentCell.ColumnIndex
For Each row As DataGridViewRow In DataGridView1.Rows
ValorIntegral += Val(row.Cells(6).Value)
Next
txtValorInt.Text = ValorIntegral.ToString
End Sub
End Class