# How may I repeat this procedure n times?

This is the procedure

      Do[With[{},mammamia = RandomReal[1, 9];
ClearAll[inexactSolve]
SetAttributes[inexactSolve, HoldFirst]
inexactSolve[expr_Solve] :=
ReleaseHold@
Replace[Hold[expr], a_?InexactNumberQ :> inert[ToString[a]],
Infinity] /. inert[a_String] :> ToExpression[a]

With[{A = 0.625, h = 0.61},
s1 = mammamia[];
s2 = mammamia[];
st = mammamia[];
th1 = mammamia[];
th2 = mammamia[];
th3 = mammamia[];
gammai = mammamia[];
gammam = mammamia[];
gammao = mammamia[];
h1 = s1 h /2;
h2 = s2 h/2;
h3 = st h/2;
azzo = inexactSolve@Solve[
A == A1 + A2 + A3 &&
th1 == b2/b1 &&
th2 == b3/b2 &&

th3 == bt/b3 &&
A1 == h1 (b1 + b2)/2 &&

A2 == h2 (b2 + b3)/2 &&
A3 == (h - h1 - h2) (b3 + bt)/2
, {A1, A2, A3, b2, b1, b3, bt}];
Flatten[{h1, h2, h3, gammai, gammai, gammao, azzo[][[;; , 2]]}]
]],100]


I tried with 'Do' but I receive an error: 'Tag Times in Null\ Null\ inexactSolve[expr_Solve] is Protected.'

• Without your actual code, we cannot help you finding the error. However, perhaps Table or similar constructs would be simpler to use, but at the moment it is unclear what exactly you intend. – Yves Klett May 17 '16 at 9:36
• This is my actual code. If you copy and paste it on a notebook, it should run. – Mirko Aveta May 17 '16 at 9:37
• You are commenting on a Do, which is not present here. – Yves Klett May 17 '16 at 9:38
• You are missing three ;s : at the end of line 2, end of line 3 and after ToExpression[a]. Plus, I don't see any reason to put the function def inside Do, and your inert is not defined. – happy fish May 17 '16 at 9:45
• And you should Print your result in the last line, Do only returns Null – happy fish May 17 '16 at 9:51

Too long for a comment. You can try this. res will contain a list of you 100 result.

ClearAll[inexactSolve] ; SetAttributes[inexactSolve, HoldFirst] ;
inexactSolve[expr_Solve] :=
ReleaseHold@
Replace[Hold[expr], a_?InexactNumberQ :> inert[ToString[a]],
Infinity] /. inert[a_String] :> ToExpression[a];

res = Reap@Do[
With[{A = 0.625, h = 0.61}, mammamia = RandomReal[1, 9];
s1 = mammamia[];
s2 = mammamia[];
st = mammamia[];
th1 = mammamia[];
th2 = mammamia[];
th3 = mammamia[];
gammai = mammamia[];
gammam = mammamia[];
gammao = mammamia[];
h1 = s1 h/2;
h2 = s2 h/2;
h3 = st h/2;
azzo =
inexactSolve@
Solve[A == A1 + A2 + A3 && th1 == b2/b1 && th2 == b3/b2 &&
th3 == bt/b3 && A1 == h1 (b1 + b2)/2 &&
A2 == h2 (b2 + b3)/2 && A3 == (h - h1 - h2) (b3 + bt)/2, {A1,
A2, A3, b2, b1, b3, bt}];
Sow@Flatten[{h1, h2, h3, gammai, gammai, gammao,
azzo[][[;; , 2]]}]], 100] // Last // First

• This might be too long, but it is exactly what I wanted!! – Mirko Aveta May 17 '16 at 9:56