YAPC::EU 2018 Glasgow Update!
This commit is contained in:
parent
22f33d4004
commit
4e2d22a71d
1170 changed files with 15042 additions and 3047 deletions
81
Task/Resistor-mesh/FreeBASIC/resistor-mesh.freebasic
Normal file
81
Task/Resistor-mesh/FreeBASIC/resistor-mesh.freebasic
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
' version 01-07-2018
|
||||
' compile with: fbc -s console
|
||||
|
||||
#Define n 10
|
||||
|
||||
Dim As UInteger nn = n * n
|
||||
Dim As Double g(-nn To nn +1, -nn To nn +1)
|
||||
Dim As UInteger node, row, col
|
||||
|
||||
For row = 1 To n
|
||||
For col = 1 To n
|
||||
node += 1
|
||||
If row > 1 Then
|
||||
g(node, node) += 1
|
||||
g(node, node - n) = -1
|
||||
End If
|
||||
If row < n Then
|
||||
g(node, node) += 1
|
||||
g(node, node + n) = -1
|
||||
End If
|
||||
If col > 1 Then
|
||||
g(node, node) += 1
|
||||
g(node, node -1) = -1
|
||||
End If
|
||||
If col < n Then
|
||||
g(node, node) += 1
|
||||
g(node, node +1) = -1
|
||||
End If
|
||||
Next
|
||||
Next
|
||||
|
||||
Dim As UInteger ar = 2, ac = 2
|
||||
Dim As UInteger br = 7, bc = 8
|
||||
Dim As UInteger a = ac + n * (ar -1)
|
||||
Dim As UInteger b = bc + n * (br -1)
|
||||
|
||||
g(a, nn +1) = -1
|
||||
g(b, nn +1) = 1
|
||||
|
||||
Print : Print "Nodes a: "; a, " b: "; b
|
||||
|
||||
' solve linear system using Gauss-Seidel method with pivoting
|
||||
Dim As UInteger i, j, k
|
||||
Dim As Double y
|
||||
|
||||
Do
|
||||
For j = 1 To nn
|
||||
For i = j To nn
|
||||
If g(i, j) <> 0 Then Exit For
|
||||
Next
|
||||
If i = nn +1 Then
|
||||
Print : Print "No solution"
|
||||
Exit Do
|
||||
End If
|
||||
For k = 1 To nn +1
|
||||
Swap g(j, k), g(i, k)
|
||||
Next
|
||||
y = g(j, j)
|
||||
For k = 1 To nn +1
|
||||
g(j, k) = g(j, k) / y
|
||||
Next
|
||||
For i = 1 To nn
|
||||
If i <> j Then
|
||||
y = -g(i, j)
|
||||
For k = 1 To nn +1
|
||||
g(i, k) = g(i, k) + y * g(j, k)
|
||||
Next
|
||||
End If
|
||||
Next
|
||||
Next
|
||||
|
||||
Print
|
||||
Print "Resistance ="; Abs(g(a, nn +1) - g(b, nn +1)); " Ohm"
|
||||
Exit Do
|
||||
Loop
|
||||
|
||||
' empty keyboard buffer
|
||||
While Inkey <> "" : Wend
|
||||
Print : Print "hit any key to end program"
|
||||
Sleep
|
||||
End
|
||||
Loading…
Add table
Add a link
Reference in a new issue