目前我試圖讓列表的使用功能來創建:OCaml中和創建列表
0 V12 V13 V14
V21 0 V23 V24
V31 V32 0 V34
V41 V42 V43 0
的方式,我發現這樣做是使用論文公式:
(2*V1 - 1)*(2*V2-1) = for spot V(1,2) in the Matrix
(2*V1 - 1)*(2*V3-1) = for spot V(1,3) in the Matrix
etc
因此到目前爲止,我有:
let singleState state =
if state = 0.0 then 0.0
else
((2.0 *. state) -. 1.0);;
let rec matrixState v =
match v with
| [] -> []
| hd :: [] -> v
| hd :: (nx :: _ as tl) ->
singleState hd *. singleState nx :: matrixState tl;;
我的結果出來是:
float list = [-3.; -3.; -3.; -1.]
當他們應該列出看起來名單如下:
0 -1 1 -1
-1 0 -1 1
1 -1 0 -1
-1 1 -1 0
所以,相反,它使列表是製作只有一個名單列表。我也有麻煩搞清楚如何使對角線0
的簽名應該是這樣的:
val singleState : float list -> float list list = <fun>
val matrixState : float list list -> float list list = <fun>
和我得到
val singleState : float -> float = <fun>
val matrixState : float list -> float list = <fun>
任何想法?
您所使用的語言爲w ritten「OCaml」,大寫字母O和大寫字母C. http://caml.inria.fr/ocaml/index.en.html –