Guest User

Untitled

a guest
Jan 17th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. a = -1;
  2. b = 1;
  3.  
  4. function y = rung( x )
  5. y = 1 ./ ( 1 + 25 * x .^ 2 );
  6. endfunction
  7.  
  8. %% equispaced points
  9. n = input( 'polynomial degree = ' );
  10.  
  11. for i = 1 : n - 1
  12. h = ( b - a ) / i;
  13. xi = a : h : b; % or xi = linspace( -1, 1, i );
  14. yi = rung( xi );
  15.  
  16. % polynomial interpolator on equispaced nodes
  17. x = linspace( a, b, 321 );
  18. pequi = polyfit( xi, yi, i );
  19. g = rung( x );
  20. yeq = polyval( pequi, x );
  21.  
  22. %plot( xi, yi, 'o', x, yeq, 'b-', x, g, 'r-' );
  23. %plot( x ,yeq, 'b-', x, g, 'r-' );
  24.  
  25. err3 = ( g - yeq );
  26. err4 = norm( err3, 2 );
  27.  
  28. plot( x, yeq, 'b-', x, g, 'm-', x, err3, 'r-' );
  29. endfor
Add Comment
Please, Sign In to add comment