Message Boards Message Boards

GROUPS:

How to get output for such a problem in a single data file

Posted 1 month ago
309 Views
|
7 Replies
|
2 Total Likes
|

f=(A^2/2G)+(G/B)^5+(A*B/C1); A={4,7,8,9,5}; B={1,2,3,4,5}; Now for each set of A and B i.e. for {A[1],B[1]},{A[2],B[2]}.....etc. I have to take 100 set of values for G and C1

C1:=RandomReal[{1,100},{100}];
G:=RandomReal[{1,100},{100}];

And print the output in a file for each set of A and B

Export["file.txt",Reap[Do[If[1<Thread[f]<100,Sow[{A,B,G,C1}]],{n,1,100}]][[2,1]],"Table"]
7 Replies
Posted 1 month ago

Hi John,

It is not clear exactly what you are trying to do. An example of the output would be helpful. Maybe this is what you want

ClearAll@f

a = {4, 7, 8, 9, 5};
b = {1, 2, 3, 4, 5};
c = RandomReal[{1, 100}, 100];
g = RandomReal[{1, 100}, 100];

(* Note: a^2/2g is (a^2 g)/2. Did you mean a^2/(2 g) ? *)
f[a_, b_, g_, c_] := (a^2/2 g) + (g/b)^5 + (a*b/c);

Table[{a[[n]], b[[n]], g[[i]], c[[i]], f[a[[n]], b[[n]], g[[i]], c[[i]]]}, {n, 1, 5}, {i, 1, 100}] // 
  Flatten[#, 1] &
Posted 1 month ago

The form of the function i.e. *g or /g is not that important here. From a previous analysis I got a data file satisfying some conditions and it consists of a few data points of A and B, now I have two more free parameter in my model G and C1 which I have tried to vary randomly and taken 100 of such sets and for each previously known A and B values I want to find all possible values for G and C1 which satisfies the condition 1<f<100, and tried to print all such values in a file

Posted 1 month ago

The form of the function i.e. *g or /g is not that important here. From a previous analysis I got a data file satisfying some conditions and it consists of a few data points of A and B, now I have two more free parameter in my model G and C1 which I have tried to vary randomly and taken 100 of such sets and for each previously known A and B values I want to find all possible values for G and C1 which satisfies the condition 1<f<100, and tried to print all such values in a file Actually I have to solve for more than one complicated functions of several random variables like C1 and G and each function have different bounds according to their physical meaning and I atlast need the parameter space

Posted 1 month ago

Thanks for clarifying. It is easy to add a filter condition to the table generation.

Table[
  If[Between[f[a[[n]], b[[n]], g[[i]], c[[i]]], {2, 99}],
   {a[[n]], b[[n]], g[[i]], c[[i]], f[a[[n]], b[[n]], g[[i]], c[[i]]]}, 
   Nothing],
  {n, 1, 5}, {i, 1, 100}] //
Flatten[#, 1] &
Posted 1 month ago

Thanks for your reply but after trying this

A1 := RandomReal[{0, 9}, {60}];
B1 := RandomReal[{0, 9}, {60}];
R1 := RandomReal[{0.01, 10}, {100}];
R2 := RandomReal[{0.01, 10}, {100}];
f1 := RandomReal[{0.00001, 0.0000001}, {100}];
f2 := RandomReal[{0.00001, 0.0000001}, {100}];

Export["C:\\Scan168.txt", 
 Reap[Table[
    If[Between[
       mass[R1[[n]], R2[[n]], f1[[n]], 
        f2[[n]], A1[[v]], B1[[v]]], {0, 0.609999}] && 
      Between[mass3[R1[[n]], R2[[n]], f1[[n]], 
        f2[[n]], A1[[v]], B1[[v]]], {0.6001, 1.16999}] &&
       Between[
       mass1[R1[[n]], R2[[n]], f1[[n]], 
        f2[[n]], A1[[v]], B1[[v]]], {16.79001, 68.009999}] &&
       Between[
       mass2[R1[[n]], R2[[n]], f1[[n]], 
        f2[[n]], A1[[v]], B1[[v]]], {1.43601, 
        2.91799}], {R1[[n]], R2[[n]], f1[[n]], 
      f2[[n]], A1[[v]], B1[[v]]}, Nothing], {v, 1, 60}, {n,
      1, 100}] // Flatten[#, 1] &]]

I am getting error messege

Thread::tdlen: Objects of unequal length in 2 <<3>> {7.09846,11.0615,2.99195,3.59533,7.92718,9.11883,14.4567,8.97938,12.5384,7.00722,14.712,14.7486,6.62113,9.37542,13.2825,2.59686,13.4586,<<17>>,19.469,13.7266,6.78945,14.4631,5.78073,13.8504,11.7908,4.76266,10.2747,14.8003,5.85192,16.8839,13.8162,7.69785,8.22073,12.0752,<<50>>} cannot be combined.
Posted 1 month ago

What is the purpose of the Reap? There is no Sow in the expression.

Since Thread does not appear anywhere in the expression it is most likely present in the definition of one of the other symbols in the expression. What are the definitions of mass1, mass2, mass3? Suggest restarting the kernel or evaluating

ClearAll[Evaluate[Context[] <> "*"]]
Posted 1 month ago

Thanks now I think the problem is going in the right direction

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract