This is part a:
Write a program (using a programming language of your choice) to implement the composite Midpoint
rule Mn for evaluating the integral form a to b of f(x)dx.
The program should accept four parameters — the function f, integral region limits a and b, and the
number of subintervals n.
In the first part of my problem I was to write a program (using a programming language of your choice) to implement the composite Midpoint
rule Mn for evaluating the integral f rom a to b of f(x)dx. I pulled this off somehow by doing;
CMP := proc(f, a, b, n)
local h, j, M;
h := (b-a)/n;
M := 0;
for j from 1 to n do
M := M + f(a + (j-1/2) * h);
od;
M := M * h;
end;
Now I have to modify the program in part (a) so that it can determine the value of n to satisfy a required tolerance Tol.The program should accept four parameters — the function f, integral region limits a and b, and tolerance tol. Use the algorithm we discussed in class – i.e., start with n = 1 and n = 2, and keep doubling the value of n until |M2n ?Mn| < or = tol.
We have done examples of using Tol in the past but I am really lost as to how I would use this in my origional program. Any help would be amazing and greatly appreciated!
Thank you
Write a program (using a programming language of your choice) to implement the composite Midpoint
rule Mn for evaluating the integral form a to b of f(x)dx.
The program should accept four parameters — the function f, integral region limits a and b, and the
number of subintervals n.
In the first part of my problem I was to write a program (using a programming language of your choice) to implement the composite Midpoint
rule Mn for evaluating the integral f rom a to b of f(x)dx. I pulled this off somehow by doing;
CMP := proc(f, a, b, n)
local h, j, M;
h := (b-a)/n;
M := 0;
for j from 1 to n do
M := M + f(a + (j-1/2) * h);
od;
M := M * h;
end;
Now I have to modify the program in part (a) so that it can determine the value of n to satisfy a required tolerance Tol.The program should accept four parameters — the function f, integral region limits a and b, and tolerance tol. Use the algorithm we discussed in class – i.e., start with n = 1 and n = 2, and keep doubling the value of n until |M2n ?Mn| < or = tol.
We have done examples of using Tol in the past but I am really lost as to how I would use this in my origional program. Any help would be amazing and greatly appreciated!
Thank you