{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

hw11_p05a

# hw11_p05a - a0 = a(1 a1 = a(2 a2 = a(3 a y_regressed = a0...

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

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;
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

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern