0001
0002
0003 a = -1;
0004 b= 1;
0005 for k = 0:5
0006 f = @(x) x^k;
0007 [ Q ] = simpsons_rule( f,a,b );
0008 disp(['Simpson',char(39),'s rule for x^', num2str(k), ' on [-1,1] is ', num2str(Q)]);
0009 end
0010 f = @sin;
0011 [ Q ] = simpsons_rule( f,a,b );
0012 disp(['Simpson',char(39),'s rule for ', func2str(f), ' on [-1,1] is ', num2str(Q)]);
0013 f = @cos;
0014 [ Q ] = simpsons_rule( f,a,b );
0015 disp(['Simpson',char(39),'s rule for ', func2str(f), ' on [-1,1] is ', num2str(Q)]);
0016 f = @exp;
0017 [ Q ] = simpsons_rule( f,a,b );
0018 disp(['Simpson',char(39),'s rule for ', func2str(f), ' on [-1,1] is ', num2str(Q)]);
0019 f = @(x) 1/x;
0020 [ Q ] = simpsons_rule( f,a,b );
0021 disp(['Simpson',char(39),'s rule for ', func2str(f), ' on [-1,1] is ', num2str(Q)]);
0022 f = @(x) 1/(1+x);
0023 [ Q ] = simpsons_rule( f,a,b );
0024 disp(['Simpson',char(39),'s rule for ', func2str(f), ' on [-1,1] is ', num2str(Q)]);