Exporting Data file in .dat format [duplicate]

Here I'm solving two simultaneous to get different values of the roots depending upon another variable 'x'. I've written up to the following using 'Find Root'

g[x_] = 2*x;
f1[p_, q_] = 2*g[x]*p^4 + q^2;
f2[p_, q_] = 5 p^2 + q - g[x];
For[x = 0, x < 10, x = x + 1,
Print[{p, q, x} /.
FindRoot[{f1[p, q] - 5 == 0, f2[p, q] - 10 == 0}, {{p, 5}, {q, 1}}]]];


Now can I export this in a data file (three column)?

• Have you looked at Export? Mar 2, 2015 at 11:31
• Trying to figure out how to use that here.
– Doon
Mar 2, 2015 at 11:39
• It's kind of hard to comment on this without working code. (e.g. define f1, f2, fix the {{p,1},{p,2}} etc.)
– djp
Mar 2, 2015 at 12:23
• Something like this 'g[x_] = 2*x; f1[p_, q_] = 2*g[x]*p^4 + q^2; f2[p_, q_] = 5 p^2 + q - g[x]; For[x = 0, x < 10, x = x + 1, Print[FindRoot[{f1[p, q] - 5 == 0, f2[p, q] - 10 == 0}, {{p, 5}, {q, 1}}]]];'
– Doon
Mar 2, 2015 at 12:32

Use Table, not For:

output = Table[
{p, q, x} /. FindRoot[{f1[p, q] - 0.03 == 0, f2[p, q] - 0.0234 == 0}, {{p, 1}, {q, 2}}],
{x, 0, 359}
]


Look in \$ExportFormats to find the format you want.

Export["output.csv", output]

• I've fixed the {{p,1},{p,2}} thing. I think it's very odd that your code doesn't use x anywhere.
– djp
Mar 2, 2015 at 12:29
• Can one use 'Export' when we are using 'For'?
– Doon
Mar 2, 2015 at 12:45
• Don't use For. mathematica.stackexchange.com/questions/18393/…
– djp
Mar 2, 2015 at 13:02