Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
185 views
in Technique[技术] by (71.8m points)

excel - Why does a 2X1 array need to be defined as (1 to 2, 1 to 1) instead of just (1 to 2)

I am performing matrix multiplication of an inverted 2X2 matrix with a 2X1 matrix. I kept getting errors and did some searching and stumbled upon this Question and Answer. The answer is the bit of code below.

Why does y need to be defined as (1 to 2, 1 to 1) instead of just (1 to 2)?

Dim A As Variant
Dim y As Variant
Dim x As Variant

ReDim y(1 To 2, 1 To 1)
y(1, 1) = 2
y(2, 1) = 3

ReDim A(1 To 2, 1 To 2)
A(1, 1) = 3
A(2, 1) = 1
A(1, 2) = 4
A(2, 2) = 2

x = WorksheetFunction.MMult(WorksheetFunction.MInverse(A), y)
question from:https://stackoverflow.com/questions/65624252/why-does-a-2x1-array-need-to-be-defined-as-1-to-2-1-to-1-instead-of-just-1-t

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

MMULT should have 2D arrays as parameters, since it is used for multiplying 2D matrices. A 1D array cannot be considered as a matrix.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...