MATLAB Code for Romberg Integration

Status
Not open for further replies.

rroy81

Newbie level 2
Joined
May 29, 2013
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Visit site
Activity points
1,292
Problem: I need to write a matlab code using the function f(x)=sin(x) evaluating integral between [0,pi]. I need to iterate till I achieve a relative error of 10^-12

this what I have as far as coding goes.
% Romberg Integration for sin(x) over [0,pi]
a = 0; b = pi; % The Endpoints
R = zeros(7,7);
R(1,1) =(b-a)/2*(sin(a) + sin(b));
for k = 7 : 7
h =(b-a)/2^(k-1);
R(k,1)=1/2*(R(k-1,1) + 2*h-1*(sin(a+ (2*(1 : (2^(k-2)))-1)*h)));
end
for j= 2 : 7
for k=j: 7
R(k,j) =R(k,j-1) + (R(k,j-1)-R(k-1,j-1))/(4^(j-1)-1);
end
end
disp(R)

I am getting mismatch errors according to matlab.

Can someone PLEASE HELP?!?!?!?!?!?!
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…