Question

Check the file: Questions.pdf

Solution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

2. function [R]=Romberg(f,a,b,n)
%ROMBERG - Romberg integration
% -Input:
%       f       -   function name or function handle
%       a,b    -   integration interval [a,b]
%       n       -   size of the romberg table
% -Output:
%       R       -   an nxn matrix of numerical integrals
%                   R(i,j): h=(b-a)/2^(i-1), order=2*j
%

%% Calculate Romberg integration
R=zeros(n,n);
h=b-a;
R(1,1)=h/2*(feval(f,a)+feval(f,b));
for i=2:n
    m=2^(i-2);
    h=(b-a)/m;
    s=sum(feval(f,a+([1:m]-0.5)*h));%summation at new points
    R(i,1)=0.5*(R(i-1,1)+h*s);      %composite trapezoidal rule
    for j=2:i                     
       R(i,j)=R(i,j-1)+(R(i,j-1)-R(i-1,j-1))/(4^(j-1)-1); % extrapolation
    end
end
%% Output R
for i=1:n
    for j=1:i
       fprintf(1,'R(%1d,%1d)=%11.4e ',i,j,R(i,j));
    end
    fprintf(1,'\n');
end
return;...

This is only a preview of the solution. Please use the purchase button to see the entire solution

Related Homework Solutions

Numerical Analysis Using Matlab
Homework Solution
$85.00
Advanced Mathematics
Numerical Analysis
Matlab
Endpoint Conditions
Cubic Spline
Natural Boundary Conditions
Tables
Scripts
Interpolation
Points
Polynomials
Numerical Orders
Errors
Methods
Numerical Analysis Questions
Homework Solution
$70.00
Mathematics
Numerical Analysis
Plots
Computer Science
Programming
Errors
Conditional Numbers
Relative Norms
Systems
Accuracy
Polynomials
Approximation
Factors
Codes
Numerical Approximation in Matlab
Homework Solution
$163.00
Advanced Mathematics
Numerical Analysis
Numerical Approximation
Matlab
Equation Systems
Matrices
Corresponding Force
Geometry
Tables
Values
Built-In Functions
Summation
Approximations
First Derivative
Computation
Round-Off Error
Binary Num
Numerical Analysis
Homework Solution
$3.00
Mathematics
Numerical Analysis
Problems
Jacobi
Gauss-Seidel
Formula
Get help from a qualified tutor
Live Chats