These commands are incorrect and will cause errors: This is done by preceding the operation in question with a period, as in. To avoid errors when we are evaluating a function at a numeric input vector, we need to use the elementwise versions of exponentiation, multiplication, and division between variables. Octave makes extensive use of elementwise operations which are covered here and here.Īn important consideration when working with a more complex function like, say, y = x^2 sin(x), is that Octave will regard the product and exponent as matrix operations, unless we indicate otherwise.
Notice that sets of input and output variables come in pairs, followed by any options that apply to that pair. > legend ( 'data points', 'regressionline' ) Alternately, we can create multiple plots within a single plot command. Now we should see four points and the graph of the line.
Then any new plots will be drawn onto the current axes. To add to our current graph we need to use the command hold on. Now suppose we want to graph the line y = 1.2x on the same set of axes (this is the line of best for this data). Let's set the axes to match the domain and range of the function. The window is controlled by a vector of the form. We can set the window with the axis command. You may wish to customize it a little bit. You should see the graph of f(x) = sin(x) pop up in a new window. Now, to plot the function, use the plot command: Now, we want to create a vector of the corresponding y-values. The semicolon at the end of the line is to suppress the output to the screen, since we don't need to see all the values in the vector. In this case, 50 points should be suitable. The smaller the increment, the smoother the curve will look. This creates a row vector of 50 evenly spaced values beginning at 0 and going up to 2. Notice the format linspace (start val, end val, n). We begin by creating a vector of x-values. The process is less automated in Octave (but in the end, much more powerful).
Like a typical graphing calculator, Octave will simply plot a series of points and connect the dots to represent the curve. Let's start by plotting the graph of the function sin(x) on the interval. The bulk of this text is from section 1.4 of this document. I have found this to be true again and again in my career so we will spend most of this tutorial on plotting with Octave. PlotsĪ picture is worth a thousand words. All arithmetic operations in Octave are assumed to be matrix operations unless specified otherwise. Matrix operations include multiplication, transposition, determinants, and eigenvalues. Vector procedures such as dot product, cross product, normal, and vector projection are supported. Octave knows basic arithmetic, ignores most white space, and recognizes a LOT of vector and matrix operations. Resources on them are all over the Internet and are not covered here. Vectors and Matrices are core data types of Octave (and MATLAB).
The one that worked for me was gnuplot - qt was not working for some reason.įurther tips for Windows development with Octave can be found here. See this stackoverflow article to switch between GUI engines for octave in WSL 2. If you prefer, you can just fire up the CLI. Note that I have to explicitly specify "octave -gui" when starting up in WSL 2 with Ubuntu 20.04 but you may not have to. Much of this tutorial owes its existence to this document, from this page. I'm doing this tutorial on Windows 11 with Windows Subsystem for Linux 2.0, running Ubuntu 20.04. It is comparable to MATLAB and has much of MATLAB's functionality, sans the high price tag and licensing fees associated with MATLAB's numerous add ons - do not get me started on the inefficiencies of the MATLAB C/C++ compiler! Don't get me wrong, those MATLAB libraries are powerful and Octave does not have the resources of MathWorks, but I find it is often powerful enough to suit my needs. My go to Open Source mathematics solution is GNU Octave.