# How to work on "Do" loop?

let's say

parameter={a->2, b->3
c->Range[1,10,0.5],
d->Range[1,10,0.5]}

Do[ eqa[parameter_]:=Module[{a,b,c,d},

cd=c[i]*d[j]/.parameter]]

eqa[parameter]


I expect the result should be

Refer to c->Range[1,10,0.5] is {a,b,c,d} d->Range[1,10,0.5] is {A,B,C,D}

Finally, I'd like to see the results in table form, as shown in the image above.

Edited2:

The way you showed is the result that I expect. Unfortunately, I can't implement it with my code. I literally get it all but the final results are wrong.

parameters={a->2, b->3
width->Range[1,10,0.5],
lenght->Range[1,10,0.5]}

eqa[parameters_]:=Module[{a,b,lenght,width}

aw = Flatten[Transpose[{width} /. parameters]];
bl = Flatten[Transpose[{lenght} /. parameters]];
area = Outer[Times, aw, bl];
cir = Outer[Plus, 2*aw, 2*bl];
uef=(area/cir)*a/.parameters;]

eqa[parameters]


the results of area and cir are perfect but when it operates with uef, it doesn't get the right answer. I am confused.

• Are you missing some syntax here? Do takes two arguments, the expression to evaluate each iteration and the iterator. You also seem to be making a pattern-matching definition inside a Do loop, which would just overwrite the definition each time...do the examples in the help docs for Do make sense? Commented Feb 9, 2023 at 1:59
• Move Module outside the Do loop. Makes no sense to redefine the function every time. Commented Feb 9, 2023 at 19:08

Clear["Global*"];

parameter = {a -> 2, b -> 3 , c -> Range[1, 10, 0.5],
d -> Range[1, 10, 0.5]};

Flatten[Transpose[{c, d} /. parameter] /. {x_, y_} :> {x*y}]

(* {1., 2.25, 4., 6.25, 9., 12.25, 16., 20.25, 25., 30.25, 36., 42.25,
49., 56.25, 64., 72.25, 81., 90.25, 100.} *)

c*d /. parameter

(* {1., 2.25, 4., 6.25, 9., 12.25, 16., 20.25, 25., 30.25, 36., 42.25,
49., 56.25, 64., 72.25, 81., 90.25, 100.} *)

% === %%

(* True *)


EDIT: For revised question

Clear["Global*"]

v1 = {A, B, C, D};

v2 = {a, b, c, d};

TableForm[tab1 = Outer[HoldForm[Times[#2, #1]] &, v1, v2],
TableHeadings -> {v1, v2}]


parameter = {a -> 2, b -> 3, c -> Range[1, 10, 1/2],
d -> Range[1, 10, 1/2]};

With[{v1 = c /. parameter, v2 = d /. parameter},
TableForm[tab2 = Outer[Times, v1, v2],
TableHeadings -> {v1, v2}] /. r_Rational :> N[r]]


EDIT 2: For your latest change,

In the list of rules you keep leaving out a comma (after b -> 3).

I changed to the standard spelling of length.

parameters = {a -> 2, b -> 3, width -> Range[1, 10, 0.5],
length -> Range[1, 10, 0.5]};


If you make the variables local to the Module, the names in the Module are not the same as those in the Global namespace and the replacements won't work. Alternatively, move the definition of parameters into the Module.

The way that you did the replacements makes no sense.

You were missing a comma in the Module and you suppressed any output with the final semicolon.

eqa[parameters_] := Module[{},
aw = width /. parameters;
bl = length /. parameters;
area = Outer[Times, aw, bl];
cir = Outer[Plus, 2*aw, 2*bl];
uef = (area/cir)*a /. parameters]

TableForm[tab = eqa[parameters],
TableHeadings -> {aw, bl}]


• I am sorry I was wrong. I actually want to get c=[1,2,3,4] d=[1,2,3,4] if c*d ,it should be 1*1, 1*2,1*3 2*1,*2*2, 2*3 Something like this like a matrix. I am sorry I was wrong about using transpose. Commented Feb 9, 2023 at 10:21
• Edit your question to reflect what you actually want. Show the full result that you are expecting. Commented Feb 9, 2023 at 15:28
• I already add more info. I hope it can clear thing up. Commented Feb 9, 2023 at 16:37
• The results were perfect but the final results were wrong when it was implemented with other equations. Commented Feb 9, 2023 at 20:32
• Hi, it works perfectly. It was my fault. I put the wrong variables. Everything works perfectly now. Thank you very much. Commented Feb 13, 2023 at 9:16