You are on page 1of 5

Regresión Logarítmica

Module Module1

Sub Main()
Console.ForegroundColor = ConsoleColor.Magenta
Dim n As Integer
cdn(n)
Dim V1(n) As Integer
Dim V2(n) As Integer

leer(V1, n)
leer(V2, n)

Console.WriteLine("la ecuacion de regresion lineal logaritmica es Y =


{0}+{1}lnX", hallando_A(V1, V2, n), hallando_B(V1, V2, n))
Console.ReadLine()

End Sub

Sub cdn(ByRef n As Integer)


Randomize()
n = CInt((50 * Rnd()) + 1)
Console.WriteLine("n={0}", n)
Console.ReadLine()
Console.Clear()

End Sub
Sub leer(ByRef v() As Integer, ByVal n As Integer)
Dim i As Integer
For i = 0 To n - 1

Randomize()
v(i) = CInt((50 * Rnd()) + 1)
Console.WriteLine("el número en la en posición {0} es {1}", i + 1, v(i))
Next

End Sub

Function hallando_B(ByVal V() As Integer, ByVal Z() As Integer, ByVal n As


Integer)
Dim suma, suma_logx, suma_y, suma_logx2 As Single
suma = 0
suma_logx = 0
suma_y = 0
suma_logx2 = 0

Dim B As Single

For i = 0 To n - 1
suma = suma + Math.Log(V(i)) * Z(i)
suma_logx = suma_logx + Math.Log(V(i))
suma_y = suma_y + Z(i)
suma_logx2 = suma_logx2 + (Math.Log(V(i))) ^ 2
B = ((suma * n) - (suma_logx * suma_y)) / ((n * suma_logx2) - (suma_logx
^ 2))
Next
Return (B)
End Function
Function hallando_A(ByVal V() As Integer, ByVal Z() As Integer, ByVal n As
Integer)
Dim suma, suma_logx, suma_y As Single
suma = 0
suma_logx = 0
suma_y = 0

Dim A As Single

For i = 0 To n - 1
suma = suma + Math.Log(V(i)) * Z(i)
suma_logx = suma_logx + Math.Log(V(i))
suma_y = suma_y + Z(i)

A = (suma_y / n) - (hallando_B(V, Z, n) * (suma_logx) / n)

Next
Return (A)
End Function

End Module

Exponencial
Module Module1

Sub Main()
Console.ForegroundColor = ConsoleColor.Cyan
Dim n As Integer
cdn(n)
Dim V1(n) As Integer
Dim V2(n) As Integer
leer_vector(V, n)
leer_vector(Z, n)

Console.WriteLine("la ecuacion de regresion lineal logaritmica es Y = {0}


X^{1}", hallando_A(V1, V2, n), hallando_B(V1, V2, n))
Console.ReadLine()

End Sub

Sub cdn(ByRef n As Integer)


Randomize()
n = CInt((50 * Rnd()) + 1)
Console.WriteLine("n={0}", n)
Console.ReadLine()
Console.Clear()

End Sub
Sub leer_vector(ByRef v() As Integer, ByVal n As Integer)
Dim i As Integer
For i = 0 To n - 1

Randomize()
v(i) = CInt((50 * Rnd()) + 1)
Console.WriteLine("el número en la en posición {0} es {1}", i + 1, v(i))
Next

End Sub

Function hallando_B(ByVal V() As Integer, ByVal Z() As Integer, ByVal n As


Integer)
Dim suma_xlogy, suma_logx, suma_logy, suma_logx2 As Single
suma_xlogy = 0
suma_logx = 0
suma_logy = 0
suma_logx2 = 0

Dim B As Single

For i = 0 To n - 1
suma_xlogy = suma_xlogy + Math.Log(Z(i)) * V(i)
suma_logx = suma_logx + Math.Log(V(i))
suma_logy = suma_logy + Z(i)
suma_logx2 = suma_logx2 + (Math.Log(V(i))) ^ 2
B = ((sumaxlogy * n) - (suma_logx * suma_logy)) / ((n * suma_logx2) -
(suma_logx ^ 2))

Next
Return (B)
End Function
Function hallando_A(ByVal V() As Integer, ByVal Z() As Integer, ByVal n As
Integer)
Dim suma_logx, suma_y As Single
suma_logx = 0
suma_logy = 0

Dim A As Single

For i = 0 To n - 1
suma_logx = suma_logx + Math.Log(V(i))
suma_logy = suma_y + math.log(Z(i))

A = 2.71828 ^ ((suma_logy / n) - (hallando_B(V, Z, n) * (suma_logx) /


n))

Next
Return (A)
End Function

End Module

Interpolación Lineal
Module Module1

Sub Main()
Dim n As Integer
cantidad_n(n)
Dim V1(n) As Integer
Dim V2(n) As Integer
leer_vector(V1, V2, n)
max_min(V1, V2, n)

End Sub
Sub cantidad_n(ByRef n As Integer)
Console.SetCursorPosition(10, 1)
Console.ForegroundColor = ConsoleColor.Cyan

Console.WriteLine("MÉTODO DE LA INTERPOLACIÓN LINEAL")

Randomize()
n = CInt((20 * Rnd()) + 1)
Console.WriteLine("n={0}", n)
Console.ReadLine()

End Sub
Sub leer_vector(ByRef V1() As Integer, ByRef V2() As Integer, ByVal n As
Integer)
Dim i As Integer
For i = 0 To n - 1

Randomize()
V1(i) = CInt((50 * Rnd()) + 1)
V2(i) = CInt((50 * Rnd()) + 1)
Console.ForegroundColor = ConsoleColor.Cyan

Console.WriteLine("Los puntos de la recta son:")


Console.WriteLine(" ({0},{1})", V1(i), V2(i))
Next
End Sub
Sub max_min(ByVal V1() As Integer, ByVal v2() As Integer, ByVal n As Integer)
Dim i, y2, y1, x2, x1, j, m As Integer
Dim A, B As Single
x1 = V1(0)
x2 = V1(0)

For i = 0 To n - 1

If (V1(i) > x2) Then


x2 = V1(i)
j = i
End If
y2 = v2(j)

If (V1(i) < x1) Then


x1 = V1(i)
m = i
End If
y1 = v2(m)

Next
Console.ForegroundColor = ConsoleColor.Cyan

Console.WriteLine("Los puntos límites son ({0},{1}) y ({2},{3}) ", x1, y1,


x2, y2)

Console.ReadLine()
A = y1 - ((x1 * (y2 - y1)) / (x2 - x1))
B = (y2 - y1) / (x2 - x1)
Console.ForegroundColor = ConsoleColor.Cyan
Console.WriteLine("La ecuación de interpolación lineal es Y= {0} + {1} * X",
A, B)
Console.ReadLine()

End Sub
End Module

You might also like