Download Assignment 10 on Numerical Analysis I | MATH 781 and more Assignments Mathematical Methods for Numerical Analysis and Optimization in PDF only on Docsity!
Problem 1. 5.3 from the text. Code: for i=1:10 X=O0:pi/(10*i):pi; Y=1./(4.+8in(20.*X)); Z=trapz(X,Y); fprintf(‘h=pi/td, integral=%e\n',10*i,2); end Output: >> trapezoid h=pi/10, integral=7.853982e-01 h=pi/20, integral=7.853982e-01 h=pi/30, integral=8.111489e-01 h=pi/40, integral=8.115781le-01 h=pi/50, integral=8.111557e-01 h=pi/60, integral=8.111489e-01 h=pi/70, integral=8.111557e-01 h=pi/80, integral=8.111558e-01 h=pi/90, integral=8.111557e-01 h=pi/100, integral=8.111557e-01 Notice that the convergence is as quick as we expected from the example given in the text. Notice that the period of sin 20x is pi/10, so we need to sample points at least once every pi/10 in order to get something useful. Also, the actual integral is pi/sqrt(15).