|
訂正があります。
>'================================================================
>Sub test()
> Dim n As Long
> n = 100 '←この値を変更して確認してみて下さい
if n>0 then 'こうしないとn=0のとき、エラーになるので
> With Range("a1:a" & n)
> .Formula = "=int(rand()*" & n & ")+1"
> .Value = .Value
> End With
end if
> MsgBox tn(n, 2)
>End Sub
>'=============================================================
>Function tn(n As Long, t0 As Long) As Double
>'Tn=Σ(i=1⇒n)Wi×Tn-iを計算する
>'input : n 求めたい数列値、t0--初期値
>'output: tn 結果
> Dim idx As Long
> Dim jdx As Long
> ReDim ans(n) As Double
> ans(0) = t0
> For idx = 1 To n
> ans(idx) = 0
> For jdx = idx - 1 To 0 Step -1
> ans(idx) = ans(idx) + Range("a" & (idx - jdx)).Value * ans(jdx)
> Next
> Next
> tn = ans(UBound(ans()))
>End Function
|
|