• 沒有找到結果。

最小平方迴歸分析之程式應用

N/A
N/A
Protected

Academic year: 2021

Share "最小平方迴歸分析之程式應用"

Copied!
13
0
0

加載中.... (立即查看全文)

全文

(1)

最小平方迴歸分析之程式應用

Program application of least square regression analysis

作者:吳彬睿 系級:資訊一丙 學號:D0611061 開課老師:林佩君 課程名稱:線性代數 開課系所:資電學院 開課學年: 106 學年度 第 1 學期

(2)

逢甲大學學生報告 ePaper(2017 年)

目次

English Introduction、Keywords

……….……1

中文摘要、關鍵字

………2

介紹最小迴歸分析法則

………...………3

用MATLAB查找資料集的最小平方迴歸線

、(a)~(f)計算流程

…...4

(a)儲存兩個矩陣………...………..……...5

(b)運算A = (X^T*X)^-1*X^T*Y……….………...6

(c)將上題的答案比對用polyfit的答案………..………...7

(d)用MATLAB印出資料點圖………...8

(e)用MATLAB印出最小回歸線圖………...9

(f) 結合(d),(e)兩圖………...10

參考文獻

………..…11

(3)

1

逢甲大學學生報告 ePaper(2017 年)

Introduction

(1) Purpose:The article is mainly introducing program application of least square regression analysis.

(2)Process and Tool:

It is mainly explained in two parts:

a. Introduce the method of least squares regression. b. Use matlab to find the least squares regression line. The tool to use:

MATLAB。

(3)Resault:Make everyone know more method of least squares regression and also inrtroducing that use program to find the method of least squares regression is more fast.

Keywords

method of least squares regression、MATLAB (method of least squares regression)、least squares regression line.

(4)

2 逢甲大學學生報告 ePaper(2017 年)

中文摘要

(1) 目的:此篇主要介紹最小平方迴歸分析法則之程式應用。 (2)過程及方法: 主要以兩部分來說明: a.介紹最小迴歸分析法則。 b.最小平方迴歸分析在MATLAB上之應用。 使用方法: 數學運算工具MATLAB。 (3)結果:讓人更了解最小迴歸分析法則,同時也介紹MATLAB程式運算最小迴歸 分析法更快速精準。

關鍵字:

最小平方法、MATLAB 最小平方法運算、最小平方迴歸線

(5)

3 逢甲大學學生報告 ePaper(2017 年) A.介紹最小迴歸分析法則 對於給定的資料點(x1,y1),(x2,y2),(x3,y3),(x4,y4)……(xn,yn),計算f(xn)所得到的 值與yn實際的值之間的誤差,將差值平方加起來,可以得到一個誤差平方和。 線 性模型中最逼近的便是可以將誤差平方和最小化的模型,這個模形稱作最小平方 回歸線,而尋找的過程稱作最小平方法。 最小平方法 對於資料點,令線性方程式f(x)=a+bx 點(x1,y1), f(x1) = a+bx1, y1-f(x1)= y1-a+bx1 點(x2,y2), f(x2) = a+bx2, y2-f(x2) = y2-a+bx2… 點(xn,yn), f(xn) = a+bxn, yn-f(xn) = yn-a+bxn

每個方程式 [yn-f(xn)]項當作f(xn)逼近yn的誤差值其最小化模型S(a,b) S(a,b)=[y1-f(x1)] ^2+[y2-f(x2)]^2 …+[yn-f(xn)]^2

(1) 令S(a,b)對a微分=0, (2)令S(a,b)對b微分=0

(6)

4 逢甲大學學生報告 ePaper(2017 年) B.用MATLAB查找資料集 (1、1)、(2、2)、(3、4)、(4、4) 和 (5、6) 的最小平 方迴歸線

(a)~(f)解說流程圖:

(a)儲存兩個矩陣

(b)運算A = (X^T*X)^-1*X^T*Y

(c)將上題的答案比對用 polyfit 的答案

(d)用 MATLAB 印出資料點圖

(e)用MATLAB印出最小回歸線圖

(f) 結合(d),(e)兩圖

(7)

5 逢甲大學學生報告 ePaper(2017 年) (a) 儲存兩個矩陣 >> X = [1 1;1 2;1 3;1 4;1 5]; >> X X = 1 1 1 2 1 3 1 4 1 5 >> Y = [1;2;4;4;6]; >> Y Y = 1 2 4 4 6

(8)

6 逢甲大學學生報告 ePaper(2017 年) (b) 運算A = (X^T*X)^-1*X^T*Y >> X' ans = 1 1 1 1 1 1 2 3 4 5 >> X'*X ans = 5 15 15 55 >> X'*Y ans = 17 63 >> inv(X'*X) ans = 1.1000 -0.3000 -0.3000 0.1000 >> A = inv(X'*X)*X'*Y A = -0.2000 1.2000

(9)

7 逢甲大學學生報告 ePaper(2017 年) (c) 將上題的答案比對用 polyfit 的答案 A = -0.2000 1.2000 X1 = X(:,2) X1 = 1 2 3 4 5 >> polyfit(X1,Y,1) ans = 1.2000 -0.2000 結果一樣

(10)

8

逢甲大學學生報告 ePaper(2017 年) (d) 用 MATLAB 印出資料點圖

>> t = (0: 0.1: 6); >> plot(X1,Y,'+')

(11)

9 逢甲大學學生報告 ePaper(2017 年) (e) 用 MATLAB 印出最小回歸線圖 >> t = (0: 0.1: 6); >> p = polyfit(X1,Y,1); >> f = polyval(p,t); >> plot(t,f,'*')

(12)

10

逢甲大學學生報告 ePaper(2017 年) (f) 結合(d),(e)兩圖

(13)

11

逢甲大學學生報告 ePaper(2017 年)

參考文獻

Ron Larson(2016) ..線性代數【第八版】 (翁慶昌譯) (第 121-125 頁)。新北市:高立 圖書有限公司出版。

參考文獻

相關文件

Compute interface normal, using method such as Gradient or least squares of Youngs or Puckett Determine interface location by iterative bisection..

The main advantages of working with continuous designs are (i) the same method- ology can be essentially used to find continuous optimal designs for all design criteria and

More than 90% of the leaders reported that the Panel Chair was also expected to ensure that all teachers followed curriculum guidelines, and to review evidence of teaching

Curriculum planning: Teachers may introduce how to use short division to find the greatest common divisor and the least common multiple of two numbers at Learning Objective 1.4

Then, we recast the signal recovery problem as a smoothing penalized least squares optimization problem, and apply the nonlinear conjugate gradient method to solve the smoothing

Then, we recast the signal recovery problem as a smoothing penalized least squares optimization problem, and apply the nonlinear conjugate gradient method to solve the smoothing

Based on the reformulation, a semi-smooth Levenberg–Marquardt method was developed, and the superlinear (quadratic) rate of convergence was established under the strict

we often use least squares to get model parameters in a fitting problem... 7 Least