{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

E7_Lab10_Solutions_Fall_2010

# E7_Lab10_Solutions_Fall_2010 - Solutions_Lab10...

This preview shows pages 1–3. Sign up to view the full content.

Solutions_Lab10 file:///D:/work/acad/PG/SEM_1/E%207/lab%2010/html/Solutions_Lab10... 1 of 7 12-Nov-2010 11:29 PM Contents 1a. 1b. 2 3 4a. 4b. 5a. Alternate problem 5 solutions (acceptable for only students from Sec.16) 5b. 5c. clear all format compact 1a. type trapezoid function I=trapezoid(fun, a, b, n) % This is just one implementation of the trapezoid function using 'for' % loop I = 0; h = (b-a)/(n+1); x = a:h:b; for i = 1:n+1; I = I + 0.5*h*(fun(x(i)) + fun(x(i+1))); end end 1b. n_array=[11 21 51 101 201 501 1001]; I_exact=2; I_n = zeros(1,length(n_array)); e = zeros(1,length(n_array)); for i=1:length(n_array) I_n(i)=trapezoid(@sin, 0, pi, n_array(i)); e(i)=abs(I_exact-I_n(i))/abs(I_exact); end loglog(n_array, e) xlabel( 'Number of Points' ) ylabel( 'Relative Error' ) title( 'By trapezoid rule' )

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Solutions_Lab10 file:///D:/work/acad/PG/SEM_1/E%207/lab%2010/html/Solutions_Lab10... 2 of 7 12-Nov-2010 11:29 PM 2 for tol=[1e-2 1e-4 1e-6] [q,fctn]=quad(@test_fun,1,3,tol); disp([ 'For tolerance = ' ,num2str(tol), ' integral = ' , num2str(q), ... ' and number of function evaluations = ' ,num2str(fctn)]); end type test_fun For tolerance = 0.01 integral = -25.8547 and number of function evaluations = 21
This is the end of the preview. Sign up to access the rest of the 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