An internet service provider has given you the following data to consider:
Year 1999 2000 2001 2002 2003 2004 2005 2006
Customers
(in
millions)
76.4 78.6 81.5 87.8 88.4 92.4 94.0 95.0
Use MATLAB to plot the data and observe its trend. Find a liner function for the data and use
it to predict the number of customers the company will have in 2014.
Script
clc
clear all
close all
% set data
years = [1999 2000 2001 2002 2003 2004 2005 2006];
customers = [76.4 78.6 81.5 87.8 88.4 92.4 94.0 95.0];
%plot data
plot(years, customers, 'bo')
xlabel('Year');
ylabel('Customers (in millions)')
hold on
% find coefficients of the trend line
p = polyfit(years,customers,1);
% points to plot trend line
x_line = [years(1) years(end)];
y_line = polyval(p,x_line);
% plot trend line
plot(x_line,y_line, 'r-')
legend('Data points', 'Trend line')
% print predicted number of customers
fprintf('The number of customers the company will have in 2014 is %.1f millions.\n ',polyval(p,2014))
Output
The number of customers the company will have in 2014 is 119.7 millions.
Comments
Leave a comment