Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

MATLAB Code for Romberg Integration

Status
Not open for further replies.

rroy81

Newbie level 2
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.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top