Hw11_p05a - a0 = a(1 a1 = a(2 a2 = a(3 a y_regressed = a0 a1*x a2*x*x plot(x y'o x y_regressed xlabel'r(m ylabel'v(m/s legend'Data'Regression l

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

View Full Document Right Arrow Icon
clc clear r = [0.0, 2.5, 5.0, 7.5, 10.0, 12.5, 15.0, 17.5, 20.0]; % Radius (cm) r = 0.01*r; % Unit conversion to (m) v = [0.914, 0.890, 0.847, 0.795, 0.719, 0.543, 0.427, 0.204, 0.0]; % Velocity (m/s) n = length(r); h = 0.025; R1 = 0.0; R2 = 0.2; % 2nd order polynomial regression: y = a0 + a1*x + a2*x^2 x = r; y = v; y sum_x = 0.0; sum_x2 = 0.0; sum_x3 = 0.0; sum_x4 = 0.0; sum_y = 0.0; sum_xy = 0.0; sum_x2y = 0.0; for i = 1:n sum_x = sum_x + x(i); sum_x2 = sum_x2 + x(i)*x(i); sum_x3 = sum_x3 + x(i)*x(i)*x(i); sum_x4 = sum_x4 + x(i)*x(i)*x(i)*x(i); sum_y = sum_y + y(i); sum_xy = sum_xy + x(i)*y(i); sum_x2y = sum_x2y + x(i)*x(i)*y(i); end e A = [n, sum_x, sum_x2; sum_x, sum_x2, sum_x3; sum_x2, sum_x3, sum_x4]; b = [sum_y; sum_xy; sum_x2y]; b a = A\b;
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: a0 = a(1); a1 = a(2); a2 = a(3); a y_regressed = a0 + a1*x + a2*x.*x; plot (x, y, 'o', x, y_regressed); xlabel('r (m)'); ylabel('v (m/s)'); legend('Data', 'Regression'); l % open file fid4 = fopen('hw11_p05_answer.txt','a'); % 'wt' means "write text" if (fid4 < 0) error('could not open file "hw11_p05_answer.txt"'); end; e fprintf(fid4, '\nv = (%10.5f) + (%10.5f)r + (%10.5f)r^2\n', a0, a1, a2); f % Analytical function obtained: y = a0 + a1*x + a2*x^2 % Analytical integration for 2*pi*(a0*x + a1*x^2 + a2*x^3) Q_analytical = 2*pi*(a0/2.0*(R2^2 - R1^2) + a1/3.0*(R2^3 - R1^3) + a2/4.0*(R2^4 - R1^4)); R fprintf(fid4, 'Q_analytical = %10.5f m^3/s\n', Q_analytical); fclose(fid4);...
View Full Document

This note was uploaded on 02/22/2010 for the course CHE 348 taught by Professor Chelikowsky during the Spring '08 term at University of Texas at Austin.

Ask a homework question - tutors are online