Thursday, 12 September 2013

Gnuplot: Graphing and Defining Variables in Polar Coordinates

Gnuplot: Graphing and Defining Variables in Polar Coordinates

I am brand new to Gnuplot and am having a problem trying to figure out how
to graph in Polar Coordinates for a school assignment. What bothers me is
we didn't go over other coordinate systems like Polar or Parametric at all
for Gnuplot, and the internet tutorials I find seem to assume some basic
knowledge and just tell me to do "set polar".
Here is the problem I am trying to solve:
The electron density around a particular molecule centered at the origin
is described by
n(r,theta) = [cos(r)]^2 * {1+[cos(theta)]^2} * exp(-r^2/25)
where r and theta are usual polar coordinates [e.g., (x,y) =
(r*cos(theta),r*sin(theta))].
Write a gnuplot script elec.gpl that generates a surface plot of this
function on a domain of x=-5..5 and y=-5..5. Set your script so that
gnuplot> elec.gpl
generates the plot as a postscript file called "elec.ps"
Since I am completely unfamiliar with graphing Gnuplot in polar
coordinates, I am stumped. I have a tried a few different things including
the following:
set terminal png enhanced
set output 'elec.ps'
set polar
set angle degrees
set title 'Electron Density Around Molecule'
set xrange[-5:5]
set yrange[-5:5]
set grid
set grid polar
plot (cos(x))^2 *(1+(cos(y))^2)*exp(-x^2/25)
quit
I have tried changing x to r, y to t, y to theta, etc. I simply can't
figure out how Gnuplot wants me to define polar coordinate inputs. Is
there a way to redefine x as r*cos(theta) and y as r*sin(theta) and then
let me set inputs and ranges for r and theta?
Thank you for your help! :)

No comments:

Post a Comment