Advertisement
legrahamcracker

Adaptive Simpson's Method with true error for g = e^xsin(e^x)

May 22nd, 2021
2,654
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Octave 0.64 KB | None | 0 0
  1. function [outI, outX] = adaptive_two_simpson_g_error (func, a, b, tol)
  2. m = (a+b)/2;
  3. ## c = 1/(1/16-1);
  4. ## k = 1/15;
  5. ## g = e.^x.*sin(e.^x)
  6. I = cos(e^a)-cos(e^b);
  7.  
  8. [outI_1, outX_1] = composite_two_simpson(func, a, m, (m-a)/2 );
  9. [outI_2, outX_2] = composite_two_simpson(func, m, b, (b-m)/2 );  
  10.  
  11. if abs(I - (outI_1 + outI_2)) < tol
  12.   outI = outI_1 + outI_2;
  13.   outX = unique([outX_1, outX_2]);
  14.  
  15. else
  16.   [outI_3, outX_3] = adaptive_two_simpson_g_error(func, a, m, tol/2);
  17.   [outI_4, outX_4] = adaptive_two_simpson_g_error(func, m, b, tol/2);
  18.  
  19.   outI = outI_3 + outI_4;
  20.   outX = unique([outX_3, outX_4]);
  21.  
  22. endif
  23.  
  24. endfunction
  25.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement