Gnuplot in Polar Coordinates

In summary, if you are having trouble graphing in polar coordinates using Gnuplot, here are a few tips that might help you: you can redefine x and y as r*cos(theta) and r*sin(theta) respectively, use the "parametric" plot command, and set the ranges for r and theta in your plot command. Best of luck with your assignment!
  • #1
adamwest
10
1
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".

1. 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"



Homework Equations


None, just miscellaneous commands listed below


The Attempt at a Solution



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? I bet the answer is something obvious because Gnuplot is REALLY easy to use for rectangular coordinates.

Thank you for your help! :)
 
Physics news on Phys.org
  • #2


Hello!

I can understand your frustration with trying to graph in polar coordinates using Gnuplot. It can be confusing if you are not familiar with it. Here are a few tips that might help you out:

1. As you mentioned, you can redefine x and y as r*cos(theta) and r*sin(theta) respectively. This can be done using the "using" keyword in your plot command. For example, your plot command can look like this: plot 'datafile' using (r*cos(theta)):(r*sin(theta)):(expression) with lines.

2. Another way to plot in polar coordinates is to use the "parametric" plot command. This allows you to specify the equations for both r and theta in terms of a parameter t. For your case, it would look like this: plot [t=0:360] (t):(expression) with lines.

3. You can also set the ranges for r and theta in your plot command. For example, if you want to plot for r=0 to 5 and theta=0 to 360, your plot command would look like this: plot [r=0:5] [theta=0:360] (expression) with lines.

I hope these tips help you out in solving your problem. If you need more help, feel free to ask! Best of luck with your assignment.
 

1. What is Gnuplot in polar coordinates and how does it differ from Cartesian coordinates?

Gnuplot in polar coordinates is a type of graphing tool that allows for the plotting of data using a polar coordinate system. This differs from Cartesian coordinates, which use a rectangular grid system. In polar coordinates, the distance from the origin and the angle from a reference point are used to plot data points, while Cartesian coordinates use x and y coordinates on a grid.

2. What are the benefits of using Gnuplot in polar coordinates?

One of the main benefits of using Gnuplot in polar coordinates is that it is useful for visualizing data that has a circular or rotational pattern, such as data from a radar or satellite. It can also be helpful for representing data in a more intuitive way, as circular plots can be easier to interpret than rectangular ones. Additionally, it allows for the plotting of complex functions that cannot be easily represented in Cartesian coordinates.

3. How do I create a polar plot in Gnuplot?

To create a polar plot in Gnuplot, you can use the set polar command followed by the plot command with the desired data points. You can also customize the plot by adjusting the range, angles, and labels using various Gnuplot commands. There are also options for adding gridlines, legends, and titles to the plot.

4. Can I combine polar and Cartesian plots in Gnuplot?

Yes, it is possible to combine polar and Cartesian plots in Gnuplot by using the set parametric command. This allows for the plotting of both types of coordinates on the same graph. However, it is important to note that the scales of the two plots may differ, so it is recommended to use axis labels and legends to clearly distinguish between the two coordinate systems.

5. Are there any limitations to using Gnuplot in polar coordinates?

While Gnuplot in polar coordinates can be a useful tool for visualizing certain types of data, it does have some limitations. For example, it may not be the best option for representing data with a linear relationship, as this can be more easily shown in Cartesian coordinates. Additionally, it may not be suitable for very large or small data sets, as the circular plot may become distorted. It is important to carefully consider the type of data being plotted and whether polar coordinates are the best choice for representing it.

Similar threads

Replies
8
Views
221
  • Differential Geometry
Replies
9
Views
402
  • Engineering and Comp Sci Homework Help
Replies
9
Views
2K
  • Introductory Physics Homework Help
Replies
10
Views
250
  • Introductory Physics Homework Help
Replies
1
Views
870
  • Special and General Relativity
Replies
14
Views
785
  • General Math
Replies
7
Views
1K
  • Calculus and Beyond Homework Help
Replies
3
Views
547
  • Engineering and Comp Sci Homework Help
Replies
6
Views
1K
  • Differential Equations
Replies
4
Views
2K
Back
Top