Need help plotting with mathematica!

1. Jun 11, 2009

jtassilo

Hi,
I want to use mathemiatica to predict the spectrum of compounds with different conformers. The input consists of 4 values: frequency (of each vibration and every conformer), Intensity, Polarizability and total energy (of the conformer).
I now want to plot the frequency vs the Intensity.
1. How do I get mathematica to plot only a vs b if my input is of the format (a, b, c, d)?
2. Next I want to weight each frequency peak using the Boltzmann distribution. So i basically want to get a graph plotting
frequency vs the Intensity*exp(-d/kT)/sum of(exp(-d/kT)).
3. After weighing each peak height with the Boltzmann distribution i want to broaden the frequencies using a gaussian profile, because in real spectra, the peaks have a certain width and are bell shaped and do not consist of single points. The gaussian function is a function of c (the Polarizability).

So in the end I would like to plot a*Function of c vs b*Function of d.
I would greatly
appreciate any help/suggestions.

2. Jun 11, 2009

Staff: Mentor

I do not understand what you are asking. If a and b are each separate inputs to your function then they are independent of each other.

3. Jun 11, 2009

jtassilo

let me rephrase my first question: Is it possible to plot in mathematica only x vs y if your input file consisits of (x, y, z, a), and you don't want to reformat your input file. If the input file is of the format (x,y) you can use the command ListPlot[input]; what is the command if your input file has a different format?

4. Jun 11, 2009

Staff: Mentor

ListPlot[input[[All,{1,2}]]]

5. Jun 12, 2009

jtassilo

Hm, Im getting the following message after typing ListPlot[data[[All, {1, 2}]]]:
{x1, y1, z1, b1}, {x2, y2, z2, b2} is not a list of numbers or pairs of numbers. (of course x1 is a specific number, which I abbreviate here with x1)

6. Jun 12, 2009

Staff: Mentor

You are really not describing your problem very well. What do you get when you do the following:

Dimensions[data]
MatrixQ[data]
MatrixQ[data,NumericQ]

If your data is not a n-row by 4-column matrix of numbers then what is it?

7. Jun 12, 2009

jtassilo

First of all thanks for you help and patience!
My input is an excel file consisiting of 4 columns and 29 rows) {{a1, b1, c1, d1}, {a2, b2, c2, d2},...
When I typed the commands, I got
{1, 29, 4}
False
False
I would now like to
1. plot the first column versus the second (plot a vs b)
2. modify the values of the first 2 columns by functions that depend on values in the the other two columns.

8. Jun 12, 2009

Staff: Mentor

OK, you have an extra "layer", perhaps representing the worksheets in Excel. To trim that off use:
data = data[[1]];

Then you should get
Dimensions[data] == {29,4}
and the other two commands should give you True

Then ListPlot[data[[All,{1,2}]]] should work.

To get the other information in there try something like

data2 = Map[{f[#[[3]],#[[4]]],g[#[[3]],#[[4]]],#[[3]],#[[4]]}&,data]

Where f and g are the functions that determine your new values for a and b respectively.

9. Jun 16, 2009

jtassilo

It worked, thanks!
I have one last question:
I am trying to plot several Gauss function.
My input is:
g= {a1, a2, a3,...}
Plot[Exp[-0.5*((x - g)/2)^2], {x, 0, 1200}]

This plots multiple gauss functions. The gauss functions overlap though and i want to add all the gauss functions together (basically they positively interfere ).
I tried the following command (it didn't work):
Plot[Sum[Exp[-0.5*((x - g)/2)^2], {x, 0, 1200}], {x, 0, 1000}]
Do you know what command might work for adding the functions?

10. Jun 16, 2009

Staff: Mentor

Try:

I am not sure it will work.

11. Jun 16, 2009

jtassilo

Yes it works great,
it does however not work when I try to use Map:
Plot[Apply[Plus, Thread[Map[{ #[[2]]....} &, data]]], {x, 0, 1200}]
Any suggestions why Plot
does not work with Map?
The normal Plot[Map[{ #[[2]]....} &, data]]], {x, 0, 1200}] command works.

12. Jun 16, 2009

Staff: Mentor

The expression:

Threads the function Map over the list that appears in the first argument. This means that it evaluates to
{Map[#[[2]] &, data], Map[ ... &, data], ...}

Which is probably not what you wanted to do.

13. Jun 17, 2009

jtassilo

Ok, this here is hopefully my last question:
I'm doing a dynamic plot using a rather complex equation (The problem does not occur with simple equations). When I hit shift enter, only the slider is returned as output and below it says "&Aborted". The strange thing is that when I use the slider it shows the graph. I can see how the graph changes when I move the mouse on the slider, but as soon as I stop pressing on the slider, the graph disappears and is replaced by "&Aborted". I read the help files concerning Dynamics and Aborted, but I haven't found a command that changes this problem. Since the calculation takes mathematica quite some time I am currently thinking that my computer might be too slow.
Any Suggestions are appreciated

14. Jun 17, 2009

Staff: Mentor

If it is easy to post the code then I will try it out. I know that there is an abbreviated rendering while you are dynamically adjusting the setting, but I have not run into that specific error before.

15. Jun 18, 2009

jtassilo

Here is the input: My other input is named data={{a1, b1, c1, d1,e1, f1}, {a2,..}}
Panel[Column[{Row[{Slider[Dynamic[T], {1, 350, 1}], Dynamic[T]}],
Dynamic[Plot[
Apply[Plus,
data[[All,
1]]*(1879421 - data[[All, 1]])^3/(1 -
Exp[-data[[All,
1]]*100*299792458*6.626*10^-34/(1.38*10^-23*T)])*
data[[All, 2]]* data[[All, 6]]*
Exp[- data[[All, 5]]*4.3597*10^-18/(1.38*10^-23 T)]/
Total[data[[All, 6]]*
Exp[-data[[All, 5]]*4.3597*10^-18/(1.38*10^-23*T)]]/(
data[[All, 1]]*(2 Pi)^0.5)*
Exp[-0.5*((x - data[[All, 1]])/2)^2]]], {x, 0, 1000},
ImageSize -> {{400, 1000}},
AxesLabel -> {v [cm^-1], I [10^-10 m^2/sr]}, PlotRange -> All,
PlotLabel -> Pentane T [K]]]}]]

Last edited: Jun 18, 2009
16. Jun 18, 2009

jtassilo

Also note plz that if the beginning of the input (Thread[1.097455759580536*10^-5 is replaced by a smaller number such as Thread[1.097455759580536*10^-105, the whole script does not work anymore, and the Gauss-function is approximated by a triangle. I think that it has something to do with the significant figures mathematica uses, but the helpfile isn't really helpful explaining how to fix this problem.

17. Jun 18, 2009

I am certain now that the $Aborted message has to do with the calculating capacity. When I change the number of input rows from 29 to for example 1400, the error message is displayed even for simple equations 18. Jun 18, 2009 Dale Staff: Mentor Well, if it has to do with numerical precision then I won't be able to help with dummy data. However, there were a few non-numerical things that I noticed: 1) Use Manipulate instead of Panel[...{Slider[Dynamic,... It is a much cleaner interface and I think that T may be getting stuck. 2) Get rid of the call to the Thread function. All of the functions inside of it are "Listable" meaning that they are automatically threaded over their arguments. 3) Wrap your function to be plotted in Evaluate: e.g. Plot[Evaluate[Apply[Plus,...]]],...] This will reduce the number of computations that have to be done at run time. 4) With my dummy data I was not getting any$Aborted messages, but I had to get rid of the ImageSize -> {{400, 1000}} option which was really messing up the display for some reason.

19. Jun 19, 2009

jtassilo

Hey, heres another question:
Is there a way to export the graph I made not as a bitmap or pdf, but as a set of points (x, y) with a predefined grid/accuracy? (Of course not a dynamic graph, but a normal graph)

20. Jun 19, 2009

Staff: Mentor

Sure, just use Rasterize[graph]

That will return a Graphics object where the first element is a Raster object. The first element of the Raster object, in turn, is a matrix containing the RGB color values at each point in the predefined grid.