1
$\begingroup$

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[[1]];
 s2 = mammamia[[2]];
 st = mammamia[[3]];
 th1 = mammamia[[4]];
 th2 = mammamia[[5]];
 th3 = mammamia[[6]];
 gammai = mammamia[[7]];
 gammam = mammamia[[8]];
 gammao = mammamia[[9]];
 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[[1]][[;; , 2]]}]
 ]],100]

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

$\endgroup$
  • $\begingroup$ 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. $\endgroup$ – Yves Klett May 17 '16 at 9:36
  • $\begingroup$ This is my actual code. If you copy and paste it on a notebook, it should run. $\endgroup$ – Mirko Aveta May 17 '16 at 9:37
  • 1
    $\begingroup$ You are commenting on a Do, which is not present here. $\endgroup$ – Yves Klett May 17 '16 at 9:38
  • 1
    $\begingroup$ 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. $\endgroup$ – happy fish May 17 '16 at 9:45
  • 1
    $\begingroup$ And you should Print your result in the last line, Do only returns Null $\endgroup$ – happy fish May 17 '16 at 9:51
1
$\begingroup$

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[[1]];
 s2 = mammamia[[2]];
 st = mammamia[[3]];
 th1 = mammamia[[4]];
 th2 = mammamia[[5]];
 th3 = mammamia[[6]];
 gammai = mammamia[[7]];
 gammam = mammamia[[8]];
 gammao = mammamia[[9]];
 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[[1]][[;; , 2]]}]], 100] // Last // First
$\endgroup$
  • $\begingroup$ This might be too long, but it is exactly what I wanted!! $\endgroup$ – Mirko Aveta May 17 '16 at 9:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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