2

Hello guys and sorry for my bad English , i have the following homework i should composite Newtons polynomial interpolation 3d grade , Simpsons 3/8 method with matlab !

But i have some trouble, i have the following formula and i should make the algorithm in Matlab formula

which i create it but i don't know if its right or not any suggestion, please?

function x = three_eight_rule(fun,a,b,n);
h = (b-a) / n;
sum = feval(fun,a) + feval(fun,b);
sum1 = 0;
sum2 = 0;

for i = 2:3:n-1
    x = a + i*h;
    sum1 = sum1 + 3*(feval(fun,x) + feval(fun,x+h));
end

for i = 4:3:n-2
    x = a + i*h;
    sum2 = sum2 + 2*(feval(fun,x));
end

sum = sum + sum1 + sum2;

x = ((3*h)/8) * sum;

1 Answers1

1

You have written the formula for the polynomial but you do not really need it, you just need that the estimate for the integral on a subinterval $[c,c+3h]$ is

$$\frac{3h}{8} \left ( f(c)+3f(c+h)+3f(c+2h)+f(c+3h) \right ).$$

If you want you can use two loops, but this is not really necessary.

Also, two comments on your Matlab:

  1. You should not use the word "sum". This is a built-in Matlab function for adding up elements of a vector or matrix. Matlab will let you overwrite it, but this is very bad style. Use a different name.
  2. You do not need to use "feval". You can just write fun(x) or similar things.
Ian
  • 101,645