Private Sub CommandButton1_Click()
CommandButton1.Caption = "Zn"
CommandButton1.BackColor = vbCyan
CommandButton1.Font = vbbold
Dim L As Double
Dim he As Double
Dim Zn1 As Double
Dim n As Double
Dim corr As Double
Dim Delta As Double
Dim Zn2 As Double
Dim cotZn1 As Double
Dim cotZn2 As Double
Dim error1 As Double
Dim error2 As Double
L = Sheet1.Range("B2")
he = Sheet1.Range("A2")
m = Val(Sheet1.Range("C2"))
Sheet1.Range("C4") = "Zn error"
Sheet1.Range("C4").Interior.ColorIndex = 8
For n = 0 To m - 1
Sheets("sheet1").Cells(n + 5, 1) = "Z" + Str(n + 1)
Sheet1.Cells(n + 5, 1).Interior.ColorIndex = 8
Zn1 = n * 3.1415926
Sheets("sheet1").Cells(n + 5, 2) = 0.0001
For corr = 1 To 1000
Delta = 0.001 * 3.1415926
Zn1 = Zn1 + Delta
Zn2 = Sheets("sheet1").Cells(n + 5, 2)
cotZn1 = 1 / Tan(Zn1)
cotZn2 = 1 / Tan(Zn2)
error1 = (cotZn1 - (Zn1 / (he * L))) ^ 2
error2 = (cotZn2 - (Zn2 / (he * L))) ^ 2
If error1 < error2 Then
Sheets("sheet1").Cells(n + 5, 2) = Val(Zn1)
Sheets("sheet1").Cells(n + 5, 3) = Val(error1)
End If
Next corr
Next n
End Sub
Private Sub CommandButton2_Click()
CommandButton2.Caption = "find Alpha"
CommandButton2.BackColor = vbGreen
CommandButton2.Font = vbbold
Dim lastrow, Alpha, i, t, L, x, Ua, Uo, m, j, Zn, part1, part2, part3, sum, u, Error, sumerror As Double
lastrow = Sheets("sheet1").Cells(Rows.Count, 9).End(xlUp).Row
Sheets("sheet1").Cells(lastrow + 1, 17) = 10000
For Alpha = 0.00000001 To 0.01 Step 0.00000001
If Alpha > 0.000001 Then GoTo limit
sumerror = 0
For i = 2 To lastrow
t = Sheets("sheet1").Cells(i, 10)
L = Sheet1.Range("B2")
x = Sheet1.Range("F4")
Ua = Sheet1.Range("F2")
Uo = Sheet1.Range("G2")
m = Val(Sheet1.Range("C2"))
sum = 0
For j = 1 To m
Zn = Sheets("sheet1").Cells(j + 4, 2)
part1 = (2 * (Uo - Ua) * Sin(Zn)) / (Zn + Sin(Zn) * Cos(Zn))
part2 = Exp(-1 * ((Zn) ^ (2)) * Alpha * t / ((L) ^ (2)))
part3 = Cos(Zn * x / L)
sum = sum + part1 * part2 * part3
Next j
u = Ua + sum
Sheets("sheet1").Cells(i, 16) = u
Erro = ((Sheets("sheet1").Cells(i, 16) - Sheets("sheet1").Cells(i, 9)) ^ (2))
Sheets("sheet1").Cells(i, 17) = Erro
sumerror = sumerror + Erro
Sheet1.Range("S2") = sumerror
Next i
L = Sheets("sheet1").Cells(lastrow + 1, 17)
If Sheet1.Range("S2") < L Then
Sheets("sheet1").Cells(lastrow + 1, 17) = sumerror
Sheet1.Range("N2") = Alpha
End If
Next Alpha
limit:
For Alpha = 0.000001 To 0.01 Step 0.000001
If Alpha > 0.0001 Then GoTo limit1
sumerror = 0
For i = 2 To lastrow
t = Sheets("sheet1").Cells(i, 10)
L = Sheet1.Range("B2")
x = Sheet1.Range("F4")
Ua = Sheet1.Range("F2")
Uo = Sheet1.Range("G2")
m = Val(Sheet1.Range("C2"))
sum = 0
For j = 1 To m
Zn = Sheets("sheet1").Cells(j + 4, 2)
part1 = (2 * (Uo - Ua) * Sin(Zn)) / (Zn + Sin(Zn) * Cos(Zn))
part2 = Exp(-1 * ((Zn) ^ (2)) * Alpha * t / ((L) ^ (2)))
part3 = Cos(Zn * x / L)
sum = sum + part1 * part2 * part3
Next j
u = Ua + sum
Sheets("sheet1").Cells(i, 16) = u
Erro = ((Sheets("sheet1").Cells(i, 16) - Sheets("sheet1").Cells(i, 9)) ^ (2))
Sheets("sheet1").Cells(i, 17) = Erro
sumerror = sumerror + Erro
Sheet1.Range("S2") = sumerror
Next i
L = Sheets("sheet1").Cells(lastrow + 1, 17)
If Sheet1.Range("S2") < L Then
Sheets("sheet1").Cells(lastrow + 1, 17) = sumerror
Sheet1.Range("N2") = Alpha
End If
Next Alpha
limit1:
For Alpha = 0.0001 To 0.01 Step 0.0001
sumerror = 0
For i = 2 To lastrow
t = Sheets("sheet1").Cells(i, 10)
L = Sheet1.Range("B2")
x = Sheet1.Range("F4")
Ua = Sheet1.Range("F2")
Uo = Sheet1.Range("G2")
m = Val(Sheet1.Range("C2"))
sum = 0
For j = 1 To m
Zn = Sheets("sheet1").Cells(j + 4, 2)
part1 = (2 * (Uo - Ua) * Sin(Zn)) / (Zn + Sin(Zn) * Cos(Zn))
part2 = Exp(-1 * ((Zn) ^ (2)) * Alpha * t / ((L) ^ (2)))
part3 = Cos(Zn * x / L)
sum = sum + part1 * part2 * part3
Next j
u = Ua + sum
Sheets("sheet1").Cells(i, 16) = u
Erro = ((Sheets("sheet1").Cells(i, 16) - Sheets("sheet1").Cells(i, 9)) ^ (2))
Sheets("sheet1").Cells(i, 17) = Erro
sumerror = sumerror + Erro
Sheet1.Range("S2") = sumerror
Next i
L = Sheets("sheet1").Cells(lastrow + 1, 17)
If Sheet1.Range("S2") < L Then
Sheets("sheet1").Cells(lastrow + 1, 17) = sumerror
Sheet1.Range("N2") = Alpha
End If
Next Alpha
End Sub
Private Sub CommandButton3_Click()
CommandButton3.Caption = "accurate Alpha"
CommandButton3.BackColor = vbGreen
CommandButton3.Font = vbbold
Dim ac, lower, upper, lastrow, Alpha, i, t, L, x, Ua, Uo, m, j, Zn, part1, part2, part3, sum, u, Erro, sumerror
As Double
lastrow = Sheets("sheet1").Cells(Rows.Count, 9).End(xlUp).Row
Sheets("sheet1").Cells(lastrow + 1, 17) = 10000
ac = Sheet1.Range("N2")
lower = ac / 100
upper = ac * 3
For Alpha = lower To upper Step lower
sumerror = 0
For i = 2 To lastrow
t = Sheets("sheet1").Cells(i, 10)
L = Sheet1.Range("B2")
x = Sheet1.Range("F4")
Ua = Sheet1.Range("F2")
Uo = Sheet1.Range("G2")
m = Val(Sheet1.Range("C2"))
sum = 0
For j = 1 To m
Zn = Sheets("sheet1").Cells(j + 4, 2)
part1 = (2 * (Uo - Ua) * Sin(Zn)) / (Zn + Sin(Zn) * Cos(Zn))
part2 = Exp(-1 * ((Zn) ^ (2)) * Alpha * t / ((L) ^ (2)))
part3 = Cos(Zn * x / L)
sum = sum + part1 * part2 * part3
Next j
u = Ua + sum
Sheets("sheet1").Cells(i, 16) = u
Erro = ((Sheets("sheet1").Cells(i, 16) - Sheets("sheet1").Cells(i, 9)) ^ (2))
Sheets("sheet1").Cells(i, 17) = Erro
sumerror = sumerror + Erro
Sheet1.Range("S2") = sumerror
Next i
L = Sheets("sheet1").Cells(lastrow + 1, 17)
If Sheet1.Range("S2") < L Then
Sheets("sheet1").Cells(lastrow + 1, 17) = sumerror
Sheet1.Range("N2") = Alpha
lastrow = Sheets("sheet1").Cells(Rows.Count, 9).End(xlUp).Row
sumerror = 0
For i = 2 To lastrow
t = Sheets("sheet1").Cells(i, 10)
L = Sheet1.Range("B2")
x = Sheet1.Range("F4")
Ua = Sheet1.Range("F2")
Uo = Sheet1.Range("G2")
m = Val(Sheet1.Range("C2"))
sum = 0
For j = 1 To m
Zn = Sheets("sheet1").Cells(j + 4, 2)
part1 = (2 * (Uo - Ua) * Sin(Zn)) / (Zn + Sin(Zn) * Cos(Zn))
part2 = Exp(-1 * ((Zn) ^ (2)) * Alpha * t / ((L) ^ (2)))
part3 = Cos(Zn * x / L)
sum = sum + part1 * part2 * part3
Next j
u = Ua + sum
Sheets("sheet1").Cells(i, 11) = u
Erro = ((Sheets("sheet1").Cells(i, 11) - Sheets("sheet1").Cells(i, 9)) ^ (2))
Sheets("sheet1").Cells(i, 12) = Erro
sumerror = sumerror + Erro
Sheets("sheet1").Cells(lastrow + 1, 12) = sumerror
Next i
End If
Next Alpha
Sheets("sheet1").Cells(lastrow + 1, 17) = Sheet1.Range("S2")
End Sub
Private Sub CommandButton4_Click()
CommandButton4.Caption = "Draw Suction vs. Time"
CommandButton4.BackColor = vbYellow
CommandButton4.Font = vbbold
Dim Alpha, i, t, L, x, Ua, Uo, m, j, Zn, part1, part2, part3, sum, u As Double
Alpha = Sheet1.Range("N2")
L = Sheet1.Range("B2")
x = Sheet1.Range("F4")
Ua = Sheet1.Range("F2")
Uo = Sheet1.Range("G2")
t=0
For i = 1 To 10
t = t + 100
Sheets("sheet1").Cells(i + 25, 6) = t
m = Val(Sheet1.Range("C2"))
sum = 0
For j = 1 To m
Zn = Sheets("sheet1").Cells(j + 4, 2)
part1 = (2 * (Uo - Ua) * Sin(Zn)) / (Zn + Sin(Zn) * Cos(Zn))
part2 = Exp(-1 * ((Zn) ^ (2)) * Alpha * t / ((L) ^ (2)))
part3 = Cos(Zn * x / L)
sum = sum + part1 * part2 * part3
Next j
u = Ua + sum
Sheets("sheet1").Cells(i + 25, 7) = u
Next i
t = 1000
For i = 1 To 9
t = t + 1000
Sheets("sheet1").Cells(i + 35, 6) = t
m = Val(Sheet1.Range("C2"))
sum = 0
For j = 1 To m
Zn = Sheets("sheet1").Cells(j + 4, 2)
part1 = (2 * (Uo - Ua) * Sin(Zn)) / (Zn + Sin(Zn) * Cos(Zn))
part2 = Exp(-1 * ((Zn) ^ (2)) * Alpha * t / ((L) ^ (2)))
part3 = Cos(Zn * x / L)
sum = sum + part1 * part2 * part3
Next j
u = Ua + sum
Sheets("sheet1").Cells(i + 35, 7) = u
Next i
t = 10000
For i = 1 To 9
t = t + 10000
Sheets("sheet1").Cells(i + 44, 6) = t
m = Val(Sheet1.Range("C2"))
sum = 0
For j = 1 To m
Zn = Sheets("sheet1").Cells(j + 4, 2)
part1 = (2 * (Uo - Ua) * Sin(Zn)) / (Zn + Sin(Zn) * Cos(Zn))
part2 = Exp(-1 * ((Zn) ^ (2)) * Alpha * t / ((L) ^ (2)))
part3 = Cos(Zn * x / L)
sum = sum + part1 * part2 * part3
Next j
u = Ua + sum
Sheets("sheet1").Cells(i + 44, 7) = u
Next i
End Sub