English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
GNU Octave is a high-level programming language like MATLAB and is mostly compatible with MATLAB. It is also used for numerical computation.
The following are common features of Octave and MATLAB-
Matrices are basic data types
It has built-in support for complex numbers
It has built-in mathematical functions and libraries
It supports user-defined functions
GNU Octave is also free software that can be redistributed. You can redistribute and redistribute it according to the terms of the GNU General Public License (GPL) published by the Free Software Foundation./or modify it.
Most MATLAB programs run in Octave, but some Octave programs may not run in MATLAB because Octave allows some syntax that MATLAB does not allow.
For example, MATLAB only supports single quotes, but Octave supports both single and double quotes to define strings. If you are looking for an Octave tutorial, please start reading this tutorial from the beginning, which covers both MATLAB and Octave.
Almost all examples introduced in this tutorial are compatible with MATLAB and Octave. Let's try the following example to produce the same result in MATLAB and Octave without any syntax changes-
This example is a function g = xe- (x 2 + y 2)Create3D surface plot. Create a script file and enter the following code-
[x,y] = meshgrid(-2:.2:2); g = x .* exp(-x.^2 - y.^2); surf(x, y, g) print -deps graph.eps
When running the file, MATLAB displays the following3-D Mapping-
Although all core functionalities of MATLAB can be used in Octave, some features (such as differential and integral calculus) do not match completely in both languages. This tutorial attempts to provide examples that differ in syntax.
Consider the following example, where MATLAB and Octave use different functions to obtain the area under the curve: f(x)= x 2 cos(x)represents the negative4≤x≤9Here is the MATLAB version of the code-
f = x^2*cos(x); ezplot(f, [-4,9]) a = int(f, -4, 9) disp('Area: '), disp(double(a));
When running the file, MATLAB plots the following graph-
Display the following result
a = 8*cos(4) + 18*cos(9) + 14*sin(4) + 79*sin(9) Area: 0.3326
However, to calculate the area under the same curve in Octave, you will have to use the followingsymbolicPackage-
pkg load symbolic symbols x = sym("x"); f = inline("x^2*cos(x)"); ezplot(f, [-4,9]) print -deps graph.eps [a, ierror, nfneval] = quad(f, -4, 9); display('Area: '), disp(double(a));