Smalltalk Vandermonde矩阵

Smalltalk Vandermonde矩阵,smalltalk,gnu-smalltalk,Smalltalk,Gnu Smalltalk,简言之,这是一个范德蒙矩阵,我在数组的第二维度上运行一个 'add meg M-et majd N-et (enter kozotte)(az 1. sor az 1-es szam hatvanyai)' displayNl. M := stdin nextLine asInteger. N := stdin nextLine asInteger. |tomb| tomb := Array new: M. x := 1. y := 1. a := M + 1. b := N + 1. x to

简言之,这是一个范德蒙矩阵,我在数组的第二维度上运行一个

'add meg M-et majd N-et (enter kozotte)(az 1. sor az 1-es szam hatvanyai)' displayNl.
M := stdin nextLine asInteger.
N := stdin nextLine asInteger.
|tomb|
tomb := Array new: M.
x := 1.
y := 1.
a := M + 1.
b := N + 1.
x to: a do: [ :i|
  tomb at:x put: (Array new: N) y to: b do: [ :j |
    x at: y put: (x raisedTo: y - 1) ] ].
tomb printNl.

下面是一个创建矩阵的好方法,我们为其创建了一个通用条目表达式
aij

Matrix class >> fromBlock: aBlock rows: n columns: m
  | matrix |
  matrix := self rows: n columns: m.
  matrix indicesDo: [:i :j | | aij |
    aij := aBlock value: i value: j.
    matrix at: i at: j put: aij].
  ^matrix
使用上述方法,您现在可以实现

Matrix class >> vandermonde: anArray degree: anInteger
  ^self
    fromBlock: [:i :j | (anArray at: i) raisedTo: j - 1]
    rows: anArray size
    columns: anInteger + 1
编辑

我刚刚意识到,在Pharo中,有一种方法可以从其
aij
的表达式中创建矩阵,它被命名为
行:列:表格:
,因此我的答案简化为:

Matrix class >> vandermonde: anArray degree: anInteger
  ^self
    rows: anArray size
    columns: anInteger + 1
    tabulate: [:i :j | (anArray at: i) raisedTo: j - 1]

(Array new:N)
y to:b do:
之间是否缺少一点?毫无意义,这两句话似乎将被解释为一个单一的关键字消息:put:to:do:all,
x at:y put:…
无法工作,因为
x
是一个整数。那可能是
坟墓在:y put:…
。还有一件事:
x
y
不会改变,因此将它们提升到任何值都会回答
1
(1^n=1)。我不理解代码的意图。根据,您应该从alphas向量开始,然后计算i,j处的每个元素作为该行的alpha,提升到列-1。