InicioCiencia EducacionSistemas de ecuaciones Lineales de 2x2 en Vb.NET

Sistemas de ecuaciones Lineales de 2x2 en Vb.NET

Buenas, primer post que hago asi que en principio pido disculpas por la desprolijidad, si hay alguna opcion para insertar codigo, no la he visto

traigo para quien le interese, una clase hecha en vb.NET que permite calcular, la compatibilidad de un sistema de ecuaciones lineales de 2x2 como tambien los conjuntos solucion, en caso de ser determinado, devolvera el punto de interseccion de las rectas, en caso de ser indeterminado, devolvera de forma parametrica, todos los puntos comunes a ambas rectas (infinitos pares que satisfacen dicho sistema)

si desean probar la clase, incluyo un codigo de ejemplo de un formulario que posee los siguientes controles:

TXTX1, TXTY1, TXTD1 (todos textboxes, pertenecientes a la primera ecuacion)
TXTX2, TXTY2, TXTD2 (todos textboxes, pertenecientes a la segunda ecuacion)

LblSolucion: Label (mostrara compatibilidad y solucion al sistema)

CmdCalcular: Button (al presionarlo se realizaran los calculos necesarios
CmdSalir: Button (al presionarlo se abandonara la aplicacion)

Ahora si, sin mas, el codigo de la clase


Public Class cSISTEMA2X2
Public Enum SISTEMA_TIPO_SOLUCION
SCD
SCI
SI
End Enum

Public Structure VECTOR_2_C
Public X As Double
Public Y As Double
End Structure

Private _x1 As Double, _y1 As Double, _d1 As Double
Private _x2 As Double, _y2 As Double, _d2 As Double
Private m_TipoSolucion As SISTEMA_TIPO_SOLUCION
Private solucion As VECTOR_2_C

Public Sub New()
Me.solucion = New VECTOR_2_C
End Sub

Public Sub New(ByVal x1 As Double, ByVal x2 As Double, ByVal y1 As Double, ByVal y2 As Double, ByVal d1 As Double, ByVal d2 As Double)
Me.solucion = New VECTOR_2_C
Me._x1 = x1 : Me._y1 = y1 : Me._d1 = d1
Me._x2 = x2 : Me._y2 = y2 : Me._d2 = d2
End Sub

Public Property X1() As Double
Get
Return Me._x1
End Get
Set(value As Double)
Me._x1 = value
End Set
End Property

Public Property Y1() As Double
Get
Return Me._y1
End Get
Set(value As Double)
Me._y1 = value
End Set
End Property

Public Property D1() As Double
Get
Return Me._d1
End Get
Set(value As Double)
Me._d1 = value
End Set
End Property

Public Property X2() As Double
Get
Return Me._x2
End Get
Set(value As Double)
Me._x2 = value
End Set
End Property

Public Property Y2() As Double
Get
Return Me._y2
End Get
Set(value As Double)
Me._y2 = value
End Set
End Property

Public Property D2() As Double
Get
Return Me._d2
End Get
Set(value As Double)
Me._d2 = value
End Set
End Property

Public ReadOnly Property ConjSolucion() As VECTOR_2_C
Get
Return Me.solucion
End Get
End Property

Public ReadOnly Property TipoSolucion As SISTEMA_TIPO_SOLUCION
Get
Return Me.m_TipoSolucion
End Get
End Property

Public Sub Calcular()
If (Me._x1 = 0 And Me._x2 = 0) Or (Me._y1 = 0 And Me._y2 = 0) Then
'SISTEMA DE DOS POR UNO
Exit Sub
End If

Dim delta As Double
Dim deltaX As Double
Dim deltaY As Double

'CALCULAMOS LOS DETERMINANTES
delta = (Me._x1 * Me._y2) - (Me._y1 * Me._x2)
deltaX = (Me._d1 * Me._y2) - (Me._y1 * Me._d2)
deltaY = (Me._x1 * Me._d2) - (Me._d1 * Me._x2)

If delta = 0 Then
'SISTEMA INCOMPATIBLE O COMPATIBLE INDETERMINADO
If deltaX <> 0 Or deltaY <> 0 Then
'INCOMPATIBLE (EVALUAR RANGOS DE MATRICES)
Me.m_TipoSolucion = SISTEMA_TIPO_SOLUCION.SI
Else
'COMPATIBLE INDETERMINADO (EVALUAR RANGOS DE MATRICES)
Me.m_TipoSolucion = SISTEMA_TIPO_SOLUCION.SCI
End If
Me.solucion.X = Double.NaN
Me.solucion.Y = Double.NaN
Else
'RANGO = 2
'SCD
Me.solucion.X = deltaX / delta
Me.solucion.Y = deltaY / delta
End If
End Sub

Public Overrides Function ToString() As String
Dim szRet As String = ""

If Me.m_TipoSolucion = SISTEMA_TIPO_SOLUCION.SCI Then
'DEVOLVEMOS UNA CADENA CON LA FORMA PARAMETRICA DE TODOS LOS PUNTOS COMUNES A AMBAS RECTAS
If Me._x1 <> 0 Then
'DESPEJAMOS Y1 EN FUNCION DE X1
szRet = "{(x,y) ϵ R² / x = λ, y = " & (Me._d1 / Me._y1).ToString & IIf(Me._x1 / Me._y1 > 0, " - ", " + " ) & IIf(Math.Abs(Me._x1 / Me._y1) = 1, "λ", Math.Abs(Me._x1 / Me._y1) & "λ" ) & ", λ ϵ R}"
ElseIf Me._x2 <> 0 Then
'DESPEJAMOS Y2 EN FUNCION DE X2
szRet = "{(x,y) ϵ R² / (x = λ, y = " & (Me._d2 / Me._y2).ToString & IIf(Me._x2 / Me._y2 > 0, " - ", " + " ) & IIf(Math.Abs(Me._x2 / Me._y2) = 1, "λ", Math.Abs(Me._x2 / Me._y2) & "λ" ) & ", λ ϵ R}"
End If
ElseIf Me.m_TipoSolucion = SISTEMA_TIPO_SOLUCION.SCD Then
'LAS RECTAS DE CORTAN EN UN SOLO PUNTO, DEVOLVEMOS DICHO PUNTO
szRet = "{(" & Me.solucion.X & ", " & Me.solucion.Y & " )}"
Else
'RECTAS PARALELAS
szRet = "Conjunto Vacio"
End If
Return szRet
End Function
End Class


Y ahora el codigo del formulario



Private Sub CmdCalcular_Click(sender As System.Object, e As System.EventArgs) Handles CmdCalcular.Click
Dim sistema As New cSISTEMA2X2

If Not Me.Validar Then Exit Sub

Try
sistema.X1 = Convert.ToDouble(TxtX1.Text)
sistema.X2 = Convert.ToDouble(TXTX2.Text)
sistema.Y1 = Convert.ToDouble(TXTY1.Text)
sistema.Y2 = Convert.ToDouble(TXTY2.Text)
sistema.D1 = Convert.ToDouble(TXTD1.Text)
sistema.D2 = Convert.ToDouble(TXTD2.Text)
Catch ex As Exception
MsgBox("No se pudo establecer valores, asegurese de haberlos especificado correctamente", MsgBoxStyle.Exclamation + MsgBoxStyle.OkOnly, "Snoopy" )
Exit Sub
End Try

sistema.Calcular()

LblSolucion.Text = "Compatibilidad del sistema: " & vbCrLf
If sistema.TipoSolucion = cSISTEMA2X2.SISTEMA_TIPO_SOLUCION.SCI Then
LblSolucion.Text &= "Compatible Indeterminado" & vbCrLf
ElseIf sistema.TipoSolucion = cSISTEMA2X2.SISTEMA_TIPO_SOLUCION.SCD Then
LblSolucion.Text &= "Compatible Determinado" & vbCrLf
Else
LblSolucion.Text &= "Sistema Incompatible"
Exit Sub
End If

LblSolucion.Text &= vbCrLf & "Conjunto Solucion:" & vbCrLf & vbCrLf & sistema.ToString
End Sub

Public Function Validar() As Boolean
Dim bRet As Boolean = False

If TxtX1.Text = "" OrElse Not IsNumeric(TxtX1.Text) Then
bRet = False
TxtX1.BackColor = Color.Red
Else
bRet = True
TxtX1.BackColor = Color.White
End If

If TXTX2.Text = "" OrElse Not IsNumeric(TXTX2.Text) Then
bRet = False
TXTX2.BackColor = Color.Red
Else
bRet = True
TXTX2.BackColor = Color.White
End If

If TXTY1.Text = "" OrElse Not IsNumeric(TXTY1.Text) Then
bRet = False
TXTY1.BackColor = Color.Red
Else
bRet = True
TXTY1.BackColor = Color.White
End If

If TXTY2.Text = "" OrElse Not IsNumeric(TXTY2.Text) Then
bRet = False
TXTY2.BackColor = Color.Red
Else
bRet = True
TXTY2.BackColor = Color.White
End If

If TXTD1.Text = "" OrElse Not IsNumeric(TXTD1.Text) Then
bRet = False
TXTD1.BackColor = Color.Red
Else
bRet = True
TXTD1.BackColor = Color.White
End If

If TXTD2.Text = "" OrElse Not IsNumeric(TXTD2.Text) Then
bRet = False
TXTD2.BackColor = Color.Red
Else
bRet = True
TXTD2.BackColor = Color.White
End If

If (TxtX1.Text = "0" And TXTX2.Text = "0" ) Or (TXTY1.Text = "0" And TXTY2.Text = "0" ) Then
MsgBox("Solo se soporta sistemas de 2X2, no de 2X1", MsgBoxStyle.Exclamation + MsgBoxStyle.OkOnly, "Snoopy" )
End If
Return bRet
End Function

Private Sub CmdSalir_Click(sender As System.Object, e As System.EventArgs) Handles CmdSalir.Click
Application.Exit()
End Sub
Datos archivados del Taringa! original
0puntos
0visitas
0comentarios
Actividad nueva en Posteamelo
0puntos
2visitas
0comentarios
Dar puntos:

Dejá tu comentario

0/2000

Autor del Post

s
snpsnp🇦🇷
Usuario
Puntos0
Posts2
Ver perfil →
PosteameloArchivo Histórico de Taringa! (2004-2017). Preservando la inteligencia colectiva de la internet hispanohablante.

CONTACTO

18 de Septiembre 455, Casilla 52

Chillán, Región de Ñuble, Chile

Solo correo postal

© 2026 Posteamelo.com. No afiliado con Taringa! ni sus sucesores.

Contenido preservado con fines históricos y culturales.