Octave教程一:基本操作

Octave教程一:基本操作

我使用的是Octave4.2.0版本,运行命令行程序。

代码块

标准octave代码:

GNU Octave, version 4.2.1
Copyright (C) 2017 John W. Eaton and others.
This is free software; see the source code for copying conditions.
There is ABSOLUTELY NO WARRANTY; not even for MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.  For details, type 'warranty'.

Octave was configured for "x86_64-w64-mingw32".

Additional information about Octave is available at http://www.octave.org.

Please contribute if you find this software useful.
For more information, visit http://www.octave.org/get-involved.html

Read http://www.octave.org/bugs.html to learn how to submit bug reports.
For information about changes from previous versions, type 'news'.

octave:1> 5+6
ans =  11
octave:2> 2 ^3
ans =  8
octave:3> 1 == 2   %false
ans = 0
octave:4> 1 ~= 2
ans = 1
octave:5> 1 && 0
ans = 0
octave:6> 1 && 4
ans = 1
octave:7> 1 || 0
ans = 1
octave:8> xor (1,0)
ans = 1
octave:9> PS1('>> ');
>>
>>
>> a = 3
a =  3
>> a = 3;
>> a
a =  3
>> b = 'hello';
>> b
b = hello
>> c = (4>=2);
>> c
c = 1
>>
>> a = pi;
>> a
a =  3.1416
>> disp(a);
 3.1416
>> disp(sprintf('2 decimals: %0.2f',a))
2 decimals: 3.14
>> disp(sprintf('2 decimals: %0.6f',a))
2 decimals: 3.141593
>> a
a =  3.1416
>> format long
>> a
a =  3.14159265358979
>> format short
>> a
a =  3.1416
>>
>>
>> A = [1 2;3 4;5 6]
A =

   1   2
   3   4
   5   6

>> A = [1 2;
> 3 4;
> 5 6];
>> A
A =

   1   2
   3   4
   5   6

>>
>> V = [1 2 3];
>> V
V =

   1   2   3

>>
>> V = [1;2;3];
>> V
V =

   1
   2
   3

>> V = 1:0.1:2
V =

    1.0000    1.1000    1.2000    1.3000    1.4000    1.5000    1.6000    1.7000    1.8000    1.9000    2.0000

>>
>> V = 1:6
V =

   1   2   3   4   5   6

>> ones(2,3)
ans =

   1   1   1
   1   1   1

>> C = 3 * ones(3,4)
C =

   3   3   3   3
   3   3   3   3
   3   3   3   3

>>
>> W = zeros(3,1);
>> W
W =

   0
   0
   0

>> W = rand(1,3)
W =

   0.45620   0.29536   0.28382

>> w = RANDN(3,4)
error: 'RANDN' undefined near line 1 column 5

randn:一个平均值为0,方差(标准差)为1的高斯分布

>> W = randn(3,4)
W =

   0.79815  -1.76728  -1.07488   0.35646
  -0.10639  -1.47903  -0.17667   1.17329
  -0.23062   0.18124   0.24532  -1.96324

>> #W = -6 + sqrt(10) * randn(1,10000)
>> #W = -6 + sqrt(10) * randn(1,10000)
>> #W = -6 + sqrt(10) * randn(1,10000)
>>
>> W = -6 + sqrt(10) * (randn(1,10000))
W =

 Columns 1 through 10:

  -7.4149e+000  -4.0478e+000  -6.4079e+000  -6.2431e+000  -7.2215e+000  -4.7352e+000  -1.4453e+001  -1.0774e+001  -8.8522e+000  -6.3777e+000

 Columns 11 through 20:

  -8.2513e+000  -5.3611e+000  -8.8823e+000  -1.2411e+001  -6.2453e-001  -5.8827e+000  -6.8437e+000  -2.4605e-001  -5.0277e+000  -9.2317e+000

 Columns 21 through 30:

  -1.0805e+001  -7.3521e+000  -1.4258e+000  -2.2598e+000  -1.2282e+001  -7.9032e+000  -2.4224e+000  -6.3601e+000  -2.7460e+000  -9.4598e+000

 Columns 31 through 40:

  -4.4481e-001  -3.1196e+000  -5.2478e+000  -8.6788e+000  -1.2110e+001  -7.5298e+000  -1.0518e+001  -2.1805e+000  -3.6926e+000  -6.9485e+000

 Columns 41 through 50:

  -1.3113e+001  -1.0300e+001  -1.0826e+001  -1.1810e+001  -2.3933e+000  -3.8893e+000  -7.7049e+000  -1.3171e+001  -7.5713e+000  -5.2680e+000

 Columns 51 through 60:

  -4.7795e+000  -5.4704e+000  -5.8448e+000  -5.0637e+000  -1.0264e+001  1.1441e-001  -5.1185e+000  -3.2941e+000  -1.4436e+001  -3.5048e+000

 Columns 61 through 70:

  -4.2454e+000  -8.1833e+000  -7.9504e+000  -6.4092e+000  -7.5682e+000  -7.5733e+000  -9.7049e-001  -4.2588e+000  -6.3171e+000  -7.6455e+000
W =

 Columns 1 through 10:

  -7.4149e+000  -4.0478e+000  -6.4079e+000  -6.2431e+000  -7.2215e+000  -4.7352e+000  -1.4453e+001  -1.0774e+001  -8.8522e+000  -6.37
77e+000

 Columns 11 through 20:

  -8.2513e+000  -5.3611e+000  -8.8823e+000  -1.2411e+001  -6.2453e-001  -5.8827e+000  -6.8437e+000  -2.4605e-001  -5.0277e+000  -9.23
17e+000

 Columns 21 through 30:

  -1.0805e+001  -7.3521e+000  -1.4258e+000  -2.2598e+000  -1.2282e+001  -7.9032e+000  -2.4224e+000  -6.3601e+000  -2.7460e+000  -9.45
98e+000

 Columns 31 through 40:

  -4.4481e-001  -3.1196e+000  -5.2478e+000  -8.6788e+000  -1.2110e+001  -7.5298e+000  -1.0518e+001  -2.1805e+000  -3.6926e+000  -6.94
85e+000

 Columns 41 through 50:

  -1.3113e+001  -1.0300e+001  -1.0826e+001  -1.1810e+001  -2.3933e+000  -3.8893e+000  -7.7049e+000  -1.3171e+001  -7.5713e+000  -5.26
80e+000

 Columns 51 through 60:

  -4.7795e+000  -5.4704e+000  -5.8448e+000  -5.0637e+000  -1.0264e+001  1.1441e-001  -5.1185e+000  -3.2941e+000  -1.4436e+001  -3.504
8e+000

 Columns 61 through 70:
>>
>>
>>
>> hist(W)

Octave教程一:基本操作_第1张图片

>> hist(W,50)

Octave教程一:基本操作_第2张图片

>>
>>
>> eye(3)
ans =

Diagonal Matrix

   1   0   0
   0   1   0
   0   0   1

>> help eye
'eye' is a built-in function from the file libinterp/corefcn/data.cc

 -- eye (N)
 -- eye (M, N)
 -- eye ([M N])
 -- eye (..., CLASS)
     Return an identity matrix.

     If invoked with a single scalar argument N, return a square NxN
     identity matrix.

     If supplied two scalar arguments (M, N), 'eye' takes them to be the
     number of rows and columns.  If given a vector with two elements,
     'eye' uses the values of the elements as the number of rows and
     columns, respectively.  For example:

          eye (3)
           =>  1  0  0
               0  1  0
               0  0  1

     The following expressions all produce the same result:

          eye (2)
          ==
          eye (2, 2)
          ==
          eye (size ([1, 2; 3, 4]))

     The optional argument CLASS, allows 'eye' to return an array of the
     specified type, like

          val = zeros (n,m, "uint8")
>>
>>
>>

你可能感兴趣的:(机器学习)