1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Homework Help: Convert a string of numbers into a graph

  1. Jan 24, 2013 #1
    1. The problem statement, all variables and given/known data
    This isn't actually a hw problem it's a problem I'm having in research since the fortran code I was given spat out a huge chunk of numbers. I've gotten the new-lines removed and I would like to graph what I have but it should really be organized in like 8-tuples.

    I haven't used mathematica (for graphing) in a while and I'm not sure if I can even use it to graph an 8-tuple...It's 7 dependent variables and 1 dependent one.
    [various parameters as a function of radius from the center of the galaxy]

    2. Relevant equations

    3. The attempt at a solution
    I am considering taking a python script and inserting commas before each whitespace and brackets around every 8 numbers and removing the white space...but I don't know if I can just feed these into Mathematica or if I should be using another graphing utility...things will need to be on a log scale...

  2. jcsd
  3. Jan 24, 2013 #2

    Simon Bridge

    User Avatar
    Science Advisor
    Homework Helper

    Well, you won't be able to plot an 8D graph! So you need to start out with some idea of how you'd go about graphing your 8-tuples by hand.
    Then you can find the mathematica plotting function that automates that.

    i.e. what you want the graph for dictates what you do.

    Mathematica does have the ability to use a text file as a source of data so you are fine there.

    Your representation would be an 8xN matrix, where the first row is your independent variable and you have N of them. If you just plot(x,y) the other 7 against the first row, you'd get 7 lines on a 2D graph. Of course, you can plot any pair of rows against each other.
  4. Jan 25, 2013 #3
    You may also use gnuplot, which uses directly text files.

    As Simon said, unless you got a computer from the 9th dimension, you will have some difficulties plotting all the variables at the same time. Solutions include:
    • Plotting couples of triplets of data (2d or 3d representations)
    • Project your 8-dimension data into a 2-dimension plane

    Without knowing more about the data you want to process, it is a bit difficult to give tailored advices.

  5. Jan 25, 2013 #4
    I suppose I wasn't clear enough, sorry about that:
    The data should be organized like this:
    Currently it is in two forms:
    1. A single string of all the numbers with varying white space and no commas or parens.
    2. Sets of 16 with a '\n' [new line] after each set.

    Though not really necessary, I'll mention that these are various parameters of AGN disks, as a function of radius, like Rosseland Mean Opacity.
  6. Jan 26, 2013 #5

    Simon Bridge

    User Avatar
    Science Advisor
    Homework Helper

    OK then, basically the same as before, but transposed:
    ... for N sample points (N-1 intervals) you'll end up with a Nx9 data matrix D.

    $$D = \left [ \begin{array}{ccccc}
    r_1 & f_1(r_1) & f_2(r_1) & \cdots & f_8(r_1)\\
    r_2 & f_1(r_2) & f_2(r_2) & \cdots & f_8(r_2)\\
    r_3 & f_1(r_3) & f_2(r_3) & \cdots & f_8(r_3)\\
    \vdots & \vdots & \vdots & \ddots & \vdots\\
    r_{N-1} & f_1(r_{N-1}) & f_2(r_{N-1}) & \cdots & f_8(r_{N-1})\\
    r_N & f_1(r_N) & f_2(r_N) & \cdots & f_8(r_N)
    \end{array} \right ]$$

    How you get it into that form is up to you... and kinda depends on the organization of the current file.
    I think mathematica can handle arbitrary space characters - what's important is it needs to know where the row/column breaks are for the matrix.
    i.e. if the forst N numbers are all r, and the next N are f1, and the next N f2 etc, then you'll want to tell mathematical that.

    Once you have the matrix D:
    plot(D) will give you a graph with 8 lines, one for each ##f_n##.
    Last edited: Jan 26, 2013
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook