Sample Calls to Octave

If y is a function of t and satisfies the following differential equation


     y'' + .1* y' + sin(y) = 0;

If we use x(1) to denote a variable 'x' with subscript 1, then this may be coded in octave as a first order matrix equation:


     y  = x(1),
     y' = x(2)

so eliminating y altogether:


    x(1)' = x(2)
    x(2)' = -sin(x(1) - .1 * x(2)

In Octave we define a vector function 'pend' which encodes this, and then call the 'lsode' linear solver. The t is ranging from values 0 to 40, with 200 steps. Then we plot the solution vector [x(1),x(2)] as two plots against t. The [0.1,0.2] correspond to an initial value of X. The initial value is at the first value of t (in this case 0) of the range requested.

The plot will have 2 curves in this case, and the 'line 1' corresponds to x(1), the 'line 2' corresponds to x(2). Remember x = [y,y'] so that line 1 correpsonds to y and line 2 to y'. The "-@" says plot lines and points. Octave has complete documentation.

function xdot = pend(x,t) xdot(1) = x(2); xdot(2) = -sin( x(1)) - 0.1*x(2); end sol=lsode( "pend",[0.1, 0.2], t = linspace(0,40, 200)); plot( t, sol,"-@")

Here are some more differential equation solutions.

Plotting

There are two commands for plotting: mesh and plot depending for 3d and 2d plots.
mesh
This can take either 1 or 3 arguments, which are vectors or matrices. After clicking on rotate in the window, you can rotate the plot to view it from different angles. The original 3d coordinates of points are displayed in the upper left corner.
plot
Make 2 dimensional plots. This takes an arbitrary number of arguments, which are basically matrices or format directives. With just 1 argument it plots the values against the ticks, eg a vector with 50 entries will have 1:50 plotted on the x axis and the values on the y axis.
If there are two arguments the second is plotted against the first. If a format argument such as "-@" (meaning plot points) then this is applied to the preceding plot.
Then the whole procedure is repeated for the remaining arguments.