Romberg integration in matlab Given the definite integral I = integral^3_0 xe^x/
ID: 3578733 • Letter: R
Question
Romberg integration in matlab
Given the definite integral I = integral^3_0 xe^x/2 Use the Romberg integration technique to calculate the result to order h^8. Fill in the epsilon_t and epsilon_a as indicated by the row and column headers in the table below, given the true value of the integral is l_true = 12.96337814. Write a Matlab script, which can be included as part of an m-file from part a), that stores the I_j, k values in an array I_j, k (4, 4) (several of the values will be empty since Matlab requires matrices be rectangular). Similarly construct an array that stores epsilon^jk_t, and epsilon^j_a. Have the script print out values in a similar format to the table below.Explanation / Answer
function r = romberg(f,a,b,n)
% Input:
% f - Matlab inline function
% a,b - integration interval
% n - number of rows in Romberg tableau
%
% Output:
% r - Romberg tableau containing the computed values of the integral
h = (b - a) ./ (2.^(0:n-1));
r(1,1) = (b - a) * (f(a) + f(b)) / 2;
for j = 2:n
subtotal = 0;
for i = 1:2^(j-2)
subtotal = subtotal + f(a + (2 * i - 1) * h(j));
end
r(j,1) = r(j-1,1) / 2 + h(j) * subtotal;
for k = 2:j
r(j,k) = (4^(k-1) * r(j,k-1) - r(j-1,k-1)) / (4^(k-1) - 1);
end
end;
%%%scripts for calling above function
clc;
clear all;
close all;
r=romberg(inline('x*exp(x/2)'),0,3,4);
r=flipud(r)
I_true=12.96337814; % given true integral value
I_jk=zeros(4,4);
for i=1:4
for j=i:4
I_jk(j,i)=I_true;
end
end
I_jk=flipud(I_jk)
error=r-I_jk
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.