Skip to main content
8-Gravel
May 6, 2024
Solved

calculate all combinations using FOR loop

  • May 6, 2024
  • 5 replies
  • 2370 views

hello community.

need some support. 

im trying to calculate all possible combinations of Voltage * Current 

need to display all combinations in a matrix with only 1 column

in this case have 3 voltages and 3 currents

matrix result should be of 1column and 9 rows. 

 

this is what I have up to now, but not been able to display each iteration. 

EP_10906526_0-1715012398877.png

 

Best answer by MartinHanak

MartinHanak_0-1715015823828.png

 

5 replies

24-Ruby III
May 6, 2024

MartinHanak_0-1715015823828.png

 

16-Pearl
May 6, 2024

A slightly shorter version than what Martin posted.  We don't need to loop through one vector if we vectorize.  Not better, just another way to go about it.

2024-05-06_12-46-41.jpg

16-Pearl
May 6, 2024

Two other ways - taking advantage of a DOE feature. fullfact provides the combinations of subscripts needed for every combination.  Personally I'd just use nested for's since it's easier to understand and more flexible.  But it's fun to explore new ways.  (Note: answer sequence changes from other posts)

2024-05-06_14-06-30.jpg

18-Opal
May 6, 2024

ppal_0-1715030041815.png

 

21-Topaz II
May 6, 2024

Hi,

The simplest method using the power of Prime

Capture.JPG

Cheers

Terry

23-Emerald IV
May 6, 2024

Here's another approach:

LucMeekes_0-1715032529959.png

with:

LucMeekes_1-1715032547777.png

and

LucMeekes_2-1715032566347.png

and

LucMeekes_3-1715032586959.png

we get:

LucMeekes_4-1715032597351.png

and with

LucMeekes_5-1715032620824.png

we get

LucMeekes_6-1715032634239.png

and with

LucMeekes_7-1715032882955.png

we get

LucMeekes_8-1715032905176.png

you could even

LucMeekes_9-1715033027268.png

to get

LucMeekes_10-1715033042313.png

Success!
Luc