×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Multiplying Arrays

Multiplying Arrays

Multiplying Arrays

(OP)
Multiplying Arrays

Is there a simple method of multiplying arrays?

I have 2 groups of data that I want to multiply and manipulate.

A1 B1
A2 B2
A3 B3
...
An Bn

I've tried declaring A1 and B1 as named variables and I've tried declaring A1:An and B1:Bn also as named variables. Is there a simple manner of multiplying and summing the results? Can this be extended to m x n arrays?

Dik

RE: Multiplying Arrays

(OP)
Will take a look at it... didn't know it was...

Dik

RE: Multiplying Arrays

Assuming N=10 and you want sum of product of corresponding elements, use this
=MMULT(TRANSPOSE(A1:A10),B1:B10)
but do not press enter after you type the formula, press ctrl-enter instead

=====================================
(2B)+(2B)' ?

RE: Multiplying Arrays

Quote (electricpete)

press ctrl-enter instead
Sorry, that should be contrl-shift-enter
The previous example responded to your request "Is there a simple manner of multiplying and summing the results?"

If you want to do a matrix operation that results in output larger than one cell, select the correct size output range, enter the formula and again press control-shift-enter

=====================================
(2B)+(2B)' ?

RE: Multiplying Arrays

ElectricPete's method is the way to do it on the spreadsheet, but it looks like you are talking VBA. You can use the same worksheet functions as follows:

If your data is in two named ranges, Range1 and Range2 and you want the result in named range Range3 then:

CODE -->

Dim Array1 as variant, Array2 as variant, Array3 as variant

Array1 = Range("Range1").Value2
Array2 = Range("Range2").Value2

Array3 = Worksheetfunction.MMult(Array1, Array2)

Range3.Value = Array3 

Add in worksheetfunction.transpose(arrayname) as required.
Note that:
- You don't need to dimension Array1, 2 and 3 as arrays, VBA does it automatically when you assign the range values to the Variant
- Using .Value2 rather than .Value discards formatting information, and makes the operation significantly faster.

Doug Jenkins
Interactive Design Services
http://newtonexcelbach.wordpress.com/

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources