Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

Concepts of Geodesy and Geodetic Methods

Winter Semester 2017/2018


Matriculation Number:10014152
Exercise 4: Modeling with Polynomials

1.0 Introduction
In this exercise we were asked to fit a polynomial of degree n (where n is an
appropriate degree) to the given time series. The time series gives the air
temperature for 30days of November 2017 for a mountain station in south
Germany.
The given instructions in the exercise were followed in order to complete the
task.
2.0 Task 1
In the first task we were required to use the Matlab file “ Data4Polyfit.mat and
load it in MATLAB. We considered the data file with two variables “t” and
“Y”. The data collected was for 30 days with a sampling rate of 30 minutes .
In the first task after following the instructions a polynomial of degree 4 with
estimated corresponding coefficients resulted in the figure below.

The unit of the time value considered was in minutes.

Charles Atakora 10014152


Figure 1: plot of given data with polynomial of degree 4 and estimated
corresponding coefficient

3.0 Task 2

Degree RMSE
2 3.31192194278123e-15 + 0.00000000000000i
3 0.00000000000000 + 1.39978092124609e-21i
4 1.09941198885324e-29 + 0.00000000000000i
5 5.04975390864909e-35 + 0.00000000000000i
6 9.01067731909221e-41 + 0.00000000000000i

The degree with the least RMSE was n=6

Charles Atakora 10014152


4.0 Task 3
The prediction of the air temperature on 1st of December 2017 at
Time Temperature
06:00
12:00
18:00
23:00

5.0 Task 4

6.0 Task 5

The noise level in the data could be estimated by looking at the frequency and
shape of the oscillation. In this case it is coloured noise because the oscillation
is not flat.

Refernces

Dr.Ing.Majid Naeimi (Institute for Erdmessung): Concept of Geodetic methods,


winter semester (2017/2018). Leibnis Universitat Hannover.

Source code:
clc;
clear;
close all;

Charles Atakora 10014152


format long

%%Task 1
load Data4Polyfit.mat % to load the data

t_1 = t/30;
y_1 = Y;

figure(1);
plot(t_1,y_1);
grid on
title('Plot of Air temperature in 30days');
xlabel('time(minutes)'); %Defining t axis
ylabel('Temperature(degrees celcius)'); %Defining y axis
hold on
A = [ones(size(t)) t t.^2 t.^3 t.^4]; %design matrix

x = (A'*A)\(A'*y_1);%coefficients x using least square adjustment

y_c = A*x;

plot(t_1,y_c,'y'); %image with line with best line of fit from degree (n)=4

%%Task 2
a=rand(1439,1); % generate random data
[TRS]= intersect(a,randsample(a,1150)); % gives training set with 80%
random samples from a you can set what size your trainign set needs to be
TS=a(~ismember(a,TRS)); % gives test set

%n=2
A1 = [ones(size(TRS)) TRS TRS.^2 ]; %design matrix

x1 = (A1'*A1)\(A1'*TRS);%coefficients x using least square adjustment

y_c1 = A1*x1;%computed y values

RMS1=sqrt(sum([TRS-y_c1]).^2/289);

%n=3
A2 = [ones(size(TRS)) TRS TRS.^2 TRS.^3 ]; %design matrix

x2 = (A2'*A2)\(A2'*TRS);%coefficients x using least square adjustment

y_c2 = A2*x2;%computed y values

RMS2=sqrt(sum([TRS-y_c2]).^3/289);

%n=4
A3 = [ones(size(TRS)) TRS TRS.^2 TRS.^3 TRS.^4 ]; %design matrix

x3 = (A3'*A3)\(A3'*TRS);%coefficients x using least square adjustment

y_c3 = A3*x3;%computed y values

Charles Atakora 10014152


RMS3=sqrt(sum([TRS-y_c3]).^4/289);

%n=5
A4 = [ones(size(TRS)) TRS TRS.^2 TRS.^3 TRS.^4 TRS.^5 ]; %design matrix

x4 = (A4'*A4)\(A4'*TRS);%coefficients x using least square adjustment

y_c4 = A4*x4;%computed y values

RMS4=sqrt(sum([TRS-y_c4]).^5/289);

%n=6
A5 = [ones(size(TRS)) TRS TRS.^2 TRS.^3 TRS.^4 TRS.^5 TRS.^6 ]; %design
matrix

x5 = (A5'*A5)\(A5'*TRS);%coefficients x using least square adjustment

y_c5 = A5*x5;%computed y values

RMS5=sqrt(sum([TRS-y_c5]).^6/289);

R=[RMS1;RMS2; RMS3; RMS4; RMS5]


S=[2 3 4 5 6]
figure (2)
plot(S,R)
%
%
figure(3)
plot(t_1,y_1,'m')
hold on
plot(t_1,y_c,'b')

Charles Atakora 10014152

You might also like