class4b_activity3_sol

# class4b_activity3_sol - % --- CALCULATIONS ---P1 =...

This preview shows page 1. Sign up to view the full content.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % Programmer(s) and Purdue Email Address(es): % 1. H. Diefes-Dux; hdiefes@purdue.edu % % Section: ALL % % Assignment #: Class 4b % % Academic Integrity Statement: % % I/we have not used source code obtained from % any other unauthorized source, either modified % or unmodified. Neither have I/we provided access % to my/our code to another. The project I/we am/are submitting % is my/our own original work. % % Program Description: Activity 3 Telephone expenditures regression % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % --- INPUTS --- % telephone expenditure data tel_data = load('telephone_expenditures.dat') year = tel_data(:,1) % col 1 contains years (1981-1999) telcost = tel_data(:,2) % col 2 constains cost (\$)
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: % --- CALCULATIONS ---P1 = polyfit(year,telcost,1) % linear regression coefficients P telcost_fit = polyval(P1,year) % predicted expenditures (\$) from the % linear regression telcost_mean = mean(telcost) % mean value of telephone expenditures (\$) t % SSE computation SSE = sum((telcost-telcost_fit).^2) % SST computation SST = sum((telcost-telcost_mean).^2) % r-squared value r_sq = 1-SSE/SST r % --- OUTPUTS ----plot(year,telcost,'rs') hold on plot(year,telcost_fit,'k-') xlabel('year') ylabel('cost (\$)') title('Telephone expenditures') legend('raw data','best fit','Location','SouthEast') l fprintf('Eqn of best fit is: \n') fprintf('y = %4.1fx + (%4.0f) \n',P1(1),P1(2)) fprintf('r_squared = %4.3f \n',r_sq) f % Eqn of best fit is: % y = 27.5x + (-54087) % r_squared = 0.992...
View Full Document

## This note was uploaded on 08/25/2011 for the course ENGR 195 taught by Professor Staff during the Fall '08 term at Purdue University-West Lafayette.

Ask a homework question - tutors are online