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

  • 相关阅读:
    链路的有效性检测 及 基于TCP的通信为什么需要RETRY
    python join
    协程
    python socket 选项
    Spring @Resource、@Autowired、@Qualifier的区别
    maven插件
    代码中的特殊注释
    AOP 底层技术比较
    关于Android开发中的证书和密钥等问题
    tomcat部署web项目的3中方法
  • 原文地址:https://www.cnblogs.com/judejie/p/9008921.html
Copyright © 2011-2022 走看看