공학수학 | 최소제곱선(least-squares line) |
페이지 정보
작성자 cemtool 작성일14-06-16 16:34 조회8,523회 댓글0건본문
다음과 같이 주어진 데이터 점들에 대한 최소제곱선을 구하여라.
ex7_2.cem
/* Example 7.2 CEMTool least squares */ // Least-squares curve fit with a line using \ operator and polyfit. // The results are displayed and plotted. x=[0 1 2 3 5]; // Define the data points y=[0 1.4 2.2 3.5 4.4]; A1=[1 1 1 1 1 ]'; // Least squares matrix A=[A1 x']; Als=A'*A; bls=A'*y'; // Compute least squares fit Xlsq1=Als\bls Xlsq2=polyfit(x,y,1)f1=polyval(Xlsq2,x); error=y-f1; msgprint(" ")msgprint(" x y f1 y-f1")[x' y' f1' error'] // Plotplot(x,y,"o",x,f1,"-")title("Least Squares line Figure")xtitle("x")ytitle("y")
따라서, 주어진 데이터 점들에 대한 최소제곱선은 다음과 같다.
CEMTool 의 역슬래시 연산자나 polyfit 함수는 같은 계수값을 구하지만, 역슬래시 연산자의 경우에는 오름차순으로, polyfit 함수는 내림차순으로 결과를 출력함에 주목하여라. 각 데이점 점들에서의 오차는 열에 나타내었다. 여기서 오차는 주어진 축 값과 최소제곱선으로 구한 함수값 사이의 수직 거리이다. 최고제곱 오차(least-squares error)는 이 값들을 제곱한 후에 모두 더하면 된다.
댓글목록
등록된 댓글이 없습니다.