0% found this document useful (0 votes)
4 views10 pages

Diffusion Software for Alpha Calculation

Uploaded by

civilhussein
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views10 pages

Diffusion Software for Alpha Calculation

Uploaded by

civilhussein
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Private Sub CommandButton1_Click()

[Link] = "Zn"

[Link] = vbCyan

[Link] = 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 = [Link]("B2")

he = [Link]("A2")

m = Val([Link]("C2"))

[Link]("C4") = "Zn error"

[Link]("C4").[Link] = 8

For n = 0 To m - 1

Sheets("sheet1").Cells(n + 5, 1) = "Z" + Str(n + 1)

[Link](n + 5, 1).[Link] = 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()

[Link] = "find Alpha"

[Link] = vbGreen

[Link] = 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([Link], 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 = [Link]("B2")

x = [Link]("F4")

Ua = [Link]("F2")

Uo = [Link]("G2")

m = Val([Link]("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

[Link]("S2") = sumerror

Next i

L = Sheets("sheet1").Cells(lastrow + 1, 17)

If [Link]("S2") < L Then

Sheets("sheet1").Cells(lastrow + 1, 17) = sumerror

[Link]("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 = [Link]("B2")

x = [Link]("F4")
Ua = [Link]("F2")

Uo = [Link]("G2")

m = Val([Link]("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

[Link]("S2") = sumerror

Next i

L = Sheets("sheet1").Cells(lastrow + 1, 17)

If [Link]("S2") < L Then

Sheets("sheet1").Cells(lastrow + 1, 17) = sumerror

[Link]("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 = [Link]("B2")

x = [Link]("F4")

Ua = [Link]("F2")

Uo = [Link]("G2")

m = Val([Link]("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

[Link]("S2") = sumerror

Next i

L = Sheets("sheet1").Cells(lastrow + 1, 17)

If [Link]("S2") < L Then

Sheets("sheet1").Cells(lastrow + 1, 17) = sumerror

[Link]("N2") = Alpha

End If

Next Alpha

End Sub

Private Sub CommandButton3_Click()


[Link] = "accurate Alpha"

[Link] = vbGreen

[Link] = 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([Link], 9).End(xlUp).Row

Sheets("sheet1").Cells(lastrow + 1, 17) = 10000

ac = [Link]("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 = [Link]("B2")

x = [Link]("F4")

Ua = [Link]("F2")

Uo = [Link]("G2")

m = Val([Link]("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

[Link]("S2") = sumerror

Next i

L = Sheets("sheet1").Cells(lastrow + 1, 17)

If [Link]("S2") < L Then

Sheets("sheet1").Cells(lastrow + 1, 17) = sumerror

[Link]("N2") = Alpha

lastrow = Sheets("sheet1").Cells([Link], 9).End(xlUp).Row

sumerror = 0

For i = 2 To lastrow

t = Sheets("sheet1").Cells(i, 10)

L = [Link]("B2")

x = [Link]("F4")

Ua = [Link]("F2")

Uo = [Link]("G2")

m = Val([Link]("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) = [Link]("S2")

End Sub

Private Sub CommandButton4_Click()

[Link] = "Draw Suction vs. Time"

[Link] = vbYellow

[Link] = vbbold

Dim Alpha, i, t, L, x, Ua, Uo, m, j, Zn, part1, part2, part3, sum, u As Double

Alpha = [Link]("N2")

L = [Link]("B2")

x = [Link]("F4")

Ua = [Link]("F2")

Uo = [Link]("G2")

t=0

For i = 1 To 10

t = t + 100

Sheets("sheet1").Cells(i + 25, 6) = t

m = Val([Link]("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([Link]("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([Link]("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

Common questions

Powered by AI

The code employs an iterative numerical method blended with analytical evaluations of trigonometric and exponential functions to fine-tune variables such as Zn and Alpha, reducing potential instabilities through controlled increments and conditional checks. Such blending allows for the convergence of computational models despite initial data variability, ensuring output accuracy. The use of finely-graded stepping and error minimization further exemplifies this stabilizing strategy .

The algorithm iteratively evaluates different values of Alpha within a specified range by calculating the sum of squared errors between the calculated and the observed values. It continues to adjust Alpha, seeking to minimize this sum. If a new sumerror is lower than the stored value in Sheets("sheet1").Cells(lastrow + 1, 17), Alpha is updated as the optimal value. This process continues across various steps of Alpha, refining the value until the optimal one is found .

The algorithm redundantly recalculates parameters and errors in nested loops, particularly within evaluating Alpha and retrieving Zn repeatedly without stored optimizations. Streamlining could involve caching repeated calculations or using vectorized operations to reduce iterative calls. Additionally, conditional statements like GoTo could be replaced with structured looping or function calls to enhance readability and maintenance, promoting faster execution .

The variable "m" denotes the number of iterations performed, directly correlating with data granularity in computations. Specifically, it determines how many Zn values are calculated at each time interval, affecting the sum of computed values when iterating over time. Its scope offers flexibility in scaling the model's temporal precision, thus enabling fine-tuning in response calculations .

The variable "sumerror" accumulates the squared differences (errors) of the calculated values u from their corresponding measured values over each iteration. It serves as a key metric to determine the convergence and accuracy of the model. By minimizing sumerror through iterative adjustments of variables like Alpha, the model optimizes parameter estimation, enhancing output precision .

The variable "t" represents a time-related component in the model. It influences computations by modifying the exponential decay factor in part2, impacting the convergence and accuracy of the model's results over time. Within subroutines, "t" is dynamically updated to reflect changes across iterations, affecting how Alpha and other parameters interact in predictive calculations .

Adjusting the step size in Alpha directly affects the granularity of the solution search space, impacting convergence speed and accuracy. Smaller step sizes offer finer control, enhancing precision by exploring more potential solutions, though at increased computation time. Conversely, larger steps may expedite processing but risk skipping optimal values, leading to potential inaccuracies in parameter convergence .

The primary mathematical functions used include the trigonometric function "Sin", the cotangent derived from "Tan" (cot(Zn)), the exponential function "Exp" for part2 in decay calculations, and "Cos" for oscillatory factors. These functions are applied to calculate dynamic interactions among variables that are critical for updating the matrix .

In CommandButton1, iterations adjust Zn1 through a loop, comparing calculated errors error1 and error2, updating Sheets('sheet1').Cells if error1 is less. For CommandButton2, conditional jumps manage the loop flow, first using Alpha gates to dynamically adjust algorithm precision with GoTo statements to skip to the next granularity limit, thus efficiently converging towards optimal Alpha settings by narrowing the error sumerror at each step .

Zn1 and Zn2 are angular variables used in iteratively calculating the error values for the algorithm's simulation. Zn1 is initially set to n * π and then iteratively incremented by Delta during the loop. Zn2 fetches values from cells for comparison. For each Zn1, an error1 is calculated as (cot(Zn1) - (Zn1 / (he * L))) ^ 2, and similarly, an error2 for Zn2. These error values are compared to find the minimal value, helping guide the algorithm towards more accurate solutions .

You might also like