2
$\begingroup$

Let's say I have a function W[x_]; and would like to export the data for xrange -100 to 100

I have tried this

Result=W[#] & /@Range[-100,100];
Export = ["result,txt",Result,"List"]

Eg: The output I get:

    w[x_]
    -1.0
    -1.5
    -2.0

But I would like to save the x_ values as the first column and w[x_] as the second column

 x_      w[x_]
 -100      -1.0
 -99       -1.5
 -98       -2.0
 ...        ....
 100       5.0

How does one print x_ values too ?

$\endgroup$
2
$\begingroup$

Using your code in Export data from NIntegrate and Piecewise this is how to do it

 data = {#, W[#]} & /@ Range[-2, 2]

Mathematica graphics

Now save it using the same commands in the above answer

SetDirectory[NotebookDirectory[]];
Export["result.txt", data, "List"]

Change the Range command above to whatever you want.

$\endgroup$

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.