>> help diary
`diary' is a built-in function
-- Command: diary options
Record a list of all commands _and_ the output they produce, mixed
together just as you see them on your terminal. Valid options are:
`on'
Start recording your session in a file called `diary' in your
current working directory.
`off'
Stop recording your session in the diary file.
`FILE'
Record your session in the file named FILE.
With no arguments, `diary' toggles the current diary state.
Additional help for built-in functions and operators is
available in the on-line version of the manual. Use the command
`doc ' to search the manual index.
Help and information about Octave is also available on the WWW
at http://www.octave.org and via the help@octave.org
mailing list.
>>
>> b = [1; 2; 3]
b =
1
2
3
>> % b above is a column vector
>> % this is a comment
>> c = [5 4 2 1]
c =
5 4 2 1
>> c = [5 4 -2 1]
c =
5 4 -2 1
>> c = [5 4 - 2 1]
c =
5 2 1
>> c = [5 4 2 1]
c =
5 4 2 1
>> c = [5 4 -2 1]
c =
5 4 -2 1
>> c = [5 4 - 2 1]
c =
5 2 1
>> c = [5, 4 - 2, 1]
c =
5 2 1
>> c = [5, - 2, 1]
c =
5 -2 1
>> A = [7 5 3; 1 -1 0; pi 8 11]
A =
1.0e+01 *
0.70000 0.50000 0.30000
0.10000 -0.10000 0.00000
0.31416 0.80000 1.10000
>> format short g
>> A = [7 5 3; 1 -1 0; pi 8 11]
A =
7 5 3
1 -1 0
3.1416 8 11
>> pi
ans = 3.1416
>> format long
>> pi
ans = 3.14159265358979
>> format e
error: format: unrecognized format state `e'
>> format long e
>> pi
ans = 3.14159265358979e+00
>> format short
>> A
A =
1.0e+01 *
0.70000 0.50000 0.30000
0.10000 -0.10000 0.00000
0.31416 0.80000 1.10000
>> format short g
>> A
A =
7 5 3
1 -1 0
3.1416 8 11
>> b
b =
1
2
3
>> c
c =
5 -2 1
>> A * b
ans =
26
-1
52.142
>> A*c
error: operator *: nonconformant arguments (op1 is 3x3, op2 is 1x3)
>> A \ b % solves the system A v = b
ans =
0.64925
-1.3507
1.0697
>> A, b
A =
7 5 3
1 -1 0
3.1416 8 11
b =
1
2
3
>> b' % transpose
ans =
1 2 3
>> A'
ans =
7 1 3.1416
5 -1 8
3 0 11
>> inv(A)
ans =
0.11159 0.31448 -0.030434
0.11159 -0.68552 -0.030434
-0.11303 0.40874 0.12173
>> eig(A)
ans =
-1.4011
5.4199
12.981
>> [X,D]=eig(A)
X =
0.33236 -0.78026 0.47041
-0.82867 -0.12154 0.033646
0.45038 0.61353 0.8818
D =
Diagonal Matrix
-1.4011 0 0
0 5.4199 0
0 0 12.981
>> det(A)
ans = -98.575
>> b
b =
1
2
3
>> c
c =
5 -2 1
>> det(A)
ans = -98.575
>>
>>
>>
>> w = [8 9 2]
w =
8 9 2
>> c
c =
5 -2 1
>> c + w
ans =
13 7 3
>> c * w
error: operator *: nonconformant arguments (op1 is 1x3, op2 is 1x3)
>> w'
ans =
8
9
2
>> c * w'
ans = 24
>> c
c =
5 -2 1
>> w
w =
8 9 2
>> c .* w % entrywise multiplication
ans =
40 -18 2
>> % plotting and graphics
>> t = 1990 : 1/12 : 2012;
>> size(t)
ans =
1 265
>> length(t)
ans = 265
>> y = exp(- (1/5) * (t - 1990));
>> plot(t,y)
>> plot(t,y,'o')
>> plot(t,y,'o','markersize',12))
parse error:
syntax error
>>> plot(t,y,'o','markersize',12))
^
>> plot(t,y,'o','markersize',12)
>> t = 1990 : 1/2 : 2012;
>> y = exp(- (1/5) * (t - 1990));
>> plot(t,y,'o','markersize',12)
>> plot(t,y,'d','markersize',12)
>> plot(t,y,'d','markersize',24)
>> plot(t,y,'gd','markersize',24)
>> plot(t,y,'rs','markersize',24)
>> axis tight
>> xlabel('t (years)')
>> ylabel('some numbers')
>> hold on
>> plot(t,sin(t))
>> hold off
>>
>>
>> text(0.5,2000,'some text')
>> text(2000,0.5,'some text')
>>
>>
>> whos
Variables in the current scope:
Attr Name Size Bytes Class
==== ==== ==== ===== =====
A 3x3 72 double
D 3x3 24 double
X 3x3 72 double
ans 1x1 8 double
b 3x1 24 double
c 1x3 24 double
t 1x45 24 double
w 1x3 24 double
y 1x45 360 double
Total is 127 elements using 632 bytes
>> clear all
>> whos
>> close all
>>
>>
>> x = 0:pi/100:3*pi;
>>
>> subplot(311,x,sin(x))
error: subplot: columns, and rows must be scalars
error: called from:
error: /usr/share/octave/3.2.4/m/plot/subplot.m at line 84, column 5
>> subplot(311), plot(x,sin(x))
>> subplot(312), plot(x,cos(x))
>> subplot(313), plot(x,sin(5*x))
>>
>>
>> % help and file system
>>
>> help sin
`sin' is a built-in function
-- Mapping Function: sin (X)
Compute the sine for each element of X in radians.
See also: asin, sind, sinh
Additional help for built-in functions and operators is
available in the on-line version of the manual. Use the command
`doc ' to search the manual index.
Help and information about Octave is also available on the WWW
at http://www.octave.org and via the help@octave.org
mailing list.
>> help plot
`plot' is a function from the file /usr/share/octave/3.2.4/m/plot/plot.m
-- Function File: plot (Y)
-- Function File: plot (X, Y)
-- Function File: plot (X, Y, PROPERTY, VALUE, ...)
-- Function File: plot (X, Y, FMT)
-- Function File: plot (H, ...)
Produces two-dimensional plots. Many different combinations of
arguments are possible. The simplest form is
plot (Y)
where the argument is taken as the set of Y coordinates and the X
coordinates are taken to be the indices of the elements, starting
with 1.
To save a plot, in one of several image formats such as PostScript
or PNG, use the `print' command.
If more than one argument is given, they are interpreted as
plot (Y, PROPERTY, VALUE, ...)
or
plot (X, Y, PROPERTY, VALUE, ...)
or
plot (X, Y, FMT, ...)
and so on. Any number of argument sets may appear. The X and Y
values are interpreted as follows:
* If a single data argument is supplied, it is taken as the set
of Y coordinates and the X coordinates are taken to be the
indices of the elements, starting with 1.
* If the X is a vector and Y is a matrix, then the columns (or
rows) of Y are plotted versus X. (using whichever
combination matches, with columns tried first.)
* If the X is a matrix and Y is a vector, Y is plotted versus
the columns (or rows) of X. (using whichever combination
matches, with columns tried first.)
* If both arguments are vectors, the elements of Y are plotted
versus the elements of X.
* If both arguments are matrices, the columns of Y are plotted
versus the columns of X. In this case, both matrices must
have the same number of rows and columns and no attempt is
made to transpose the arguments to make the number of rows
match.
If both arguments are scalars, a single point is plotted.
Multiple property-value pairs may be specified, but they must
appear in pairs. These arguments are applied to the lines drawn by
`plot'.
If the FMT argument is supplied, it is interpreted as follows. If
FMT is missing, the default gnuplot line style is assumed.
`-'
Set lines plot style (default).
`.'
Set dots plot style.
`N'
Interpreted as the plot color if N is an integer in the range
1 to 6.
`NM'
If NM is a two digit integer and M is an integer in the range
1 to 6, M is interpreted as the point style. This is only
valid in combination with the `@' or `-@' specifiers.
`C'
If C is one of `"k"' (black), `"r"' (red), `"g"' (green),
`"b"' (blue), `"m"' (magenta), `"c"' (cyan), or `"w"'
(white), it is interpreted as the line plot color.
`";title;"'
Here `"title"' is the label for the key.
`+'
`*'
`o'
`x'
`^'
Used in combination with the points or linespoints styles,
set the point style.
The FMT argument may also be used to assign key titles. To do so,
include the desired title between semi-colons after the formatting
sequence described above, e.g., "+3;Key Title;" Note that the last
semi-colon is required and will generate an error if it is left
out.
Here are some plot examples:
plot (x, y, "@12", x, y2, x, y3, "4", x, y4, "+")
This command will plot `y' with points of type 2 (displayed as
`+') and color 1 (red), `y2' with lines, `y3' with lines of color
4 (magenta) and `y4' with points displayed as `+'.
plot (b, "*", "markersize", 3)
This command will plot the data in the variable `b', with points
displayed as `*' with a marker size of 3.
t = 0:0.1:6.3;
plot (t, cos(t), "-;cos(t);", t, sin(t), "+3;sin(t);");
This will plot the cosine and sine functions and label them
accordingly in the key.
If the first argument is an axis handle, then plot into these axes,
rather than the current axis handle returned by `gca'.
See also: semilogx, semilogy, loglog, polar, mesh, contour, bar,
stairs, errorbar, xlabel, ylabel, title, print
Additional help for built-in functions and operators is
available in the on-line version of the manual. Use the command
`doc ' to search the manual index.
Help and information about Octave is also available on the WWW
at http://www.octave.org and via the help@octave.org
mailing list.
>> close all
>>
>> ls
>>
>> pwd
ans = /home/bueler
>>
>> cd Desktop/
>> ls
>> % note: ls pwd cd are inherited into Matlab from Unix
>>
>> path
Octave's search path contains the following directories:
.
/usr/local/share/octave/site-m
/usr/lib/octave/3.2.4/oct/x86_64-pc-linux-gnu
/usr/share/octave/3.2.4/m
/usr/share/octave/3.2.4/m/plot
/usr/share/octave/3.2.4/m/pkg
/usr/share/octave/3.2.4/m/miscellaneous
/usr/share/octave/3.2.4/m/deprecated
/usr/share/octave/3.2.4/m/statistics
/usr/share/octave/3.2.4/m/statistics/base
/usr/share/octave/3.2.4/m/statistics/tests
/usr/share/octave/3.2.4/m/statistics/distributions
/usr/share/octave/3.2.4/m/statistics/models
/usr/share/octave/3.2.4/m/set
/usr/share/octave/3.2.4/m/general
/usr/share/octave/3.2.4/m/path
/usr/share/octave/3.2.4/m/sparse
/usr/share/octave/3.2.4/m/time
/usr/share/octave/3.2.4/m/audio
/usr/share/octave/3.2.4/m/signal
/usr/share/octave/3.2.4/m/polynomial
/usr/share/octave/3.2.4/m/help
/usr/share/octave/3.2.4/m/special-matrix
/usr/share/octave/3.2.4/m/optimization
/usr/share/octave/3.2.4/m/geometry
/usr/share/octave/3.2.4/m/testfun
/usr/share/octave/3.2.4/m/startup
/usr/share/octave/3.2.4/m/specfun
/usr/share/octave/3.2.4/m/io
/usr/share/octave/3.2.4/m/strings
/usr/share/octave/3.2.4/m/elfun
/usr/share/octave/3.2.4/m/image
/usr/share/octave/3.2.4/m/linear-algebra
>> mytest
error: `mytest' undefined near line 87 column 1
>> pwd
ans = /home/bueler/Desktop
>> mytest
ans = 9
>> help mytest
`mytest' is a script from the file /home/bueler/Desktop/mytest.m
MYTEST this is a test
Additional help for built-in functions and operators is
available in the on-line version of the manual. Use the command
`doc ' to search the manual index.
Help and information about Octave is also available on the WWW
at http://www.octave.org and via the help@octave.org
mailing list.
>> help mytest
`mytest' is a script from the file /home/bueler/Desktop/mytest.m
MYTEST this is a test
Example: to run this type
>> mytest
Additional help for built-in functions and operators is
available in the on-line version of the manual. Use the command
`doc ' to search the manual index.
Help and information about Octave is also available on the WWW
at http://www.octave.org and via the help@octave.org
mailing list.
>> mytest
ans = 9
>> testforig
error: `testforig' undefined near line 92 column 1
>> testforif
ans = 1
ans = 2
ans = 6
ans = 24
ans = 120
ans = 720
ans = 5040
ans = 40320
ans = 3.6288e+05
ans = 3.6288e+06
ans = 3.9917e+07
ans = 4.79e+08
ans = 6.227e+09
ans = 8.7178e+10
ans = 1.3077e+12
ans = 2.0923e+13
ans = 3.5569e+14
ans = 6.4024e+15
ans = 1.2165e+17
ans = 2.4329e+18
>> testforif
ans = 1
ans = 2
ans = 6
ans = 24
ans = 120
ans = 720
>> testforif
ans = 1
ans = 2
ans = 6
ans = 24
ans = 120
ans = 720
>> 1:6
ans =
1 2 3 4 5 6
>> testforif
ans = 720
ans = 120
ans = 24
ans = 6
ans = 2
ans = 1
>> 6:-1:1
ans =
6 5 4 3 2 1
>> 6:-1:1
ans =
6 5 4 3 2 1
>> testforif
ans = 1
ans = 6
ans = 120
ans = 5040
ans = 3.6288e+05
ans = 3.9917e+07
ans = 6.227e+09
ans = 1.3077e+12
ans = 3.5569e+14
ans = 1.2165e+17
ans = 5.1091e+19
>> testforif
ans = 1
ans = 2
ans = 6
ans = 24
ans = 120
ans = 720
ans = 5040
ans = 40320
ans = 3.6288e+05
ans = 3.6288e+06
ans = 3.9917e+07
ans = 4.79e+08
ans = 6.227e+09
ans = 8.7178e+10
ans = 1.3077e+12
ans = 2.0923e+13
ans = 3.5569e+14
ans = 6.4024e+15
ans = 1.2165e+17
ans = 2.4329e+18
i = 3
i = 6
i = 9
i = 12
i = 15
i = 18
>> 4
ans = 4
>> testforif
ans = 1
ans = 2
ans = 6
ans = 24
ans = 120
ans = 720
ans = 5040
ans = 40320
ans = 3.6288e+05
ans = 3.6288e+06
ans = 3.9917e+07
ans = 4.79e+08
ans = 6.227e+09
ans = 8.7178e+10
ans = 1.3077e+12
ans = 2.0923e+13
ans = 3.5569e+14
ans = 6.4024e+15
ans = 1.2165e+17
ans = 2.4329e+18
3 is divisible by 3
6 is divisible by 3
9 is divisible by 3
12 is divisible by 3
15 is divisible by 3
18 is divisible by 3
>> s = 7
s = 7
>> s = s + 7
s = 14
>> s == 7 % is s equal to 7
ans = 0
>> s == 14 % is s equal to 7
ans = 1
>> s == 14 % is s equal to 14
ans = 1
>> testforif
ans = 1
ans = 2
ans = 6
ans = 24
ans = 120
ans = 720
ans = 5040
ans = 40320
ans = 3.6288e+05
ans = 3.6288e+06
ans = 3.9917e+07
ans = 4.79e+08
ans = 6.227e+09
ans = 8.7178e+10
ans = 1.3077e+12
ans = 2.0923e+13
ans = 3.5569e+14
ans = 6.4024e+15
ans = 1.2165e+17
ans = 2.4329e+18
3 is divisible by 3
6 is divisible by 3
9 is divisible by 3
12 is divisible by 3
15 is divisible by 3
18 is divisible by 3
2 is not divisible by 3
5 is not divisible by 3
8 is not divisible by 3
11 is not divisible by 3
14 is not divisible by 3
17 is not divisible by 3
20 is not divisible by 3
>> testforif
ans = 1
ans = 2
ans = 6
ans = 24
ans = 120
ans = 720
ans = 5040
ans = 40320
ans = 3.6288e+05
ans = 3.6288e+06
ans = 3.9917e+07
ans = 4.79e+08
ans = 6.227e+09
ans = 8.7178e+10
ans = 1.3077e+12
ans = 2.0923e+13
ans = 3.5569e+14
ans = 6.4024e+15
ans = 1.2165e+17
ans = 2.4329e+18
3 is divisible by 3
6 is divisible by 3
9 is divisible by 3
12 is divisible by 3
15 is divisible by 3
18 is divisible by 3
1 is not divisible by 3
2 is not divisible by 3
4 is not divisible by 3
5 is not divisible by 3
7 is not divisible by 3
8 is not divisible by 3
10 is not divisible by 3
11 is not divisible by 3
13 is not divisible by 3
14 is not divisible by 3
16 is not divisible by 3
17 is not divisible by 3
19 is not divisible by 3
20 is not divisible by 3
>>
>>
>> fprintf('just a string')
just a string>>
>>
>> fprintf('just a string\n')
just a string
>> fprintf('a formatted number is x = %8.4f\n',pi)
a formatted number is x = 3.1416
>> fprintf('a formatted number is y = %8.4f\n',e)
a formatted number is y = 2.7183
>> fprintf('a formatted number is w = %8.4f\n',37)
a formatted number is w = 37.0000
>> for i = 1:10, fprintf('%2d! = %g\n',i,factorial(i)), end
1! = 1
2! = 2
3! = 6
4! = 24
5! = 120
6! = 720
7! = 5040
8! = 40320
9! = 362880
10! = 3.6288e+06
>>
>>
>> % final topic: save a function
>>
>> f = @(x) x + sin(x)
f =
@(x) x + sin (x)
>> sin(pi)
ans = 1.2246e-16
>> f(pi)
ans = 3.1416
>> x = 0:.01:10;
>> plot(x,f(x))
>> quad(f,0,2)
ans = 3.4161
>> diary off