Learn How to Calculate Product in MATLAB (R2010a) | Step-by-Step Guide

  • Context: MATLAB 
  • Thread starter Thread starter dunyali
  • Start date Start date
  • Tags Tags
    Matlab Product
Click For Summary

Discussion Overview

The discussion focuses on calculating the product of elements in MATLAB (R2010a), specifically addressing both vector and multi-dimensional matrix scenarios. Participants seek guidance on performing these operations effectively within the software.

Discussion Character

  • Homework-related
  • Technical explanation

Main Points Raised

  • One participant asks how to calculate the product of a sequence of function values f(1)*f(2)*...*f(n) in MATLAB.
  • Another participant suggests using the built-in function prod(f) after defining the vector f.
  • A different participant describes a scenario involving a 4D matrix M and seeks assistance with element-wise multiplication across its dimensions.
  • One reply directs participants to MATLAB's Help entry for guidance on taking the product over a specified dimension, indicating a willingness to assist further without completing the task for others.

Areas of Agreement / Disagreement

There is no consensus on the best approach for the multi-dimensional case, as participants present different scenarios and methods without resolving the differences.

Contextual Notes

Some assumptions about the definitions and dimensions of the vectors and matrices involved are not explicitly stated, which may affect the applicability of the proposed solutions.

dunyali
Messages
2
Reaction score
0
Can someone tell me how to do the following in MATLAB (R2010a):

f(1)*f(2)*...*f(n)

thanx in advance.
 
Physics news on Phys.org
I assume that you have already defined the contents of the vector f of length n.
Then
p = prod(f);
 
Hi, marcusl

I have a 4d matrix M, with size: a * b * c * n
This is exactly what I want: M(:,:,:,1).*M(:,:,:,2).*...*M(:,:,:,n) (this is element wise multiplication of the elements)

Please help.
 
Read Matlab's Help entry, which tells you exactly how to take the product over a desired dimension (index). I will help you if you're stuck, but I will not do all your work for you.
 

Similar threads

  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
Replies
5
Views
3K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 5 ·
Replies
5
Views
3K
Replies
5
Views
3K
Replies
8
Views
4K
  • · Replies 5 ·
Replies
5
Views
4K