考拉茲級數函式是考拉茲猜想的拓展級數函式
基本介紹
- 中文名:考拉茲級數函式
定義,套用,
定義
它是個疊代循環級數,但是不是所有的考拉茲級數是收斂的
套用
它是考拉茲猜想1927年提出的猜想,一個整數n,如果是偶數則除以2,如果是奇數則乘以3再加1,如此循環計算結果是4,2,1的循環,研究它對於一些自然現象是有幫助的。下面是考拉茲級數的通項表達式
這是原函式,k級通項式為
下面是vba程式代碼,F(n,a)函式是求級數值,k(i,a)是層級數
Function F(N As Variant,a as Variant ) As Variant
Dim b As Variant
Dim c As Variant
b = (-1) ^ (N + 1)
c =( 1-(-1) ^ N)/2
F = c + N * (1+(a-1) ^ c) ^ b
End Function
Sub 求考拉茲級數函式()
Dim k As Variant
Dim i As Integer
Dim j As Integer
Dim m As Variant
k = InputBox(Prompt:="輸入任意整數")
m = F(k,3): j = 1
Do While m > 1
m = F(m): j = j + 1
Loop
m = 1
MsgBox "總計考拉茲" & j & "級"
End
End Sub
以下函式是用於excel中求考拉茲級數的
下面兩個函式必須放在一個模組之中
Function K(I As Variant,a as Variant ) As Integer
Dim j As Integer
Dim m As Variant
m = F(I,a): j = 1
Do While m > 1
m = F(m): j = j + 1
Loop
m = 1
K = j
End Function
Function F(N As Variant,a as Variant ) As Variant
b = (-1) ^ (N + 1)
c =( 1-(-1) ^ N)/2
F = c + N * (1+(a-1) ^ c) ^ b
End Function
EXCEL中
使用時直接輸入 =k(m,a)即可求出考拉茲級數=F(m,a)即可求出考拉茲級數
當a不等於3時,函式多數是發散的。基本很少有循環的規律性.