Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

So far I have been solving non-linear pdes with NDSolve and then plotting the result with the in-built Plot3D and ContourPlots.

An example file can be found here.

This is a two part question with part 1 leading in to part 2.

Part 1

How do I interpret the interpolating function (how do I read it)?

For instance, I can "expand" the InterpolatingFunction with

InterpolatingFunctionGrid[hSol]

This obviously has all the points that Plot3D plots with. How do I read this, say, row-wise or column-wise to make more sense of whats going on?

Part 2

How can I save this data to a .csv format or just some external file to use, say, gnuplot or some other plotting routine?

I have trid DumpSave etc . but the resulting huge files are generally not cross platform compatible.

share|improve this question
    
Define "read it." Do you mean that you wish to read it yourself, or do you wish to have some other program (as you've implied) interpret it for you? (The latter obviously requires an understanding of the internal structure, but not necessarily the ability to read the internals yourself.) More specifically, why do you wish to do this? What are you using it for? –  rcollyer Aug 20 '12 at 14:58
    
@rcollyer I wish to do this (export data) because I am not a big fan of mathematica's Plot functions. When I say, "read", I mean, how is the data laid out? Should I look at it columnwise/rowwise? –  drN Aug 20 '12 at 15:04
    
Perhaps I am not getting this, but once you´ve got your InterpolationFunction up and running, you can extract and generate values according to your or your plotting software´s liking... –  Yves Klett Aug 20 '12 at 16:08
    
@YvesKlett HOW must I extract data, is the question. DumpSave didn't help. ONe person thinks I should use export. I'll try that soon. –  drN Aug 20 '12 at 16:10
1  
Please help us by refining your question: What exactly do you want to achieve? How does your input look like (post working code)? How should the result look like? –  Yves Klett Aug 20 '12 at 16:47
show 1 more comment

2 Answers

up vote 2 down vote accepted

It depends on what you want to do with your data afterwards

Needs["DifferentialEquations`InterpolatingFunctionAnatomy`"]
l = Flatten[
   Table[{{x, y}, x^2 + y^2}, {x, -1, 1, .1}, {y, -1, 1, .1}], 1];
f = Interpolation[l];

(* To export as a text file*)
ListPlot3D[
 r = Flatten /@ Transpose[Flatten[#, 1] & /@ 
                       {InterpolatingFunctionGrid[f], InterpolatingFunctionValuesOnGrid[f]}]]

(* Export as a CSV file *)
Export["c:\\test.csv", r];

Mathematica graphics

Note: Please note that the above is needed if your function is expensive to calculate, because the following is a lot easier to type:

 Export["c:\\test.csv", Table[{x,y,f@x},{x,0,1,.1},{y,0,1,.1}]];

Also, you may export for other pieces of s...oftware. Like Excel:

(*I don't mean to be rude, but the following is for Excel 3D plots (OMG)*)
Export["c:\\test.xls", InterpolatingFunctionValuesOnGrid[f]]

Mathematica graphics

share|improve this answer
    
YOu weren't rude at all! I'll look into this. I am doing so right now. However, my interpolating function thingy is 6MB or more for my problem and I am having a tough time loading it and extracting data from it. Lots of curly brackets I don't know what to do with. And then there is the matter of how should I read this data? Which is X, Y and Z? –  drN Aug 20 '12 at 19:39
1  
@DNA If you are really planning to plot this kind of thing in Excel, be prepared to suffer a lot. It's MUCH easier to do it in Mma. Go to Chat and ping me if you need help –  belisarius Aug 20 '12 at 19:43
    
No, not in excel. I was only wondering if I could extract data. The reason I want to is that I have literally 100s of cases that I run in mathematica and I can't extract the data out of mathematica. So if I need some data I don't have, I need to re-run my simulations which is quite the pain in the rear. –  drN Aug 20 '12 at 19:45
    
@DNA The Export[] before the Excel example in my code exports a CSV without braces –  belisarius Aug 20 '12 at 19:48
    
Noticed. However, it seems to entail a lot of trouble with mathematica commands that sound so foreign to me to just export the simplest of data cases. Wow. Sorry but I've been extremely frust. with mathematica's lack of easy export capabilities. –  drN Aug 20 '12 at 19:50
show 2 more comments

Interpolation stores it's data consistent with other Mathematica functions:

Needs["DifferentialEquations`InterpolatingFunctionAnatomy`"]
f = Interpolation[
   Flatten[Table[{{x, y}, Sin[x y]}, {x, 0, 1, .25}, {y, 0, 2, .25}], 
    1]];
InterpolatingFunctionGrid[f] === 
 Table[{x, y}, {x, 0, 1, .25}, {y, 0, 2, .25}]
(* True *)

To export that raw data you could use Export

share|improve this answer
    
Ummm... there are a lot of curly brackets. How should I go about getting rid of all the curly brackets? –  drN Aug 20 '12 at 19:31
    
@DNA, Export[] will take care of that for you. Within Mathematica, however, the curly brackets are a necessity. –  J. M. Aug 20 '12 at 19:38
    
Export didn't take care of the curly brackets for me. I am thinking of writing a bash script to do that. –  drN Aug 20 '12 at 19:39
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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