question archive Problem 3 (a)

Problem 3 (a)

Subject:MathPrice: Bought3

Problem 3 (a). Find approximations to the following integrals: 1 1 f (1 — 43(1 — 3))"ng and / medals 0 I] by using the composite trapezoidal rule (quadtrapn) and composite Simpson's rule ( quadsimpn). Use the Matlob statement format long to get extra precision and choose ninit = 2 and main: = 100000. Run the programs for the choices tol = 10—2, 10—4, and 10—3 and record the error and the number of subintervals used in a table. In addition, for 1:01: 10—16 run only the Simpson's rule program on the second function. (h) Now compute the order of convergence of these approximations by using the following idea. Assume that the error of each approximation has the form E = Ch" , where C and d are constants. Then if E1 and E2 are the errors corresponding to h] and fig , respectively, we have ngE1 = (h?h?a from which it follows that or = ln[E2/'E1)fln(h2jh1). Since for this problem, it = I/N , the number of subintervals, or = in(E2fE1)fh1[N1ng). For each function and each method, use this formula to compute an approximate o: for each pair of successive entries in the table of part (a). [[11 the case of Simpson's rule and the second function, do the computations corresponding to the pairs, [10—4, 10—3) and (10—3, Ill—1'5), rather than {10—2,10_4) and [10—4, 104).] {c} Brie?y explain why the results do or do not agree with the order of convergence predicted by the theory developed in class.

quadtrap.m  code:
 

function [value, nfinal, errfinal] = quadtrap(FunFcn,a,b,tol,ninit,maxn)
 

told = trap(FunFcn,a,b,ninit);
  err=1;
  n = ninit;
while n <= maxn & err > tol
  tnew = (told + mid(FunFcn,a,b,n))/2;
  err = abs(tnew-told);
  n= 2*n;
  told = tnew;
end
value = tnew;
nfinal = n;
errfinal = err;
 

 

quadsimp.m  code:
 

function [value, nfinal, errfinal] = quadsimp(FunFcn,a,b,tol,ninit,maxn)
trapold = trap(FunFcn,a,b,ninit);
  midold = mid(FunFcn,a,b,ninit);
  told = (trapold + 2*midold)/3;
  err=1;
  n = ninit;
while n <= maxn & err > tol
  midnew =  mid(FunFcn,a,b,2*n);
  trapnew = (trapold + midold)/2;
  tnew = (trapnew + 2*midnew)/3;
  err = abs(tnew-told);
  n= 2*n;
  midold=midnew;
  trapold = trapnew;
  told = tnew;
end
value = tnew;
nfinal = n;
errfinal = err;

pur-new-sol

Purchase A New Answer

Custom new solution created by our subject matter experts

GET A QUOTE