Programacion
Ismael MartínezEnsayo9 de Marzo de 2020
566 Palabras (3 Páginas)267 Visitas
Function g(x, a, b, c)
g = a * x ^ 4 + b * x ^ 2 + c
End Function
Function d(x, a, b, c)
d = (g(x + 0.0001, a, b, c) - g(x, a, b, c)) / 0.0001
End Function
'formula general programa
Sub FG_secan()
Worksheets("Hoja1").Range("a1:xfd1048546").Delete
MsgBox ("Este programa resuelve ecuaciones de segundo grado por la formula general y por el metodo de la secante ")
aqui:
a = InputBox("dame el coeficiente bicuadratico")
a = Val(a)
If a = 0 Then
MsgBox ("a no pude ser cero")
GoTo aqui
End If
b = InputBox("dame el coeficiente cuadratico")
b = Val(b)
c = InputBox("dame el termino independiente")
c = Val(c)
'vamos a tabular y luego grafiacar
Cells(1, 1) = "x"
Cells(1, 2) = "y"
aqui1:
a1 = InputBox("limite inferior")
a1 = Val(a1)
b1 = InputBox("limite superior")
b1 = Val(b1)
h = InputBox("de cuanto en cuanto")
h = Val(h)
n = (b1 - a1) / h + 1
i = 1
While i <= n
Cells(i + 1, 1) = a1
Cells(i + 1, 2) = g(a1, a, b, c)
a1 = a1 + h 'para que en la nueva iteracion actualice a
i = i + 1 'evolucion del contador
Wend
r = MsgBox("¿deseas tabular otra vez?", vbYesNo)
If r = vbYes Then
GoTo aqui1
End If
datos = Range(Cells(2, 1), Cells(n + 1, 2)).Address 'rango a graficar
Set graf = Charts.Add 'gráfico y sus caraterísticas
With graf
.Name = "Gráfico"
.ChartType = xlXYScatterSmoothNoMarkers
.SetSourceData Source:=Sheets("Hoja1").Range(datos), PlotBy:=xlColumns
.Location Where:=xlLocationAsObject, Name:="Hoja1"
End With
dis = b ^ 2 - 4 * a * c
If dis < 0 Then
MsgBox ("las raices son imaginarias ")
ElseIf dis >= 0 Then
x1 = (-b + Sqr(b ^ 2 - 4 * a * c)) / (2 * a)
x2 = (-b - Sqr(b ^ 2 - 4 * a * c)) / (2 * a)
dis = x1
If dis < 0 Then
MsgBox ("las raices son imaginarias ")
ElseIf dis >= 0 Then
x3 = Sqr(x1)
dis = x1
If dis < 0 Then
MsgBox ("las raices son imaginarias ")
ElseIf dis >= 0 Then
x31 = -Sqr(x1)
dis = x2
If dis < 0 Then
MsgBox ("las raices son imaginarias ")
ElseIf dis >= 0 Then
x4 = Sqr(x2)
dis = x2
If dis < 0 Then
MsgBox ("las raices son imaginarias ")
ElseIf dis >= 0 Then
x41 = -Sqr(x2)
MsgBox ("las raices son " & x3 & ", " & x31 & "," & x41 & ", " & x4 & "ahora empieza secante")
'aqui empieza secante'
xl = InputBox("dame xl")
xl = Val(xl)
xu = InputBox("dame xu")
xu = Val(xu)
Cells(1, 4) = "iteracion"
Cells(1, 5) = "xl"
Cells(1, 6) = "xu"
Cells(1, 7) = "xaprox"
Cells(1, 8) = "erp"
tolerancia = 0.001
itera = InputBox("¿cuantas iteraciones deseas hacer?")
itera = Val(itera)
i = 1
erp = 1000 'para que entre la variable
While erp >= tolerancia And i < itera
Cells(i + 1, 4) = i
Cells(i + 1, 5) = xl
Cells(i + 1, 6) = xu
xaprox = (xl * g(xu, a, b, c) - xu * g(xl, a, b, c)) / (g(xu, a, b, c) - g(xl, a, b, c))
...