zoukankan      html  css  js  c++  java
  • Octave /Matlab--Control Statements:for,while, if statement----Coursera ML笔记

    >> v = zeros(10,1)
    v =
         0
         0
         0
         0
         0
         0
         0
         0
         0

         0

    >> for i=1:10;
             v(i) = 2^i;
          end;
    >> v
    v =
               2
               4
               8
              16
              32
              64
             128
             256
             512
            1024

    >> indices = 1:10;
    >> indices
    indices =

      Columns 1 through 9

         1     2     3     4     5     6     7     8     9

      Column 10

        10

    >> for i = indices,
           disp(i);
       end;
         1
         2
         3
         4
         5
         6
         7
         8
         9
        10

    >> v

    v =
               2
               4
               8
              16
              32
              64
             128
             256
             512
            1024


    >> i = 1;
    >> while i<=5,
            v(i) = 100
            i=i+1
        end;

    >> v

    v =
             100
             100
             100
             100
             100
              64
             128
             256
             512
            1024

    >> i = 1;
    >> while true,
        v(i) = 999;
        i = i+1
        if i == 6,
           break;
        end;
        end;

    >> v

    v =
             999
             999
             999
             999
             999
              64
             128
             256
             512
            1024

    >>if ****,

              ######;

         elseif ****,

             #######;

         else,

             ######;

         end;

    =============================================================

    拟合上图训练集合

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

    >>y = [1; 2; 3]

    >>theta = [0;1]

    function J = costFunctionJ(X, y, thera)

    % X is the "design matrix" containing our training examples,

    %y is the class labels

    m = size(X, 1)    %number of training examples

    predictions = X*thera;  % predictions of hypothesis on all m examples

    sqrErrors = (predictions - y).^2;

    J = 1/(2*m) *sum(sqrErrors);

  • 相关阅读:
    PowerShell2.0之Windows排错(六)检查网络故障
    确保数据安全是云计算取信于用户的关键
    企业发展如何借助“云的力量”
    PowerShell2.0之维护网络(三)设置网络适配器
    Feign最佳实践
    Nacos注册中心原理
    GateWay网关快速入门
    Nacos集群搭建
    Feign快速入门
    Feign的性能优化
  • 原文地址:https://www.cnblogs.com/judejie/p/9008921.html
Copyright © 2011-2022 走看看