lettura simple

Logarithmic Scale Diagrams in Octave

In this lesson, I will explain how to create a logarithmic scale diagram in Octave.

A logarithmic scale diagram is a graph in which values are represented on a logarithmic scale on the x-axis and/or y-axis. It is useful for representing data that grows exponentially.
example of logarithmic scale diagram

To create a logarithmic scale diagram in Octave, you can follow these steps.

Create an array with the values of the variable x from 1 to 10

>> x=0:1:10;

Create an array with the values of y.

In this example, the array is composed of the squares of x:

>> y=x.^2

Plot the function on a normal Cartesian diagram with the function plot(x,y)

>> plot(x,y)

It is an exponential function.

graph of an exponential function.

To represent the function on a diagram with a logarithmic scale on the y-axis, use the function semilogy().

>> semilogy(x,y)

Now, the y-axis is on a logarithmic scale in the diagram.

Graph on a logarithmic scale

To display gridlines on the logarithmic scale diagram, type grid on.

>> grid on

This makes the logarithmic scale easier to see.

Adding gridlines to logarithmic scale

How to apply a logarithmic scale to the x-axis?

If you want to display the diagram on a logarithmic scale on the x-axis, use the function semilogx()

>> semilogx(x,y)

In this way, only the x-axis is on a logarithmic scale.

In the graph, the x-axis is on a logarithmic scale.

How to create a graph with a logarithmic scale on both axes?

To represent a logarithmic diagram on both axes, use the function loglog()

>> loglog(x,y)

Now, both axes are on a logarithmic scale in the graph.

Logarithmic scale diagram

If this lesson on Octave by Nigiara is useful, continue to follow us.




If something isn't clear, write your question in the comments.




FacebookTwitterLinkedinLinkedin