(*Exercise 04*)
ClearAll[val,sol,sol1,val1]
(*Input Part*)
time1=Table[i,{i,1995,1997}];
time2=Table[i,{i,1999,2008}];
time=Join[time1,time2];
income={15,15.1,17.8,20.7,21.1,23,23,23.4,26.8,28.9,29,33.1,29.5};
production={746,800,819,890,926,1005,1022,1081,1087,1147,1185,1240,1230};
(*Calculation Part*)
(*Part 1*)
tin=Transpose[{time,income}];
tpro=Transpose[{time,production}];
netprofit=income*(12.5/100);
tnetprofit=Transpose[{time, netprofit}];
table=TableForm[tnetprofit,TableHeadings->{None,{"Year","Net Profit(Billions)"}},TableAlignments->Center];
(*Part 2*)
(*A*)
gin=ListPlot[tin,PlotStyle->Red];
(*B*)
gpro=ListPlot[tpro,PlotStyle->Green];
(*C*)
ginpro=Show[{gin,gpro},PlotRange->All];
(*Part 3*)
fin1=Fit[tin,{t,1},t];
fin2=Fit[tin,{t^2,t,1},t];
fin3=Fit[tin,{t^3,t^2,t,1},t];
gin1=Plot[fin1,{t,time[[1]],Last[time]},PlotStyle->Blue];
gin2=Plot[fin2,{t,time[[1]],Last[time]},PlotStyle->Purple];
gin3=Plot[fin3,{t,time[[1]],Last[time]},PlotStyle->Yellow];
fin1/.t->1998;
fin2/.t->1998;
fin3/.t->1998;
sol=fin2/.t->{2009,2050};
(*Part 4*)
fpro=Fit[tpro,{t,1},t];
gpro1=Plot[fpro,{t,time[[1]],Last[time]},PlotStyle->Brown];
fpro/.t->1998;
percentageerror=((870-fpro/.t->1998)/870)*100;
(*Part 5*)
proin=Transpose[{income,production}];
gproin=ListPlot[proin,PlotStyle->Pink];
fproin=Fit[proin,{i,1},i];
gproin1=Plot[fproin,{i,income[[1]],Last[income]},PlotStyle->Magenta];
fproin/.i->40;
sol3=Solve[fin2==40,t];
t/.sol3[[1]];
(*Output Part*)
Print[Style["Exercise 4-part (1)",Bold]]
tin
tpro
table
Print[Style["Exercise 4-part (2) (A)",Bold]]
gin
Print[Style["Exercise 4-part (2) (B)",Bold]]
gpro
Print[Style["Exercise 4-part (2) (C)",Bold]]
ginpro
Print[Style["Exercise 4-part (3)",Bold]]
Show[{gin,gin1,gin2,gin3}]
Print["The suitable model is quadratic model",fin2]
Print["Suitable income in year 2009 and 2009 respectively ",sol[[1]]," and ",sol[[2]]]
Print[Style["Exercise 4-part (4)",Bold]]
Show[{gpro,gpro1}]
Print["The percentage of the error is ",percentageerror]
Print[Style["Exercise 4-part (5)",Bold]]
Show[{gproin,gproin1}]
Print["The production when the incoem is 40 billion rupees is ",fproin/.i->40]
Print["The year that the income is equal to 40 billion rupees is ",t/.sol3[[1]]]