Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Function funcerror(wpen)

wagua = 1000
whpaq = 200
m = wagua / wpen
X1 = 0.05
'For i = 1 To 1
'Y1 = 2.08 * X ^ 2 + 0.29 * X
'X1 = ((Y1 - Y) / m) + X
'Y = Y1
'X = X1
'Next i
'If i = 1 Then
Y = 2.08 * X1 ^ 2 + 0.29 * X1
X = (Y / m) + X1
funcerror = 0.2 - X

'End If
End Function
Function etapas(wpen)
N = 20
wagua = 1000
whpaq = 200
m = wagua / wpen
X1 = 0.05
'For i = 2 To 21
'Y1 = 2.08 * X ^ 2 + 0.29 * X
'X1 = ((Y1 - Y) / m) + X
'Y = Y1
'X = X1
'worg = Y * wpen + wpen
'waq = X * wagua + wagua
'Cells(i, 6).Value = waq

'Cells(i, 7).Value = worg


'Cells(i, 8).Value = X
'Cells(i, 9).Value = Y
'Next i
'If i = Then
Y = 2.08 * X1 ^ 2 + 0.29 * X1
X = (Y / m) + X1
worg = Y * wpen + wpen
waq = X * wagua + wagua
Cells(3, 6).Value = waq
Cells(3, 7).Value = worg
Cells(3, 8).Value = X
Cells(3, 9).Value = Y
'End If

End Function

Sub extraccion()
errorx = 0.001
wpen = Cells(3, 2)
dp = 1
a = etapas(wpen)
error1 = Abs(funcerror(wpen))
If error1 < errorx Then
a = etapas(wpen)
Exit Sub
Else
wpen2 = wpen + dp
error2 = Abs(funcerror(wpen2))
derror = (error2 - error1) / dp
End If

For i = 1 To 40
alfa = 1
1 wpennew = wpen - alfa * (error1 / derror)

errornew1 = Abs(funcerror(wpennew))
Cells(1, 2).Value = wpennew
If (Abs(errornew1) < errorx) Then
wpen = wpennew
c = etapas(wpennew)
Cells(1, 2).Value = wpennew
Exit Sub
End If
If (Abs(errornew1) > Abs(error1)) Then
alfa = alfa / 2
GoTo 1
Else
alfa = 1
wpen = wpennew
error2 = Abs(funcerror(wpen2))

derror = Abs(error2 - error1) / dp


End If
Stop
Next i
Cells(1, 7).Value = "no convergencia"
End Sub

You might also like