In: Mechanical Engineering
(Using Matlab)We are given data about a charity organization in table 1 Days 10 20 30 40 50 60 70 80 90 100 Donation 23 45 60 82 111 140 167 198 200 220 Table 1: Donation collection by the charity organization Assume that x corresponds to the independent variable. Compute linear, quadratic and cubic fit for the data using regression techniques and plot them on three different graphs, all on the same figure. Use an appropriate small interval to create your plots. Mark the original data with green circles. Give appropriate titles and labels for the graph. Explain in few sentences which model best represents the data and why? Now, use the best model to find the value of the donation collection for 25th day. Print this value.
MATLAB CODE
clc
clear all
d=[10 20 30 40 50 60 70 80 90 100];
D=[23 45 60 82 111 140 167 198 200 220];
a=polyfit(d,D,1); % Linear fit
b=polyfit(d,D,2); %Quadratic fit
c=polyfit(d,D,3); %Cubic fit
D1=polyval(a,d);
D2=polyval(b,d);
D3=polyval(c,d);
subplot(3,1,1)
plot(d,D1,'k-o')
hold on
plot(d,D,'go')
title('Linear fit')
xlabel('Days')
ylabel('Donation')
legend('Fitted data','Origional data')
subplot(3,1,2)
plot(d,D2,'k-o')
hold on
plot(d,D,'go')
title('Quadratic fit')
xlabel('Days')
ylabel('Donation')
legend('Fitted data','Origional data')
subplot(3,1,3)
plot(d,D3,'k-o')
hold on
plot(d,D,'go')
title('Cubic fit')
xlabel('Days')
ylabel('Donation')
legend('Fitted data','Origional data')
donation25th=polyval(c,25) %Donation at 25th day using cubic fit
OUTPUT
donation25th =
49.1270
Remark - From the cubic fitted curve it is clear that all the fitted data coincing with origional data hence cubic curve is best for given data