You are on page 1of 3

American University of Sharjah

College of Engineering

NGN 509 – Computational Methods


Professor Nai-Shyong Yeh
Assignment #3

Mostafa Mohamed Moussa - 59665

Submitted on 21st of March 2019


Q1.
Q2.
Code for Romberg integration:
Function:
function f = funy(x)
f = 7+14*(x.^6);
end
M-file:
clear;clc;close all;
%*****Question 2***********************************************************
e=10e-6; % Maximum acceptable error.
n=4; % Sets dimension of R
a=0;
b=1; % a and b are the definite integration limits.
h=b-a;
R=zeros(n+1,n+1); % Creates R(5,5) as a zero matrix (faster).
R(1,1)= (1/2)*h*(funy(a)+funy(b)); % Computes R(1,1)=I1.
for i=1:n
h=h/2; % Reduces h by half with every iteration to compute the next R
element in column 1.
for j=1:i
R(i+1,1)= (1/2)*h*(funy(a)+2*sum(funy((a + h):h:(b - h)))+funy(b));
R(i+1,j+1)= (4^j*R(i+1,j)-R(i,j))/(4^j-1); % Richardson extrapolation
(slide 22)
end
error=abs(R(i+1, i+1) - R(i, i));
if error<e
break
end
end
%Display i, h, and R
i
h
R
______________________________________________________________________________________
i =
4
h =
0.0625

You might also like