rsquared_yourlogin - x_vector slope slope of a fitted line...

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

function r_sq = rsquared_sol(x_vector,y_vector,slope,intercept) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % Programmer(s) and Purdue Email Address(es): % 1. H. Diefes-Dux [email protected] % % Section #: ALL % % Assignment #: Homework 9 Problem 5 % % 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. % % RSQUARED_SOL: Computes r^2 for (x,y) data given slope and intercept of % a fitted line % % INPUTS: List them below one line per input argument % x_vector - independent data values (length and dimension same as % y_vector) % y_vector - dependent data values (length and dimension same as
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: % x_vector) % slope - slope of a fitted line % intercept - intercept of a fitted line % % OUTPUTS: List them below line per output argument % r_sq - computed r^2 value % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % --- CALCULATIONS ---% y_fits = slope*x_vector + intercept; % Fitted values of y % Alternative solution % y_fits1 = polyval([slope,intercept],x_vector); % SSE = sum((y_vector - y_fits).^2); % Sum of squares of errors S y_vector_mean = mean(y_vector); % Mean of the raw y values y SST = sum((y_vector - y_vector_mean).^2); % Sum of squates of deviations S r_sq = 1 - SSE/SST; % r^2 value r % RESULTS: % x = [1, 3, 5, 7, 9]; % y = [0.5, 2.5, 2 4 3.5]; % m = 0.5; % b = 0; % rsquared_sol(x,y,m,b) % ans = % 0.6667...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online