Advertisement
Voldemord

[Matlab] Algorytm całkowania metodą Simpsona

Apr 24th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.27 KB | None | 0 0
  1. %>> Tested('x^2 +4',1,6,1)
  2. %ans =   91.6667
  3.  
  4. function [ o ] = Tested( f, a, b, d)
  5. syms x;
  6. f = @(x)eval(f);
  7. x = [a:d:b];
  8. s = 0;
  9. %
  10.     for i = 1:(length(x) - 1)
  11.        p = ( f(x(i)) + 4 * f((x(i)+ d/2)) + f(x(i)+d) ) * d / 6;
  12.        s = s + p;  
  13.     end
  14. o = s;
  15. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement