Question

In: Advanced Math

Write a program to implement the Romberg Algorithm. Input: f(x), an interval [a,b], N (the number...

Write a program to implement the Romberg Algorithm.

Input: f(x), an interval [a,b], N (the number of subintervals on the finest grid on level 0 is 2^N, therefore, N is usualy a small integer)

Output: the triangle generated by Romberg Algorithm.

Solutions

Expert Solution

Parameters:
f                - function to be integrated
a, b           - interval of integration
N              - number of columns to generated (zero-based)
print_table - true or false, true to display generated table

romberg := proc(f::algebraic, a, b, N,print_table)
local R,h,k,row,col;
R := array(0..N,0..N);

# Compute column 0, Trapezoid Rule approximations of
#                   1,2,4,8,..2^N subintervals
h := evalf(b - a);
R[0,0] := evalf(h/2 * (f(a)+f(b)));
for row from 1 to N do;
   h := h/2;
   R[row,0] := evalf(0.5*R[row-1,0] +
                     sum(h*f(a+(2*k-1)*h),k=1..2^(row-1)));
   # Compute [row,1]:[row,row], via Richardson extrapolation
   for col from 1 to row do;
     R[row,col] := ((4^col)*R[row,col-1] - R[row-1,col-1]) /
                       (4^col - 1);
   end do;
end do;

# Display results if requested
if (print_table) then
   for row from 0 to N do;
     for col from 0 to row do;
       printf("%12.10f ",R[row,col]);
     end do;
     printf("\n");
   end do;
end if;

return(R[N,N]);

end proc:

Ask if you have any queries. Thank you


Related Solutions

Write a program to implement problem statement below: provide the menu for input N and number...
Write a program to implement problem statement below: provide the menu for input N and number of experiment M to calculate average time on M runs. randomly generated list. State your estimate on the BigO number of your algorithm/program logic. (we discussed in the class) Measure the performance of your program by given different N with randomly generated list with multiple experiment of Ns against time to draw the BigO graph (using excel) we discussed during the lecture. Lab-08-BigBiggerBiggtest.png ***...
Write an algorithm to input a number n, then calculate 13 +2 3 + 33 +...
Write an algorithm to input a number n, then calculate 13 +2 3 + 33 + ... + n3, the sum of the first n cubic numbers, and output the result. 2-Construct a trace table of the algorithm in question 1 with input n=4.
Write a program (O(n), where n is the number of words) that takes as input a...
Write a program (O(n), where n is the number of words) that takes as input a set of words and returns groups of anagrams for those words. Complete your code here Do not change anything in the test file. CPP File: #include #include #include #include using namespace std; vector> findAnagrams(const vector& dict); vector> findAnagrams(const vector& dict) { // Your code here... } Test File: #include #include #include #include using namespace std; vector> findAnagrams(const vector& dict); int main() { vector word_list...
algorithm binarySearch input bottom, top: a number    a: array a[0] to a[n-1] of numbers    x: a...
algorithm binarySearch input bottom, top: a number    a: array a[0] to a[n-1] of numbers    x: a number output result: true if x in a false otherwise Sideeffect NA Plan if (top < bottom) result := false else // get the middle of the array (refining) middle := (top - bottom)/2 + bottom (refining by +1 or -1 or integer division …) // example what is midpoint between 6 and 8 // (8-6)/2 = 1 we need to add 6 to...
Implement a C++ program to implement the Banker’s algorithm for deadlock avoidance. Number of process 5,...
Implement a C++ program to implement the Banker’s algorithm for deadlock avoidance. Number of process 5, number of resources 3 and the number of instances of each given resource is in available. You should complete the functionalities for safe state check and resource request processing. To Do 1. Complete the definition of isSafe function. The function take, the process array, 1D array of available resources, 2D array storing current allocation, and 2D array of current need. The function does not...
Write a program to choose a random number X in the interval [2,10] 1000 times and...
Write a program to choose a random number X in the interval [2,10] 1000 times and record what fraction of the outcomes satisfy X > 5, what fraction satisfy 5 < X < 7, and what fraction satisfy x2 −12x+35 > 0. How do these results compare with Exercise 1?
a) write a program to compute and print n, n(f), f(f(n)), f(f(f(n))).........for 1<=n<=100, where f(n)=n/2 if...
a) write a program to compute and print n, n(f), f(f(n)), f(f(f(n))).........for 1<=n<=100, where f(n)=n/2 if n is even and f(n)=3n+1 if n is odd b) make a conjecture based on part a. use java
Now say you wish to write a program that, given a natural number input n, finds...
Now say you wish to write a program that, given a natural number input n, finds another program (e.g. in Java or C) which prints out n. The discovered program should have the minimum execution-time-plus-length of all the programs that print n. Execution time is measured by the number of CPU instructions executed, while “length” is the number of characters in the source code. Can this be done? (Hint: Is it possible to tell whether a program halts on a...
Find the absolute maxima and minima for f(x) on the interval [a, b]. f(x) = x3...
Find the absolute maxima and minima for f(x) on the interval [a, b]. f(x) = x3 − 2x2 − 4x + 4,    [−1, 3] absolute maximum     (x, y) =    absolute minimum     (x, y) =    2. f(x) on the interval [a, b]. f(x) = x3 − 3x2 − 24x + 8,    [−3, 5] absolute minimum (x, y) =    absolute maximum (x, y) =
Find the absolute maxima and minima for f(x) on the interval [a, b]. f(x) = x3...
Find the absolute maxima and minima for f(x) on the interval [a, b]. f(x) = x3 − 2x2 − 4x + 4,    [−1, 3] absolute maximum     (x, y) =    absolute minimum     (x, y) =    2. f(x) on the interval [a, b]. f(x) = x3 − 3x2 − 24x + 8,    [−3, 5] absolute minimum (x, y) =    absolute maximum (x, y) =   
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT