lettura simple

Polar Graphs in Octave

In this lesson, I'll show you how to draw a polar graph in Octave.

What is a polar graph? A polar graph (or polar plot) is a circular graph used in scientific contexts to represent the polar coordinates of a function.
example of polar graph with two functions

Let me give you a practical example.

Create the vector theta of angular variations.

>> theta = 0 : 0.1 : 2*pi;

This command creates a vector containing values from 0 to 2π (360°) with a constant increment of 0.1.

Now, define an array with the values of the function as a function of the angular variations theta.

>> y1=0.5+(1.3).^(theta);

The arrays theta and y1 have the same number of elements.

To represent the function on a polar graph, use the function polar()

>> PolarGraph = polar(theta,y1,"*");

Octave displays the polar graph, and each point is indicated with an asterisk.

In this case, it is a spiral function.

polar graph with a spiral function

How to draw two functions overlapping on the polar graph?

First, clear the screen from the previous example.

clf

Create the vector of angular variations again.

>> theta = 0 : 0.1 : 2*pi;

Now, generate the arrays of two functions y1 and y2 instead of one.

>> y1=0.5+(1.3).^(theta);
>> y2 = 3*(1 - cos(theta));

Next, create a matrix [m] that contains both functions.

>> m = [y1;y2];

This way, you can display both functions overlapping on the graph using the polar() function only once.

>> PolarGraph = polar(theta,m);

Both functions are printed on the polar graph.

polar chart with two spiral functions

However, the two lines are difficult to see.

To double the thickness of the lines, use the set() command.

set(PolarGraph,"LineWidth",2);

Now the multiple polar graph is certainly more understandable.

a polar graph with 2 functions

To add a legend to the graph, use the legend() function.

legend("y1","y2");

The legend appears near the polar graph in the top right corner.

how to add a legend

This way, you can represent two or more overlapping functions in a single polar graph.

Note.For example, create a new function y3, generate a matrix with three functions m = [y1; y2; y3]. Then, display the three graphs on the polar graph.
how to add a function to the polar graph
Now the polar graph displays three overlapping functions.
example of polar graph with 3 functions

If this Octave lesson on polar graphs has helped you, please continue to follow us.




Report a mistake or post a question




FacebookTwitterLinkedinLinkedin