吴恩达机器学习(第2周--Octave/Matlab Tutorial)

第2周--Basic Operations

>> 1 && 0
ans = 0
>> 1 || 0
ans = 1

>> xor(1,0)
ans = 1
>> PS('>> ');
error: 'PS' undefined near line 1 column 1
>> PS1('>> ');    %PS1() is a function that is used for Query or set the primary prompt string. 

>> PS1('>> ')
>> T = PS1('>>')
T = >>
>>clear
>>a = 3
a =  3
>>b = 'hi';
>>b
b = hi
>>c = (3>=1);
>>c
c = 1

>>a = pi;
>>a
a =  3.1416
>>disp(a);
 3.1416
>>disp(sprintf('2 decimals: %0.2f',a))    %Here to control its bits after the point are 2
2 decimals: 3.14
>>disp(sprintf('6 decimals: %0.6f',a))    %Here to control its bits after the point are 6
6 decimals: 3.141593

>>format long
>>a
a =  3.141592653589793
>>format short
>>a
a =  3.1416

接下来这部分是基本的一些矩阵相关

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

   1   2
   3   4
   5   6

>>A = [1 2;]
A =

   1   2

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

   1   2
   3   4
   5   6

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

   1   2   3

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

   1
   2
   3

>>V = 1:0.1:2
V =

 Columns 1 through 9:

    1.0000    1.1000    1.2000    1.3000    1.4000    1.5000    1.6000    1.7000    1.8000

 Columns 10 and 11:

    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 = 2 * ones(2,3)
C =

   2   2   2
   2   2   2

>>c = [2 2 2; 2 2 2]
c =

   2   2   2
   2   2   2

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

   1   1   1

>>w = zeros(1,3)
w =

   0   0   0

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

   0.56964   0.58711   0.16050

>>rand(3,3)
ans =

   0.31862   0.17487   0.89735
   0.33011   0.81878   0.42345
   0.61995   0.61151   0.66674

>>
>>rand(3,3)
ans =

   0.55248   0.41297   0.69621
   0.76598   0.86068   0.19670
   0.18062   0.59087   0.85608

>>w = randn(1,3)
w =

  -0.55813  -0.16527  -1.17928

>>
>>
>>
>>w = -6 + sqrt(10) * (randn(1,10000));
>>>w = -6 + sqrt(10) * (randn(1,10000))
parse error:

  syntax error

>>> >w = -6 + sqrt(10) * (randn(1,10000))
    ^

>>hist(w)
>>hist(w)
>>hist(w,50)
>>
>>
>>eye(4)
ans =

Diagonal Matrix

   1   0   0   0
   0   1   0   0
   0   0   1   0
   0   0   0   1

>>I = eye(4)
I =

Diagonal Matrix

   1   0   0   0
   0   1   0   0
   0   0   1   0
   0   0   0   1

>>I = eye(6)
I =

Diagonal Matrix

   1   0   0   0   0   0
   0   1   0   0   0   0
   0   0   1   0   0   0
   0   0   0   1   0   0
   0   0   0   0   1   0
   0   0   0   0   0   1

>>
>>
>>help

  For help with individual commands and functions type

    help NAME

  (replace NAME with the name of the command or function you would
  like to learn more about; for an operator, enclose "NAME" in quotes).

  For a more detailed introduction to GNU Octave, consult the manual.
  The manual may be read from the prompt by typing

    doc

  GNU Octave is supported and developed by its user community.
  For more information visit https://www.octave.org.

>>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")

     Calling 'eye' with no arguments is equivalent to calling it with an
     argument of 1.  Any negative dimensions are treated as zero.  These
     odd definitions are for compatibility with MATLAB.

     See also: speye, ones, zeros.

Additional help for built-in functions and operators is
available in the online version of the manual.  Use the command
'doc <topic>' to search the manual index.

Help and information about Octave is also available on the WWW
at https://www.octave.org and via the [email protected]
mailing list.



猜你喜欢

转载自blog.csdn.net/garrulousabyss/article/details/80716504
今日推荐