Latest revision |
Your text |
Line 1: |
Line 1: |
| For the meaning of operators, see the [https://octave.org/doc/interpreter/Operator-Index.html GNU Octave manual].
| | = The very basics = |
| | <tt>+ | - | * | / | ^ | pi | i | inf | eps | sin | cos | tan | exp | log | log10 | abs | sqrt | sign | round | ceil | floor | fix | = | , | ; | who | clear | help | lookfor</tt> |
| | x = pi, y = floor (sin (x)), z = log (exp (2013)), z / inf ↵ |
| | = Vectors and matrices = |
| | <tt>: | .* | ./ | .^ | ' | .' | \ | length | numel | size | zeros | ones | eye | diag | rand | det | trace | inv | lu | eig | cond | expm</tt> |
| | x = 1:5, x(:), x(2:4), A = [11 12; 21, 22], A(1,1:end) ↵ |
| | = Graphics = |
| | <tt>plot | semilogx | semilogy | loglog | contour | quiver | surf | mesh | meshgrid | xlabel | ylabel | zlabel | title | grid | axis | hold | subplot | figure | print</tt> |
| | t = 0:0.01*pi:21*pi; x = sin (t).*(exp (cos (t)) - 2*cos (4*t) + sin (t/12).^5); y = cos (t).*(exp (cos (t)) - 2*cos (4*t) + sin (t/12).^5); plot(x, y) ↵ |
| | = Scrpts and functions = |
| | <tt>@ | function | return | nargin | nargout | varargin | varargout | feval | eval</tt> |
| | f = @(x) x.^2, f(1:10) ↵ |
|
| |
|
| === The very basics ===
| | function v = cossum (x, n) v = cumsum (repmat (cos (x), 1, n)); |
| | | = Programming elements = |
| <code>+</code> , <code>-</code> , <code>*</code> , <code>/</code> , <code>^</code> , {{manual|pi}} , {{manual|I}} , {{manual|e}} , {{manual|inf}} , {{manual|eps}} , {{manual|sin}} , {{manual|cos}} , {{manual|tan}} , {{manual|exp}} , {{manual|log}} , {{manual|log10}} , {{manual|abs}} , {{manual|sqrt}} , {{manual|sign}} , {{manual|round}} , {{manual|ceil}} , {{manual|floor}} , {{manual|fix}} , <code>=</code> , <code>,</code> , <code>;</code> , {{manual|who}} , {{manual|clear}} , {{manual|help}} , {{manual|lookfor}}
| | <tt>== | > | < | >= | <= | != | | || | | & | && | ! | if | else | elseif | for | while |end | break | continue | pause</tt> |
| | | for i = 1:5 if (i < 3) disp (i) else disp (i^2) end end ↵ |
| <syntaxhighlight lang="octave">
| |
| x = pi, y = floor (sin (x)), z = log (exp (2013)), z / inf
| |
| </syntaxhighlight>
| |
| | |
| === Vectors and matrices ===
| |
| | |
| <code>:</code> , <code>.*</code> , <code>./</code> , <code>.^</code> , <code>'</code> , <code>.'</code> , <code>\</code> , {{manual|length}} , {{manual|numel}} , {{manual|size}} , {{manual|zeros}} , {{manual|ones}} , {{manual|eye}} , {{manual|diag}} , {{manual|rand}} , {{manual|det}} , {{manual|trace}} , {{manual|inv}} , {{manual|lu}} , {{manual|eig}} , {{manual|cond}} , {{manual|expm}}
| |
| | |
| <syntaxhighlight lang="octave">
| |
| x = 1:5, x(:), x(2:4), A = [11 12; 21, 22], A(1,1:end)
| |
| </syntaxhighlight>
| |
| | |
| === Graphics ===
| |
| | |
| {{manual|plot}} , {{manual|semilogx}} , {{manual|semilogy}} , {{manual|loglog}} , {{manual|contour}} , {{manual|quiver}} , {{manual|surf}} , {{manual|mesh}} , {{manual|meshgrid}} , {{manual|xlabel}} , {{manual|ylabel}} , {{manual|zlabel}} , {{manual|title}} , {{manual|grid}} , {{manual|axis}} , {{manual|hold}} , {{manual|subplot}} , {{manual|figure}} , {{manual|print}}
| |
| | |
| <syntaxhighlight lang="octave">
| |
| t = 0:0.01*pi:21*pi; x = sin (t).*(exp (cos (t)) - 2*cos (4*t) + sin (t/12).^5); y = cos (t).*(exp (cos (t)) - 2*cos (4*t) + sin (t/12).^5); plot(x, y)
| |
| </syntaxhighlight>
| |
| | |
| === Scripts and functions ===
| |
| | |
| <code>@</code> , <code>function</code> , <code>return</code> , {{manual|nargin}} , {{manual|nargout}} , {{manual|varargin}} , {{manual|varargout}} , {{manual|feval}} , {{manual|eval}}
| |
| | |
| <syntaxhighlight lang="octave">
| |
| f = @(x) x.^2, f(1:10)
| |
| | |
| function v = cossum (x, n) v = cumsum (repmat (cos (x), 1, n)); | |
| </syntaxhighlight>
| |
| | |
| === Programming elements ===
| |
| | |
| <code>==</code> , <code>></code> , <code><</code> , <code>>=</code> , <code><=</code> , <code>!=</code> , <code>|</code> , <code>||</code> , <code>&</code> , <code>&&</code> , <code>!</code> , <code>~</code> , <code>if</code> , <code>else</code> , <code>elseif</code> , <code>for</code> , <code>while</code> , <code>end</code> , <code>break</code> , <code>continue</code> , <code>pause</code> | |
| | |
| <syntaxhighlight lang="octave">
| |
| for i = 1:5 if (i < 3) disp (i) else disp (i^2) endif endfor | |
| </syntaxhighlight>
| |
| | |
| == See also ==
| |
| | |
| * [https://lists.gnu.org/archive/html/help-octave/2013-01/pdfoEurT8AZ7Z.pdf GNU OCTAVE CARD by Fotios Kasolis]
| |
| | |
| [[Category:Tutorials]]
| |