2
$\begingroup$

Suppose I have $t=4, 2, 5$ and $v=5, 7, 4, 8, 0, 5$ and $equ=A v/t$. I would like to calculate $equ$ at a single value of $t$ by using all $v$ values and then move to next value of $t$.

How can I make a loop for this?

$\endgroup$
  • 5
    $\begingroup$ tab = Table[A v/t, {t, {4, 2, 5}}, {v, {5, 7, 4, 8, 0, 5}}]. $\endgroup$ – Henrik Schumacher May 3 '18 at 15:28
1
$\begingroup$

Another simple way using Map:

 t = {4, 2, 5}; v = {5, 7, 4, 8, 0, 5};
 equ = A (v/#) & /@ t

(*{{(5 A)/4, (7 A)/4, A, 2 A, 0, (5 A)/4}, {(5 A)/2, (7 A)/2, 
 2 A, 4 A, 0, (5 A)/2}, {A, (7 A)/5, (4 A)/5, (8 A)/5, 0, A}}*)
$\endgroup$
2
$\begingroup$
t = {4, 2, 5} ; v = {5, 7, 4, 8, 0, 5};
A Outer[#2/# &, t, v] (* or *)
A Outer[Divide, v, t] // Transpose

{{(5 A)/4, (7 A)/4, A, 2 A, 0, (5 A)/4}, {(5 A)/2, (7 A)/2, 2 A, 4 A, 0, (5 A)/2}, {A, (7 A)/5, (4 A)/5, (8 A)/5, 0, A}}

$\endgroup$
  • $\begingroup$ thank you guys i appreciate your help $\endgroup$ – Rabia May 4 '18 at 9:39
  • $\begingroup$ @rabia, my pleasure. Welcome to mma.se. $\endgroup$ – kglr May 4 '18 at 9:54

Not the answer you're looking for? Browse other questions tagged or ask your own question.