Finding Best T Line For Given Dataset in Octave: Shubham-AE18B041 September 30, 2019
Finding Best T Line For Given Dataset in Octave: Shubham-AE18B041 September 30, 2019
Octave
Shubham-AE18B041
1 Introduction
In this assignment we are trying to nd the best le line for the given dataset
using "Least square tting" method. We are given three datasets which
include co-ordinates of 200 points (x&y co-ordinates). The data is given in
.txt format.
2 Logic
The data we have is in .txt format. First we have to assign the values to
particular variables say x&y. The variable x will store x co-ordinates and y
will store y co-ordinates. Let m and c be the slope and y-intercept of the
best t ine which we have to nd. Then the equation y=mx+c for all 200
points can be written in matrix format as
y1 x1 1
y2 x2 1
m
.. = .. ..
. . . c
yn xn 1
yn xn 1
1
By doing above matrix multiplication we will get values of m&c
m slope
=
c y _intercept
3 Code
The octave code for performing the above operatins is given below
4 Result
The resultant graph for dierent datasets and dierent no. of points is shown
below.
2
Figure 1: Dataset-1 , no. of points-25
3
Figure 2: Dataset-1 , no. of points-75
4
Figure 3: Dataset-1 , no. of points-150
5
Figure 4: Dataset-2 , no. of points-25
6
Figure 5: Dataset-2 , no. of points-75
7
Figure 6: Dataset-2 , no. of points-150
8
Figure 7: Dataset-3 , no. of points-25
9
Figure 8: Dataset-3 , no. of points-75
10
Figure 9: Dataset-3 , no. of points-150
11
5 Inference
We can see that graphs plotted in python and octave are exactly same. For
datasets 2 & 3 our data set is nearly linear so we get a straight line where
each point is very close to the best t line. But for dataset 1 we can see that
the data is not linear. So some points are close to the best line whereas
some are away from the best t line.
12