2

要するに、これは Vandermonde 行列であり、配列の 2 番目の次元で for を実行するのに問題があります。

'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.
4

1 に答える 1

1

一般的なエントリの式を持つ行列を作成する良い方法を次に示します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という名前が付けられrows:columns:tabulate:ているため、私の答えは次のようになります。

Matrix class >> vandermonde: anArray degree: anInteger
  ^self
    rows: anArray size
    columns: anInteger + 1
    tabulate: [:i :j | (anArray at: i) raisedTo: j - 1]
于 2016-02-25T00:52:29.230 に答える