【斯坦福大学-机器学习】5.Octave教程

来源:互联网 发布:html5网页制作软件 编辑:程序博客网 时间:2024/06/05 03:24

5.1 基本操作

>> a='hello world!';>> aa = hello world!

基本运算:

>> 5+6ans =  11>> 3-2ans =  1>> 5*8ans =  40>> 1/2ans =  0.50000>> 2^6ans =  64>> 1==2ans = 0>> 1~=2ans = 1>> 1||0 % orans = 1>> 1&&0 % andans = 0>> 10>xor(1,0)ans = 1>> xor(1,0)  % 异或ans = 1

格式:

>> d=pi;>> dd =  3.1416>> disp(d); 3.1416>> disp(sprintf('2 decimals:%0.2f',d))2 decimals:3.14>> format long>> dd =  3.14159265358979>> format short>> dd =  3.1416

矩阵:

>> A = [1,2;3,4]A =   1   2   3   4>> v=[1,2,3]v =   1   2   3>> v=1:6v =   1   2   3   4   5   6>>>> v=1:0.5:6v = Columns 1 through 8:    1.0000    1.5000    2.0000    2.5000    3.0000    3.5000    4.0000    4.5000 Columns 9 through 11:    5.0000    5.5000    6.0000>> ones(2,3)ans =   1   1   1   1   1   1>> zeros(3,2)ans =   0   0   0   0   0   0>> f = 3*ones(3,3)f =   3   3   3   3   3   3   3   3   3>> f = 3*ones(3,3)f =   3   3   3   3   3   3   3   3   3>> rand(3,3)ans =   0.909508   0.835294   0.630493   0.785196   0.989619   0.587810   0.081212   0.132675   0.302757>> w=randn(1,3)w =  -0.085923  -0.971393  -1.802269>> 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
>> w=-6+sqrt(10)*(randn(1,10000));ᔀ>> hist(w)

这里写图片描述

0 0