Documentos de Académico
Documentos de Profesional
Documentos de Cultura
Module Module1
Dim nro1, nro2, suma As Integer
Sub Main()
Console.Write(" ingrese nro 1 ")
nro1 = Console.ReadLine
Console.Write(" ingrese nro 2 ")
nro2 = Console.ReadLine
suma = nro1 + nro2
Console.WriteLine(" la suma es {0}", suma)
Console.ReadLine()
End Sub
End Module
Module Module1
Dim Nro1, Nro2, Suma, resta As Integer
Sub Main()
Console.Write("ingrese nro 1 ")
Nro1 = Console.ReadLine()
Console.Write("ingrese nro 2 ")
Nro2 = Console.ReadLine()
Suma = Nro1 + Nro2
resta = Nro1 - Nro2
Console.WriteLine("La suma es {0} ", Suma)
Console.WriteLine("La resta es {0} ", resta)
Console.ReadLine()
End Sub
End Module
Module Module1
Dim Nro1, Nro2 As Single
Sub Main()
Console.Write("ingrese nro 1 ") : Nro1 = Console.ReadLine()
Console.Write("ingrese nro 2 ") : Nro2 = Console.ReadLine()
Console.WriteLine("La suma es {0} ", Nro1 + Nro2)
Console.WriteLine("La resta es {0} ", Nro1 - Nro2)
Console.ForegroundColor = ConsoleColor.Yellow
Console.WriteLine("La multiplicacion es {0} ", Nro1 * Nro2)
Console.WriteLine("La division entera es {0} ", Nro1 \ Nro2)
Console.WriteLine("La division real es {0} ", Nro1 / Nro2)
Console.ForegroundColor = 10
Console.WriteLine("el modulo es {0} ", Nro1 Mod Nro2)
Console.WriteLine("la raiz cuadrada es {0} ", Math.Sqrt(Nro1))
Console.WriteLine(" {0} elevado a {1} es {2} ", Nro1, Nro2, Math.Pow(Nro1, Nro2))
Console.WriteLine(" le fecha es {0} ", Date.Now)
Console.WriteLine(" el año es {0} ", Date.Now.Year)
Console.WriteLine(" nroo aleaorio es {0} ", Int(Rnd() * 20))
Console.SetCursorPosition(40, 12)
Console.Write("hola")
Console.ReadLine()
End Sub
End Module
Module Module1
Dim Nombre As String
Sub Main()
Console.Write("Como te llamas")
Nombre = Console.ReadLine
Console.ForegroundColor = 9
Console.Write(" *** MUCHO GUSTO DE CONOCERLO")
Console.ForegroundColor = 12
Console.BackgroundColor =14
Console.Write("<<<{0}>>>",NOMBRE)
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 3-
Console.ForegroundColor = 9
Console.BackgroundColor = 0
Console.WriteLine("ESTIMADO AMIGO")
Console.ReadLine()
End Sub
End Module
Module Module1
Dim base, altura, area As Single
Sub Main()
Console.Write("Ingrese base")
base = Console.ReadLine
Console.Write("Ingrese altura")
altura = Console.ReadLine
area = (base * altura) / 2
Console.WriteLine("el area es {0}",area)
Console.ReadLine()
End Sub
End Module
Module Module1
Dim Area, base, altura As Single
Sub Main()
Console.Write("ingrese base ")
base = Console.ReadLine
Console.Write("ingrese altura ")
altura = Console.ReadLine
Area = (base * altura) / 2
Console.WriteLine(" el area es {0} ", Area)
Console.ReadLine()
End Sub
End Module
Module Module1
Dim Area, radio As Single
Sub Main()
' este programa calcula area del radio
Console.Write("ingrese radio ")
radio = Console.ReadLine
Area = Math.PI * Math.Pow(radio, 2)
Console.ForegroundColor = 10
Console.WriteLine(" el area del circulo {0} ", Area)
Console.ReadLine()
End Sub
End Module
Module Module1
Dim AreaBase, arealateral, areatotal, radio, altura As Single
Dim volumen As Single
Sub Main()
' este programa calcula area del radio
Console.Write("ingrese radio ")
radio = Console.ReadLine
Console.Write("ingrese altura ")
altura = Console.ReadLine
AreaBase = Math.PI * Math.Pow(radio, 2)
Console.ForegroundColor = 10
Console.WriteLine(" el area de la base es {0} ", AreaBase)
arealateral = 2 * Math.PI * radio * altura
Console.WriteLine(" el area lateral es {0} ", arealateral)
areatotal = 2 * AreaBase + arealateral
Console.WriteLine(" el area total es {0} ", areatotal)
volumen = AreaBase * altura
Console.WriteLine(" el volumen es {0} ", volumen)
Console.ReadLine()
End Sub
End Module
PROBLEMAS
1. AREA DEL Trapecio
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 6-
Sub Main()
Console.Write("INGRESE x1 ") : x1 = Console.ReadLine()
Console.Write("INGRESE y1 ") : y1 = Console.ReadLine()
Console.Write("INGRESE x2 ") : x2 = Console.ReadLine()
Console.Write("INGRESE y2 ") : y2 = Console.ReadLine()
de = Math.Sqrt(Math.Pow(x2 - x1, 2) + Math.Pow(y2 - y1, 2))
dr = Math.Abs(x2 - x1) + Math.Abs(y2 - y1)
Console.WriteLine("Euclidiana (X1,Y1) {0}:{1} Y (X2,Y2) {2}:{3} = {4} ", _
x1, y1, x2, y2, de)
Console.WriteLine("Rectilinea (X1,Y1) {0}:{1} Y (X2,Y2) {2}:{3} = {4} ", _
x1, y1, x2, y2, dr)
Console.ReadLine()
End Sub
End Module
1 2 3 4 5 6 7 8 9 r 11
1 e
2 1 2 3 4 5 6
3 7 x1 y1 2 2
4 8 x2 y2 7 8
5 9
6 10
7 11
8 2
9
Module Module1
Dim BaseMenor, BaseMayor, Area, altura As Single
Sub Main()
Console.Write("INGRESE Base Menor")
BaseMenor = Console.ReadLine()
Console.Write("INGRESE BaseMayor")
BaseMayor = Console.ReadLine()
Console.Write("INGRESE ALtura")
altura = Console.ReadLine()
Area = (BaseMenor + BaseMayor) / 2 * altura
REM este programa calcula area del trapecio
Console.Write("el area es {0}", Area)
Console.ReadLine()
End Sub
End Module
Encuentre los puntos y grafique el triangulo
Elabore el área del triángulo en modo formulario
Module Module1
Dim x1, x2, x3, y1, y2, y3 As Single
Dim a, b, c, p, area As Single
Sub Main()
X1 = 10 : Y1 = 2
X2 = 10 : Y2 = 12
X3 = 20 : Y3 = 12
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 8-
Module Module1
Dim x1, x2, x3, y1, y2, y3 As Single
Dim a, b, c, p, area As Single
Sub Main()
Console.Write("x1 ") : x1 = Console.ReadLine
Console.Write("y1 ") : y1 = Console.ReadLine
Console.Write("x2 ") : x2 = Console.ReadLine
Console.Write("y2 ") : y2 = Console.ReadLine
Console.Write("x3 ") : x3 = Console.ReadLine
Console.Write("y3 ") : y3 = Console.ReadLine
a = Math.Sqrt(Math.Pow(X2 - X1, 2) + Math.Pow(Y2 - Y1, 2))
b = Math.Sqrt(Math.Pow(x3 - x2, 2) + Math.Pow(y3 - y2, 2))
c = Math.Sqrt(Math.Pow(x3 - x1, 2) + Math.Pow(y3 - y1, 2))
p = 1 / 2 * (a + b + c)
area = Math.Sqrt(p * (p - a) * (p - b) * (p - c))
Console.WriteLine(" valor de a ={0} ", a)
Console.WriteLine(" valor de b ={0} ", b)
Console.WriteLine(" valor de c ={0} ", c)
Console.WriteLine(" perimetro ={0} ", p * 2)
Console.WriteLine("area es {0} ", area)
Console.ReadLine()
End Sub
End Module
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 9-
Module Module1
Dim N1, N2, mayor As Single
Sub Main()
'N1 = 3 'N2 = 2
Console.Write(" ingrese Nro 1 ")
N1 = Console.ReadLine
Console.Write(" ingrese Nro 2 ")
N2 = Console.ReadLine
If (N1 > N2) Then
mayor = N1
Else
mayor = N2
End If
Console.WriteLine(" le mayor es {0} ", mayor)
Console.ReadLine()
End Sub
End Module
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 10-
Mayor de 3 numeros
Module Module1
Dim N1, N2, N3, mayor As Single
Sub Main()
Console.Write(" ingrese Nro 1 ")
N1 = Console.ReadLine
Console.Write(" ingrese Nro 2 ")
N2 = Console.ReadLine
Console.Write(" ingrese Nro 3 ")
N3 = Console.ReadLine
mayor = N1
If (N2 > mayor) Then mayor = N2
If (N3 > mayor) Then mayor = N3
Console.WriteLine(" le mayor es {0} ", mayor)
Console.ReadLine()
End Sub
End Module
Mayor de 5 numeros
Module Module1
Dim N1, N2, N3, N4, mayor As Single
Sub Main()
Console.Write(" ingrese Nro 1 ")
N1 = Console.ReadLine
Console.Write(" ingrese Nro 2 ")
N2 = Console.ReadLine
Console.Write(" ingrese Nro 3 ")
N3 = Console.ReadLine
Console.Write(" ingrese Nro 4 ")
N4 = Console.ReadLine
mayor = N1
If (N2 > mayor) Then mayor = N2
If (N3 > mayor) Then mayor = N3
If (N4 > mayor) Then mayor = N4
Console.WriteLine(" le mayor es {0} ", mayor)
Console.ReadLine()
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 11-
End Sub
End Module
Module Module1
Dim Nro As Integer
Dim numletras As String
Dim SIGNO As String
Sub Main()
Console.Write(" ingrese Nro ")
Nro = Console.ReadLine
If Nro >= 0 Then
SIGNO = "(+) MAS"
Else
SIGNO = "(-) MENOS"
End If
Select Case Math.Abs(Nro)
Case 0 : numletras = "CERO"
Case 1 : numletras = "UNO "
Case 2 : numletras = "DOS "
Case 3 : numletras = "TRES "
Case 4 : numletras = "CUATRO"
Case 5 : numletras = "CINCO"
Case 6 : numletras = "SEIS "
Case 7 : numletras = "SIETE"
Case 8 : numletras = "OCHO"
Case 9 : numletras = "NUEVE"
Case Else : numletras = " ERROR TIENE QUE SOLO UN DIGITO"
End Select
Console.Write(" {0} EN LETRAS ES ", Nro)
Console.ForegroundColor = ConsoleColor.Blue
Console.Write(" {0} ", SIGNO)
Console.ForegroundColor = ConsoleColor.Yellow
Console.Write("{0} ", numletras)
Console.ReadLine()
End Sub
End Module
Module Module1
Dim N As Integer
Dim Nro As Single ' variable para almacenar los numeros queleo
Dim mayor As Single = -1000000
Sub Main()
Dim i As Integer = 0 ' contador
Console.Write(" ingrese cntidad de numeros que quiere procesar ")
N = Console.ReadLine
While (i < N)
Console.Write(" ingrese nro {0} ", i)
Nro = Console.ReadLine
If Nro > mayor Then mayor = Nro
i=i+1
End While
Console.WriteLine(" el mayor es {0} ", mayor)
Console.ReadLine()
End Sub
End Module
Module Module1
Dim N As Integer
Dim Nro As Single ' variable para almacenar los numeros queleo
Dim mayor As Single = -1000000
Sub Main()
Dim i As Integer = 0 ' contador
Console.Write(" ingrese cntidad de numeros que quiere procesar ")
N = Console.ReadLine
For i = 1 To N
Console.Write(" ingrese nro {0} ", i)
Nro = Console.ReadLine
If Nro > mayor Then mayor = Nro
Next i
Console.WriteLine(" el mayor es {0} ", mayor)
Console.ReadLine()
End Sub
End Module
EJERCICIOS
1. valores de una funcion f(x)
2. valores de una funcion f(x,y)
3. sumatorias
4. graficos en modos consola. ejemplo un cuadro un marco, lineas , creacion del
alumno
Module Module1
Sub Main()
Dim x, y, dx, lix, lsx As Single
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 15-
lix = -3
lsx = 4
dx = 0.5
For x = lix To lsx Step dx
y = Math.Pow(x, 2)
Console.WriteLine("{0:F2}{1}{2:F2}", x, vbTab, y)
Next
Console.ReadLine()
End Sub
End Module
Module Module1
Sub Main()
Dim x, y, dx, lix, lsx As Single
Dim cx, cy, ex, ey As Integer
lix = -6
lsx = 6
dx = 0.1
cx = 40
cy = 20
ex = 6
ey = -2
For x = lix To lsx Step dx
y = Math.Sin(x)
' Console.WriteLine("{0:F2}{1}{2:F2}", x, vbTab, y)
Console.SetCursorPosition(cx + x * ex, cy + y * ey)
Console.Write("*")
Next
Console.ReadLine()
End Sub
End Module
Module Module1
Sub Main()
Dim f, c As Integer
' horizontales
Console.BackgroundColor = 10
Console.Clear()
Console.ForegroundColor = ConsoleColor.Red
Console.BackgroundColor = ConsoleColor.Red
For c = 20 To 60
Console.SetCursorPosition(c, 4)
Console.Write("*")
Console.SetCursorPosition(c, 16)
Console.Write("*")
Next
For c = 30 To 50
Console.SetCursorPosition(c, 10)
Console.Write("*")
Next
For f = 4 To 16
Console.SetCursorPosition(20, f) : Console.Write("*")
Console.SetCursorPosition(30, f) : Console.Write("*")
Console.SetCursorPosition(40, f) : Console.Write("*")
Console.SetCursorPosition(50, f) : Console.Write("*")
Console.SetCursorPosition(60, f) : Console.Write("*")
Next
Console.ReadLine()
End Sub
End Module
Espiral decreciente
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 17-
Module Module1
Sub Main()
Dim vel As Integer = 10
Dim x1, x2, y1, y2, pasox, pasoy As Integer
Console.ForegroundColor = ConsoleColor.Blue
pasox = 6 : pasoy = 2 : x1 = 1 : x2 = 78 : y1 = 1 : y2 = 24
Dim f, c, k As Integer
Dim nvueltas As Integer = 6
For k = 1 To 5
x2 = x2 - pasox
For c = x1 To x2
Console.SetCursorPosition(c, y1)
Console.Write("X")
System.Threading.Thread.Sleep(vel) ' // derecha
Next
y2 = y2 - pasoy
For f = y1 To y2
Console.SetCursorPosition(x2, f)
Console.Write("X")
System.Threading.Thread.Sleep(vel) ' // abajo
Next
x1 = x1 + pasox
For c = x2 To x1 Step -1
Console.SetCursorPosition(c, y2)
Console.Write("X")
System.Threading.Thread.Sleep(vel) ' // izqueirda
Next
y1 = y1 + pasoy
For f = y2 To y1 Step -1
Console.SetCursorPosition(x1, f)
Console.Write("X")
System.Threading.Thread.Sleep(vel) ' // izqueirda
Next f
Next k
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 18-
Console.ReadLine()
End Sub
End Module
Module Module1
Sub Main()
Dim x1, y1, x2, y2, pasoy, pasox As Integer
x1 = 1 : y1 = 1 : x2 = 73 : y2 = 22 : pasoy = 3 : pasox = 8
Dim fila, col As Integer
Console.BackgroundColor = 4
Console.Clear()
'***********// horizontales
Console.ForegroundColor = 10
Console.BackgroundColor = 10
For fila = y1 To y2 Step pasoy
For col = x1 To x2
Console.SetCursorPosition(col, fila)
Console.Write("*")
Next
Next
'***********verticales
For col = x1 To x2 Step pasox
For fila = y1 To y2
Console.SetCursorPosition(col, fila)
Console.Write("*")
Next
Next
Console.ReadLine()
End Sub
End Module
Module Module1
Dim cki As ConsoleKeyInfo
Sub Main()
Randomize()
Dim Cadena As String = "HOLA"
Dim cx, cy, x1, y1, x2, y2, pasox, pasoy, rx, ry As Integer
x1 = 2 : y1 = 2 : x2 = 78 : y2 = 24 : pasox = 2 : pasoy = 1
cx = 40 : cy = 12
Console.SetCursorPosition(cx, cy)
Console.Write(Cadena)
Do
Console.ForegroundColor = 0
Console.SetCursorPosition(cx, cy)
Console.Write(Cadena)
rx = -pasox + Int(Rnd() * pasox * 2)
ry = -pasoy + Int(Rnd() * pasoy * 2)
If cx + rx > x1 And cx + rx < x2 Then cx = cx + rx
If cy + ry > y1 And cy + ry < y2 Then cy = cy + ry
Console.ForegroundColor = 14
Console.SetCursorPosition(cx, cy)
Console.Write(Cadena)
System.Threading.Thread.Sleep(100)
Loop While cki.Key <> ConsoleKey.Escape
End Sub
End Module
Module Module1
Sub Main()
Dim x, y, lix, lsx, dx As Single
lix = -3 : lsx = 3 : dx = 0.5
For x = lix To lsx Step dx
y = Math.Pow(x, 2)
Console.WriteLine("{0:F2}{1}{2:f2}", x, vbTab, y)
Next
Console.ReadLine()
End Sub
End Module
Module Module1
Sub Main()
Dim x, y, lix, lsx, dx, cx, cy, ex, ey As Single
cx = 40 : cy = 12 : ex = 1 : ey = -1
lix = -3 : lsx = 3 : dx = 0.5
Console.ForegroundColor = 14
'Console.BackgroundColor = 14
For x = lix To lsx Step dx
y = Math.Pow(x, 2)
Console.SetCursorPosition(cx + x * ex, cy + y * ey)
Console.Write("*")
Next
Console.ReadLine()
End Sub
End Module
Module Module1
Sub Main()
Dim x, y, lix, lsx, dx, cx, cy, ex, ey As Single
cx = 40 : cy = 12 : ex = 10 : ey = -10
lix = -3 : lsx = 3 : dx = 0.1
'coordenada x
Console.ForegroundColor = ConsoleColor.Blue
For x = 1 To 78
Console.SetCursorPosition(x, cy)
Console.Write("=")
Next
'coordenada y
Console.ForegroundColor = ConsoleColor.Blue
For y = 1 To 24
Console.SetCursorPosition(cx, y)
Console.Write("=")
Next
For x = lix To lsx Step dx
y = Math.Sin(x)
Console.ForegroundColor = 14
Console.SetCursorPosition(cx + x * ex, cy + y * ey)
Console.Write("*")
y = Math.Cos(x)
Console.ForegroundColor = 10
Console.SetCursorPosition(cx + x * ex, cy + y * ey)
Console.Write("*")
y = 0.5 * x
Console.ForegroundColor = 12
Console.SetCursorPosition(cx + x * ex, cy + y * ey)
Console.Write("*")
'Console.WriteLine("{0:F2}{1}{2:f2}", x, vbTab, y)
Next
Console.ReadLine()
End Sub
End Module
Graficar varias funciones en varios ejes de coordenadas
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 22-
En modo formulario
Module Module1
Sub Main()
Console.WriteLine(" Timestring {0} ", Now)
Console.WriteLine("DATE {0} ", Now.Date)
Console.WriteLine("AÑO {0} ", Now.Year)
Console.WriteLine("MES {0} ", Now.Month)
Console.WriteLine("DIA {0} ", Now.Day)
Console.WriteLine("DIA SEMANA{0} ", Now.DayOfWeek)
Console.WriteLine("DIA AÑO{0} ", Now.DayOfYear)
Console.WriteLine("HORA {0} ", Now.Hour)
Console.WriteLine("MINUTE {0} ", Now.Minute)
Console.WriteLine("SEGUNDO {0} ", Now.Second)
Console.ReadLine()
End Sub
End Module
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 24-
NUMERO PRIMO
Module Module1
Dim NRO As Integer
Sub Main()
Dim I As Integer
Console.Write("INGRESE UN NRO ENTERO ")
NRO = Console.ReadLine
For I = 2 To NRO - 1
If NRO Mod I = 0 Then
Console.WriteLine(" {0} no es PRIMO", NRO)
GoTo fin
End If
Next
Console.WriteLine(" {0} SI ES PRIMO", NRO)
fin:
Console.ReadLine()
End Sub
End Module
Module Module1
Dim NRO As Integer
Sub Main()
Dim I, control As Integer
Console.Write("INGRESE UN NRO ENTERO ")
NRO = Console.ReadLine
For I = 2 To NRO - 1
If NRO Mod I = 0 Then
control = 1
Exit For
End If
Next
If control = 1 Then
Console.WriteLine(" {0} *** NO ES PRIMO", NRO)
Else
Console.WriteLine(" {0} ES PRIMO ", NRO)
End If
Console.ReadLine()
End Sub
End Module
OTRA FORMA
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 25-
Module Module1
Dim NRO As Integer
Sub Main()
Dim cadena = " ES PRIMO"
Dim I As Integer
Console.Write("INGRESE UN NRO ENTERO ")
NRO = Console.ReadLine
For I = 2 To NRO - 1
If NRO Mod I = 0 Then
cadena = "NO ES PRIMO"
Exit For
End If
Next
Console.WriteLine(" {0} {1}", NRO, cadena)
Console.ReadLine()
End Sub
End Module
Module Module1
Dim NRO As Integer ' Para evaluar si ese numero es primo o no
Dim n As Integer '' el numero limite para listado de primos
Sub Main()
Dim cadena = " ES PRIMO"
Dim I, j As Integer
Console.Write("INGRESE UN NRO ENTERO cantidad de nros ")
n = Console.ReadLine
For j = 1 To n
NRO = j
cadena = " ES PRIMO"
For I = 2 To NRO - 1
If NRO Mod I = 0 Then
cadena = "NO ES PRIMO"
Exit For
End If
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 26-
Next
Console.WriteLine(" {0} {1}", NRO, cadena)
Next j
Console.ReadLine()
End Sub
End Module
Module Module1
Dim n As Integer '' el numero limite para listado de primos
Sub Main()
Dim I, j, control As Integer
Console.Write("INGRESE UN NRO ENTERO cantidad de nros ")
n = Console.ReadLine
For j = 1 To n
control = 0
For I = 2 To j - 1
If j Mod I = 0 Then
control = 1
Exit For
End If
Next I
If control = 0 Then Console.Write(" {0} {1}", j, vbTab)
Next j
Console.ReadLine()
End Sub
End Module
Module Module1
Dim li, ls As Integer '' el numero limite para listado de primos
Sub Main()
Dim I, j, control As Integer
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 27-
Module Module1
Dim n As Integer '' el numero limite para listado de primos
Sub Main()
Dim I, j, control, cont As Integer
Console.Write("INGRESE cantidad de numeros que quieres generar ")
n = Console.ReadLine
cont = 1
For j = 1 To 1000
control = 0
For I = 2 To j - 1
If j Mod I = 0 Then
control = 1
Exit For
End If
Next I
If control = 0 Then
Console.Write(" {0} {1}", j, vbTab)
cont = cont + 1
End If
If cont > n Then Exit For
Next j
Console.ReadLine()
End Sub
End Module
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 28-
Solución
Module Module1
Sub Main()
Dim x, y, z As Integer
' Console.WriteLine("{0,8}{1,8}{2,8}", "x", "y", "z")
For x = 1 To 12
For y = 1 To 12 Step 1
z=x*y
Console.Write("{0,4}", z)
Next
Console.WriteLine()
Next
Console.ReadLine()
End Sub
End Module
Module Module1
Sub Main()
Dim fila, col, k, pasocol As Integer
pasocol = 4
Do
For k = 1 To 14
Console.ForegroundColor = k
Console.BackgroundColor = 14 - k
For fila = 1 To 12
For col = 1 To 12
Console.SetCursorPosition(col * pasocol, fila)
Console.Write("{0,4}", fila * col)
Next col
Console.WriteLine()
Next fila
System.Threading.Thread.Sleep(200)
Next k
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 29-
Loop
Console.ReadLine()
End Sub
End Module
Module Module1
Dim mensaje As String = "HOLA"
Dim borrador As String = " "
Sub Main()
Dim Y1, col, x1, x2 As Integer
Y1 = 2 : x1 = 20 : x2 = 30
Dim color As Integer = 1
Do
If color > 14 Then
color = 1
Else
color = color + 1
End If
Console.ForegroundColor = color
For col = x1 To x2
Console.SetCursorPosition(col, Y1)
Console.Write(mensaje)
System.Threading.Thread.Sleep(100) ' // derecha
Console.SetCursorPosition(col, Y1)
Console.Write(borrador)
Next
Loop
Console.ReadLine()
End Sub
End Module
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 30-
Module Module1
Dim mensaje As String = "HOLA"
Dim borrador As String = " "
Sub Main()
Dim col, fila, x1, x2, y1, y2 As Integer
y1 = 10 : y2 = 20 : x1 = 20 : x2 = 50
Dim color As Integer = 1
Do
If color > 14 Then
color = 1
Else
color = color + 1
End If
Console.ForegroundColor = color
For col = x1 To x2 ' derecha
Console.SetCursorPosition(col, Y1)
Console.Write(mensaje)
System.Threading.Thread.Sleep(100) ' // derecha
Console.SetCursorPosition(col, Y1)
Console.Write(borrador)
Next
For fila = y1 To y2 ' abajo
Console.SetCursorPosition(x2, fila)
Console.Write(mensaje)
System.Threading.Thread.Sleep(100) ' // derecha
Console.SetCursorPosition(x2, fila)
Console.Write(borrador)
Next
For col = x2 To x1 Step -1 ' izquierda
Console.SetCursorPosition(col, y2)
Console.Write(mensaje)
System.Threading.Thread.Sleep(100) ' // derecha
Console.SetCursorPosition(col, y2)
Console.Write(borrador)
Next
For fila = y2 To y1 Step -1 ' arriba
Console.SetCursorPosition(x1, fila)
Console.Write(mensaje)
System.Threading.Thread.Sleep(100) ' // derecha
Console.SetCursorPosition(x1, fila)
Console.Write(borrador)
Next
Loop
Console.ReadLine()
End Sub
End Module
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 31-
Marco
Module Module1
Dim mensaje As String = "HOLA"
Dim borrador As String = " "
Sub Main()
Dim col, fila, x1, x2, y1, y2 As Integer
y1 = 10 : y2 = 20 : x1 = 20 : x2 = 50
Console.ForegroundColor = 12
For col = x1 To x2 ' derecha
Console.SetCursorPosition(col, y1) : Console.Write("*")
Console.SetCursorPosition(col, y2) : Console.Write("*")
Next
For fila = y1 To y2 ' abajo
Console.SetCursorPosition(x1, fila) : Console.Write("*")
Console.SetCursorPosition(x2, fila) : Console.Write("*")
Next
Console.ReadLine()
End Sub
End Module
Cuadro
' cuadro
Module Module1
Sub Main()
Dim x1, y1, ancho, alto, col, k As Integer
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 32-
x1 = 20 : y1 = 2
ancho = 40
alto = 20
Dim pasoalto As Integer = 1
Dim pasoancho As Integer = 1
For k = 1 To 10
Console.ForegroundColor = 15 - k
Console.BackgroundColor = 15 - k
For fila = 0 To alto
For col = 0 To ancho
Console.SetCursorPosition(col + x1, fila + y1)
Console.Write("*")
Next
Next
alto = alto - pasoalto * 2
ancho = ancho - pasoancho * 2
x1 = x1 + pasoancho
y1 = y1 + pasoalto
Next
Console.ReadLine()
End Sub
End Module
Ejemplo de sonido
Module Module1
Dim frec, durac, i As Integer
Sub Main()
For i = 1 To 10
frec = 10 + Int(Rnd() + 500)
durac = 10 + Int(Rnd() + 200)
Console.Beep(frec, durac)
Next
Console.ReadLine()
End Sub
End Module
Module Module1
Sub Main()
Dim i = 1, suma = 0, n As Integer = 3
Console.Write("ingrese cantidad de numeros a sumar ")
n = Console.ReadLine()
While (i <= n)
Console.Write("{0} ", i)
suma += i
i=i+1
End While
Console.WriteLine(" la suma con while es {0} ", suma)
suma = 0
i=1
Do
Console.Write("{0} ", i)
suma += i
i=i+1
Loop While (i <= n)
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 34-
Module Module1
Function SUMA(N1 As Single, _
N2 As Single) As Single
Dim S As Single
S = N1 + N2
'Return S
SUMA = S
End Function
Sub Main()
Dim A, B, RES As Single
A=2:B=3
RES = SUMA(A, B)
Console.WriteLine("LA SUMA ES {0}", RES)
Console.ReadLine()
End Sub
End Module
Factorial de un numero
Module Module1
Sub MAIN()
Dim N As Integer = 100
Console.Write("ingrese n 1.. 20")
N = Console.ReadLine
Dim I As Integer ' CONTADOR '
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 35-
Dim F As Double = 1
For I = 1 To N
F=F*I
Next
Console.WriteLine(" el factorial es {0} ", F)
Console.ReadLine()
End Sub
End Module
Module Module1
Function factorial(n As Integer) As Integer
Dim I As Integer ' CONTADOR '
Dim F As Double = 1
For I = 1 To n
F=F*I
Next
Return F
End Function
Sub MAIN()
Dim Nro, Fac As Integer
Console.Write("ingrese n 1.. 20 ")
Nro = Console.ReadLine
Fac = factorial(Nro)
Console.WriteLine(" el factorial es {0} ", Fac)
Console.ReadLine()
End Sub
End Module
Module Module1
Function factorial(n As Integer) As Integer
Dim I As Integer ' CONTADOR '
Dim F As Double = 1
For I = 1 To n
F=F*I
Next
Return F
End Function
Sub MAIN()
' 2C3=
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 36-
Potencia de un numero
Module Module1
Sub MAIN()
Dim base As Single = 8
Dim exponente As Single = 1 / 3
Dim poten As Single
poten = Math.Pow(base, exponente)
Console.WriteLine(" {0} elevado a {1} es = {2} ", base, exponente, poten)
Console.ReadLine()
End Sub
End Module
Module Module1
Function Potencia(base As Single, exponente As Single) As Single
Return Math.Pow(base, exponente)
End Function
Sub MAIN()
Dim base As Single = 8
Dim exponente As Single = 1 / 3
Dim poten As Single
poten = Potencia(base, exponente)
Console.WriteLine(" {0} elevado a {1} es = {2} ", base, exponente, poten)
Console.ReadLine()
End Sub
End Modul
Module Module1
Function Potencia(base As Single, n As Integer) As Single
Dim i As Integer
Dim producto As Single = base
For i = 1 To n - 1
producto = producto * base
Next
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 37-
Return producto
End Function
Sub MAIN()
Dim base As Single = 2
Dim exponente As Integer = 3
Dim poten As Single
poten = Potencia(base, exponente)
Console.WriteLine(" {0} elevado a {1} es = {2} ", base, exponente, poten)
Console.ReadLine()
End Sub
End Module
Calcular la formula
' X3 X5 X7
'Sen(x) = x- ---- + ---- - --- + ...
' 3! 5! 7!
Module Module1
Sub MAIN()
Dim x As Single = Math.PI / 4
Dim suma As Single = 0
Dim n As Integer = 10
Dim i As Integer
Dim signo As Integer = 1
For i = 1 To n Step 2
suma = suma + signo * Potencia(x, i) / factorial(i)
signo = signo * (-1)
Next
Console.WriteLine(" el seno de {0} con {1} terminos es {2} ", x, n, suma)
Console.ReadLine()
End Sub
End Module
Module Module1
Function f(x As Single) As Single
' Return x * x
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 38-
f = Math.Pow(x, 2)
End Function
Sub MAIN()
Dim x, y As Single
x=2
y = f(x)
Console.WriteLine("{0} {1} {2} ", x, vbTab, y)
Console.ReadLine()
End Sub
End Module
Module Module1
Function f(x As Single) As Single
' Return x * x
f = Math.Pow(x, 2)
End Function
Sub MAIN()
Dim x, y As Single
x=2
y = f(x)
For x = -3 To 3 Step 0.5
y = f(x)
Console.WriteLine("{0:f2} {1} {2:F2} ", x, vbTab, y)
Next
Console.ReadLine()
End Sub
End Module
Module Module1
Function f(x As Single, Y As Single) As Single
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 39-
' Return x * x
f = Math.Pow(x, 2) + Math.Pow(Y, 2)
End Function
Sub MAIN()
Dim x, y, z As Single
'x = 2
'z = f(x, y)
'Console.WriteLine("{0} {1} {2}", x, y, z)
For y = -2 To 2 Step 1
Console.WriteLine()
For x = -2 To 2 Step 1
z = f(x, y)
Console.Write("{0:f2} {1} ", z, vbTab)
Next x
Next y
Console.ReadLine()
End Sub
End Module
Module Module1
Sub MAIN()
Dim cx, cy, ancho, alto, fila, col As Integer
cx = 10 : cy = 2
ancho = 20 : alto = 10
Console.ForegroundColor = 10
Console.BackgroundColor = 4
For fila = 0 To alto
For col = 0 To ancho
Console.SetCursorPosition(cx + col, cy + fila)
Console.Write("*")
Next
Next
Console.ReadLine()
End Sub
End Module
Con funciones
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 40-
Module Module1
Sub Cuadro(cx As Integer, cy As Integer, ancho As Integer, alto As Integer)
Dim fila, col As Integer
For fila = 0 To alto
For col = 0 To ancho
Console.SetCursorPosition(cx + col, cy + fila)
Console.Write("*")
Next
Next
End Sub
Sub MAIN()
Console.ForegroundColor = 10
Console.BackgroundColor = 4
Cuadro(10, 2, 20, 12)
Console.ReadLine()
End Sub
End Module
Module Module1
Sub main()
Dim n1, n2, suma As Single
Console.Write(" ingrese n1 :")
n1 = Console.ReadLine
Console.Write(" ingrese n2 : ")
n2 = Console.ReadLine
suma = n1 + n2
Console.WriteLine(" la suma es {0} ", suma)
Console.ReadLine()
End Sub
End Module
En Modo formulario
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 41-
Forma corta
Case 1 : res = n1 + n2
Case 2 : res = n1 - n2
Case 3 : res = n1 * n2
End Select
txtRes.Text = res
End Sub
End Class
graficos
Código
Public Class Form1
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 43-
PictureBox1.Load(OpenFileDialog1.FileName)
End Sub
End Class
PRUEBE La funciones
Grafico.DrawClosedCurve()
Grafico.DrawPolygon()
Grafico.FillClosedCurve()
Grafico.DrawClosedCurve()
Dibuje polígonos regulares
RESUMEN
pag fecha TIPO
1 23-Mar practica
3 VIERNES 06 DE ABRIL DEL 2018 TEORIA
PRACTICA
Practicas del dia martes 10 de abril del 2018
7 S
9 VIERNES 13 DE ABRIL TEORIA
15 VIERNES 13 DE ABRIL PRACTICA
19 MARTES 17 DE ABRIL PRACTICA
23 VIERNES 20 DE ABRIL TEORIA
MARTRES 24 DE ABRIL PRACTICA
1 1MAYO DEL ABRIL FERIADO
FUNCIONE
24 VIERNES 4 DE MAYO TEORIA S
PRACTICA
30
VIERNES 4 DE MAYO S
Module Module1
Sub Main()
Dim NRO1, NRO2, RES As Single
NRO1 = 2 : NRO2 = 3
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 45-
Module Module2
Function SUMA(N1 As Single, N2 As Single) As Single
Dim S1 As Single
S1 = N1 + N2
Return S1
'SUMA = S1
End Function
End Module
Module Module1
Sub INGRESAR(ByRef A As Single, ByRef B As Single)
Console.Write(" INGRESE NRO 1 ")
A = Console.ReadLine
Console.Write(" INGRESE NRO 2 ")
B = Console.ReadLine
End Sub
Function SUMA(N1 As Single, N2 As Single) As Single
Return N1 + N2
End Function
Sub main()
Dim RES As Single
Dim x As Single = 10
Dim y As Single = 50
INGRESAR(x, y)
RES = SUMA(x, y)
Console.WriteLine("x= {0} y ={1} SUMA {2} ", x, y, RES)
Console.ReadLine()
End Sub
End Module
ColorDialog1.ShowDialog()
pluma.Color = ColorDialog1.Color
End Sub
Module Module1
Function f(ByVal x As Single) As Single
Return x * x
End Function
Function Trapecial(ByVal a As Single, ByVal b As Single, ByVal n As Integer) As
Single
Dim at As Single = 0, ap, dx, x, y1, y2 As Single
dx = (b - a) / n
For x = a To b - dx Step dx
y1 = f(x)
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 51-
y2 = f(x + dx)
ap = (y1 + y2) / 2 * dx
at = at + ap
Next
Return at
End Function
End Module
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
GRAFICO = PictureBox1.CreateGraphics
pluma = New Pen(Brushes.Green, 4)
brocha = New SolidBrush(Color.Aqua) : grosor = 4
pluma.Width = grosor : x = 100 : y = 300 : alto = 100
teta = 3 * Math.PI / 2.0 : w = 0.6 : paro = 20 : rama = 1.4
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 52-
Dim Ex As Integer = 80
Dim Ey As Integer = -50
Dim MiFuente As New Font("Verdana", 12, FontStyle.Bold)
Sub ObtenerDatos()
a = txtA.Text
b = txtB.Text
n = txtN.Text
End Sub
Sub PrepararGrafico()
brocha.Color = Color.Yellow
Grafico.DrawString(CStr(a), MiFuente, brocha, Cx + a * Ex, Cy)
Grafico.DrawString(CStr(b), MiFuente, brocha, Cx + b * Ex, Cy)
lapiz.Color = Color.Brown
lapiz.Width = 1
Grafico.DrawLine(lapiz, Cx, 0, Cx, PictureBox1.Height)
Grafico.DrawLine(lapiz, 0, Cy, PictureBox1.Width, Cy)
lapiz.Color = Color.Red
lapiz.Width = 2
brocha.Color = Color.Green
End Sub
Private Sub btnTrapecial_Click(sender As Object, e As EventArgs) Handles
btnTrapecial.Click
Dim x, y, dx, x1, y1, x2, y2 As Single
ObtenerDatos()
area = Trapecial(a, b, n)
txtAREA.Text = area
PrepararGrafico()
dx = (b - a) / n
For x = a To b - dx Step dx
x1 = x
y1 = f(x1)
x2 = x1 + dx
y2 = f(x2)
' grafico de los trapecios
Dim np As Integer = 4
Dim VX(4) As Single
Dim VY(4) As Single
VX(0) = x1 : VY(0) = y1
VX(1) = x2 : VY(1) = y2
VX(2) = x2 : VY(2) = 0
VX(3) = x1 : VY(3) = 0
GraficarPoligono(Cx, Cy, VX, VY, Ex, Ey, np)
Next
brocha.Color = Color.Azure
Grafico.DrawString("METODO TRAPECIAL", MiFuente, brocha, 10, 10)
End Sub
Sub ObtenerDatosGrafico()
Cx = Val(txtCx.Text)
Cy = Val(txtCy.Text)
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 55-
Ex = Val(txtEx.Text)
Ey = Val(txtEy.Text)
End Sub
Next
brocha.Color = Color.Indigo
Grafico.DrawString("METODO RECTANGULOS CIRCUNSCRITOS", MiFuente,
brocha, 10, 10)
End Sub
Module Module1
Function f(ByVal x As Single) As Single
Return x * x
' Return Math.Sin(x)
End Function
Function circunscritos(ByVal a As Single, ByVal b As Single, ByVal n As Integer) As
Single
Dim at As Single = 0, ap As Single, dx As Single, x As Single, y As Single
dx = (b - a) / n
For x = a + dx To b Step dx
y = f(x)
ap = dx * y
at = at + ap
Next
Return at
End Function
Function inscritos(ByVal a As Single, ByVal b As Single, ByVal n As Integer) As
Single
Dim at As Single = 0, ap As Single, dx As Single, x As Single, y As Single
dx = (b - a) / n
For x = a To b - dx Step dx
y = f(x)
ap = dx * y
at = at + ap
Next
Return at
End Function
y2 = f(x + dx)
ap = (y1 + y2) / 2 * dx
at = at + ap
Next
Return at
End Function
Function Simpson(ByVal a As Single, ByVal b As Single, ByVal n As Integer) As
Single
Dim at As Single = 0, ap, h, x As Single
h = (b - a) / n
For x = a To b - h Step 2 * h
ap = h / 3 * (f(x) + 4 * f(x + h) + f(x + 2 * h))
at = at + ap
Next
Return at
End Function
End Module
Module Module1
Function f(x As Single) As Single
Return (x - 2) * (x + 1)
End Function
Sub Main()
Dim x, y, dx, li, ls As Single
li = -4 : ls = 4
dx = 0.5
For x = li To ls Step dx
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 60-
y = f(x)
Console.WriteLine("{0:f2}{1} {2:f2}", x, vbTab, y)
Next
Console.ReadLine()
End Sub
End Module
Modelo y repitirlo
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 61-
3.9.- RECURSIVIDAD
TORRES DE HANOI
10 Diseñe un figura de su creación y haga mover la figura
Module Module1
Function f(ByVal x As Single) As Single
Return (x + 2) * (x - 3)
End Function
cont = cont + 1
Next
End Sub
Sub Main()
Dim a As Single = -3, b As Single = 4
Dim h As Single = 0.1
Buscartodas(a, b, h)
Console.ReadLine()
End Sub
End Module
Imports Tao.Platform.Windows
Imports Tao.OpenGl
Imports System.IO
Public Class Form1
Sub Iniciar()
DataGridView1.ColumnCount = 4
DataGridView1.RowCount = 4
Dim fila, col As Integer
DataGridView1.Columns(0).Width = 50
For col = 0 To 3
DataGridView1.Columns(col).Width = 50
Next
For fila = 0 To DataGridView1.RowCount - 1
DataGridView1.Rows(fila).HeaderCell.Value = fila.ToString
Next
DataGridView1.Columns(0).HeaderText = "PROPIEDAD"
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 64-
DataGridView1.Columns(1).HeaderText = "EjeX"
DataGridView1.Columns(2).HeaderText = "Eje Y"
DataGridView1.Columns(3).HeaderText = "Eje Z"
DataGridView1.Rows(0).Cells(0).Value = "Rotacion"
DataGridView1.Rows(0).Cells(1).Value = anguloCuboX
DataGridView1.Rows(0).Cells(2).Value = anguloCuboY
DataGridView1.Rows(0).Cells(3).Value = anguloCuboZ
DataGridView1.Rows(1).Cells(0).Value = "Traslacion"
DataGridView1.Rows(1).Cells(1).Value = tx
DataGridView1.Rows(1).Cells(2).Value = ty
DataGridView1.Rows(1).Cells(3).Value = tz
DataGridView1.Rows(2).Cells(0).Value = "Escalado"
DataGridView1.Rows(2).Cells(1).Value = ex
DataGridView1.Rows(2).Cells(2).Value = Ey
DataGridView1.Rows(2).Cells(3).Value = Ez
End Sub
Ez = DataGridView1.Rows(2).Cells(3).Value
Select Case e.KeyCode
Case Keys.Right ' fflecha derecha rota al rededdor del x
ex = ex + pasoEscala
Case Keys.Left ' fflecha izquierdaderecha rota al rededdor del x
ex = ex - pasoEscala
Case Keys.Up ' flecha arriba a al rededdor del y
Ey = Ey + pasoEscala
Case Keys.Down ' flecha arriba a al rededdor del y
Ey = Ey - pasoEscala
Case Keys.PageUp ' pagina arriba giro alrededor del eje z
Ez = Ez + pasoEscala
Case Keys.PageDown ' pagina arriba giro alrededor del eje z
Ez = Ez - pasoEscala
End Select
DataGridView1.Rows(2).Cells(1).Value = ex
DataGridView1.Rows(2).Cells(2).Value = Ey
DataGridView1.Rows(2).Cells(3).Value = Ez
txtEscalado.Text = ""
End Sub
End Class
Imports System.IO
Module Module1
Function ContarLetra(Cadena As String, letra As Char)
Dim LARGO As Integer = Len(Cadena)
Dim cont, cant As Integer
For cont = 0 To LARGO - 1
If Cadena(cont) = letra Then
cant = cant + 1
End If
Next
Return cant
End Function
inicio = 1
For col = 0 To nc - 1
pos = InStr(inicio, cadena, Chr(9))
subcadena = Mid(cadena, inicio, pos - inicio)
A(fila, col) = Val(subcadena)
inicio = pos + 1
Next
fila = fila + 1
cadena = srLector.ReadLine()
Loop
nf = fila
Console.WriteLine("Archivo leido satisfactoriamente")
srLector.Close()
End Sub
End Module
Imports System.IO
Imports Tao.OpenGl
Imports Tao.OpenGl.Glu
Imports Tao.Platform.Windows
Module Module2
Public ambiente() As Single = {0.5, 0.5, 0.5, 1}
Public mat_specular() As Single = {1.0, 1.0, 1.0, 1.0}
Public mat_shininess() As Single = {50.0} '//resplandor
Public light_position() As Single = {15, 5, 5, 1}
Public difuso() As Single = {1, 1, 1, 1}
Public especular() As Single = {1, 1, 1, 1}
'******************
'Public NombreArchivo As String = "D:\datos\matriz20x20.txt"
Public Const limite As Integer = 120
Public NombreArchivo As String = "D:\datos\misti.txt"
Sub DISCO(X() As Single, Y() As Single, Z() As Single, nRadio As Integer, altura As
Single)
Dim fila As Integer
Dim x1(100), Y1(100), Z1(100) As Single
Traslacion(X, Y, Z, x1, Y1, Z1, nRadio, 0, 0, altura)
Gl.glBegin(Gl.GL_POLYGON) ' inicio del poligono
For fila = 0 To nRadio - 1
Gl.glVertex3f(X(fila), Y(fila), Z(fila)) ' // color verde
Next
Gl.glEnd()
Gl.glBegin(Gl.GL_POLYGON) ' inicio del poligono
For fila = 0 To nRadio - 1
Gl.glVertex3f(x1(fila), Y1(fila), Z1(fila)) ' // color verde
Next
Gl.glEnd()
For fila = 0 To nRadio - 2
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 71-
Gl.glBegin(Gl.GL_QUADS)
Gl.glVertex3f(X(fila), Y(fila), Z(fila))
Gl.glVertex3f(x1(fila), Y1(fila), Z1(fila))
Gl.glVertex3f(x1(fila + 1), Y1(fila + 1), Z1(fila + 1))
Gl.glVertex3f(X(fila + 1), Y(fila + 1), Z(fila + 1))
Gl.glEnd()
Next
End Sub
Sub GraficarFuncion3d(M3D(,) As Single, Lix As Single, lsX As Single, _
Liy As Single, lsy As Single, _
npX As Integer, npy As Integer)
Dim fila, col As Integer
Dim dx As Single = (lsX - Lix) / npX
Dim dy As Single = (lsy - Liy) / npy
Dim x, y As Single
y = Liy
For fila = 0 To npy
y = y + dy
x = Lix
For col = 0 To npX
x = x + dx
Gl.glBegin(Gl.GL_QUADS)
Gl.glVertex3f(x, y, M3D(fila, col))
Gl.glVertex3f(x, y + dy, M3D(fila + 1, col))
Gl.glVertex3f(x + dx, y + dy, M3D(fila + 1, col + 1))
Gl.glVertex3f(x + dx, y, M3D(fila, col + 1))
Gl.glEnd()
Next
Next
End Sub
Sub GraficarFuncion(VX() As Single, VY() As Single, VZ() As Single, a As Single, b
As Single, _
npRadio As Integer, ndiscos As Integer)
Dim x, y, x1, y1, x2, y2, dx As Single
dx = (b - a) / ndiscos
For x = a To b - dx Step dx
x1 = x
y1 = f(x)
x2 = x + dx
y2 = f(x + dx)
Gl.glBegin(Gl.GL_LINES)
Gl.glVertex3f(x1, y1, 0)
Gl.glVertex3f(x2, y2, 0)
Gl.glEnd()
Gl.glPushMatrix()
Gl.glColor3f(1, 1, 0)
Gl.glRotatef(90, 0.0F, 1.0F, 0.0F)
Radio = (y1 + y2) / 2
generarPuntos(VX, VY, VZ, Radio, npRadio)
Gl.glTranslatef(0, 0, x)
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 72-
Imports Tao.OpenGl
Imports Tao.Platform.Windows
Imports System.IO
End Sub
Public Sub EliminarOpenGL()
Wgl.wglMakeCurrent(IntPtr.Zero, IntPtr.Zero)
Wgl.wglDeleteContext(hRC)
End Sub
Gl.glEnd()
Gl.glColor3f(0, 0, 1) REM eje z
Gl.glBegin(Gl.GL_LINES)
Gl.glVertex3f(0, 0, 0)
Gl.glVertex3f(0, 0, tam)
Gl.glEnd()
End Sub
Sub display()
Gl.glLoadIdentity()
Gl.glRotatef(anguloCuboX, 1.0F, 0.0F, 0.0F)
Gl.glRotatef(anguloCuboY, 0.0F, 1.0F, 0.0F)
Gl.glRotatef(anguloCuboZ, 0.0F, 0.0F, 1.0F)
Gl.glScalef(ex, Ey, Ez)
Gl.glTranslatef(tx, ty, tz)
Coordenadas()
Gl.glColor3f(1, 1, 0)
Select Case Modelo
Case 1
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 74-
Sub Inicializaciones()
Gl.glLightfv(Gl.GL_LIGHT0, Gl.GL_AMBIENT, ambiente)
Gl.glLightfv(Gl.GL_LIGHT0, Gl.GL_DIFFUSE, difuso)
Gl.glLightfv(Gl.GL_LIGHT0, Gl.GL_SPECULAR, especular)
b
EJERCICIO PREGUNTAS TIPO PARA EL SEGUNDO EXAMEN
METODO NUEMRICOS
Encuentra el área y volumen de una figura de su creación e interprete en modo consola
y modo formulario
Encuentre la raíz de una ecuación que usted mismo se plantee
Problema de optimizacion, problema de confesiones y punto de equilibro
Hallar el área sombreada
Funciones de suma
Integral recursive
Module Module4
Function f(ByVal x As Single) As Single
Return x * x
End Function
Function Trapecialrecursivo(ap, a, b, h) As Single
Dim x, y1, y2 As Single
If a < b Then
y1 = f(a)
y2 = f(a + h)
ap = (y1 + y2) / 2 * h
Return ap + Trapecialrecursivo(ap, a + h, b, h)
Else
Return 0
End If
End Function
Function Trapecial(ByVal a As Single, ByVal b As Single, ByVal n As Integer) As
Single
Dim at As Single, ap, dx As Single
ap = 0
dx = (b - a) / n
at = Trapecialrecursivo(ap, a, b, dx)
Return at
End Function
Sub Main()
Dim a, b, area As Single
area = Trapecial(0, 2, 4000)
Console.WriteLine("La integral es {0} ", area)
Console.ReadLine()
End Sub
End Module
Module Module1
Function f(x As Single) As Single
Return (x + 1) * (x - 2) * (x - 4)
End Function
Sub Main()
Dim x, y As Single
Dim a, b, dx As Single
a = -2 : b = 5 : dx = 0.5
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 78-
For x = a To b Step dx
y = f(x)
Console.WriteLine(" {0} {1} {2} ", x, vbTab, y)
Next
Console.ReadLine()
End Sub
End Module
Posibles preguntas
1 cambiar la funion y halle
1. Ingrese a,b, y nro de divisiones
2. Grafique la funcion
3. Grafique la funciones pero en modo formualarioo
4. Encuentre las raíces de la ecuaciones
5. Encuentre el recorrido de la función desde la raíz 1 hasta la raíz 3. Un móvil
recorre por esa funcion
6. Integral de la raiz1 a la raíz 3
7. Volumen de revolución de r1 a r33 pr el método de disco ( simpson)
8. Volumen de disco por el método de los cilidnicos
9. Área lateral de r1 a r3
10. Encuntre el máximo de la función de la r1 a r2 ( valores de x y y)
11. En que parte la función se tiene mayor derivada ( pendiente)
12. Otras que usted vea por conviene por ejemplo dado un punto encuentre el punto
mas cercano
Funciones f(x,y)
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 79-
Imports System.IO
Module Module1
Function fxy(x As Single, y As Single) As Single
Return Math.Cos(x * x + y * y) / (x * x + y * y)
End Function
Sub Main()
Dim x, y, z As Single
Dim lix, lsx, liy, lsy, dx, dy As Single
Dim archivo As StreamWriter
archivo = New StreamWriter("D:\datos\grafico3d.txt")
lix = -5 : lsx = 5 : dx = 0.5 : liy = -5 : lsy = 5 : dy = 0.5
For y = liy To lsy Step dy
For x = lix To lsx Step dx
z = fxy(x, y)
Console.Write("{0}{1}", z, vbTab)
archivo.Write("{0}{1}", z, vbTab)
Next
Console.WriteLine()
archivo.WriteLine()
Next
archivo.Close()
Console.ReadLine()
End Sub
End Module
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 80-
Chart Title
2
Series19
1
Series13
0
Series7
1 3 5
-1 7 9 11 13 Series1
15 17 19 21
Jueguen con el auto por ejemplo carrera de autos, y la función f(x) y f(x,y) hecho
en practicas. Recursivdad tanto function como sub. Cree figuras recursivas, vea
el punto de quilibrio confeciones y otros problemas de optimización.
ProbLEmea de conduccion terminado
Module Module1
Dim cki As ConsoleKeyInfo
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 81-
Dim ax1, ay1, ax2, ay2, bx1, by1, bx2, by2 As Integer
Function prueba(px As Integer, py As Integer) As Integer
Dim r1, r2 As Integer
If (px > ax1 And px < ax2 And py > ay1 And py < ay2) Then
r1 = 1
Else
r1 = 0
End If
If (px < bx1 Or px > bx2 Or py < by1 And py > by2) Then
r2 = 1
Else
r2 = 0
End If
If r1 = 1 And r2 = 1 Then
Return 1
Else
Return 2
End If
Return 1
End Function
Sub contadorMov(cx As Integer, cy As Integer, Mov As Integer)
Console.ForegroundColor = 15
Console.SetCursorPosition(30, 12)
Console.Write("Cx = {0} cy= {1} Mov ={2}", cx, cy, Mov)
End Sub
Sub main()
End Sub
End Module
Module Module2
Console.Write("X")
Next
Next
End Sub
End Sub
Sub autoIzquierdo(px1 As Integer, py1 As Integer, ancho As Integer, alto As Integer,
_
color1 As Integer, color2 As Integer, nombre As String)
Cuadro(px1, py1 - alto, ancho, alto, color1)
Cuadro(px1, py1, ancho, alto, color1)
Cuadro(px1, py1 + alto, ancho, alto, color1)
Cuadro(Px + alto, Py - alto * 2, alto, alto, color2)
Cuadro(Px + ancho - alto, Py - alto * 2, alto, alto, color2)
Cuadro(Px + alto, Py + alto * 2, alto, alto, color2)
Cuadro(Px + ancho - alto, Py + alto * 2, alto, alto, color2)
Marca(px1, py1, nombre)
End Sub
Sub autoabajo(px1 As Integer, py1 As Integer, ancho As Integer, alto As Integer, _
color1 As Integer, color2 As Integer, nombre As String)
Cuadro(Px - ancho, Py - alto, ancho, alto, color1)
Cuadro(Px, Py - alto, ancho, alto, color1)
Cuadro(Px + ancho, Py - alto, ancho, alto, color1)
Marca(Px, Py - 1, nombre)
End Sub
Sub autoarriba(px1 As Integer, py1 As Integer, ancho As Integer, alto As Integer, _
Clases y prácticas de programación y métodos numéricos 2018 a\ Ismael Veliz Vilca - 84-
Case 2
Grafico.FillRectangle(brochacircuito, px1 - ancho, Py - 2 * alto, ancho, 5 * alto)
End Select
End Sub
Sub autoIzquierdografico(px1 As Integer, py1 As Integer, ancho As Integer, alto As
Integer, tipo As Integer)
Select tipo
Case 1
dir = 4
autoarribagrafico(Px, Py, alto, ancho, 1)
Case Keys.Down ' flecha arriba a al rededdor del y
Py = Py + 1
dir = 2
autoabajoGrafico(Px, Py, alto, ancho, 1)
End Select
mov = mov + 1
TextBox1.Text = mov
ListBox1.Items.Add("px= " & Px & "py =" & Py & " mov" & mov)
End Sub
End Class