Question

In: Computer Science

Give me a MATLAB code which integrates any function using Romberg integration The code must work...

Give me a MATLAB code which integrates any function using Romberg integration

The code must work fine or else I will down vote the answer badly

Dont post if you dont know

Solutions

Expert Solution

The given MATLAB CODE takes any function and integrates it as per the rule of Romberg as per various levels and prints the result. The intermediate trapezoidal rule code is also shown

The sample is shown for f(x)=1/(1+x) for 5 levels from 0 to 1

clc;clear all
format long
f=@(x) 1./(1+x);
a=0;b=1;h=1;n=5;
ans1=RombergIntegration(f,a,b,h,5);
fprintf('Desired answer is %5.6f \n',ans1(1,n+1))
function I=RombergIntegration(f,a,b,s,level)
for(j=1:(level+1))
ni=s*2^(j-1);
I(j,1)=trapezoidal(f,a,b,ni);
end
for(j=2:level+1)
for(k=1:(level-j+2))
I(k,j)=(4^(j-1)*I(k+1,j-1)-I(k,j-1))/(4^(j-1)-1);
end
end
end
function answer=trapezoidal(f,a,b,n)
i(1)=f(a); i(n+1)=f(b);
h=(b-a)/n;
x=a:h:b;
i(2:n)=2*f(x(2:(length(x)-1)));
answer=0.5*h*sum(i);
end


Related Solutions

Give me a working code in MATLAB for Crout Decomposition. The code must work totally fine...
Give me a working code in MATLAB for Crout Decomposition. The code must work totally fine and must break into 2 matrix L and U It must be in MATLAB The code used must use continue statement. If no continue statement is there in code it will be downvoted. Answer only if you know or else i will dislike badly
The following code must be written using matlab and must be using a for-loop. NOTE! Write...
The following code must be written using matlab and must be using a for-loop. NOTE! Write a computer program that assigns random integers for each entry and generates a row vector. Different random integers should be drawn from different intervals for position 1, position 2, position3 and position 4 of the array. After these first 4 positions are drawn. The whole thing should start over where position5 drawn from same interval as positions 1, position6 drawn from same interval as...
The following code must be written using matlab and must be using a for-loop. NOTE! Write...
The following code must be written using matlab and must be using a for-loop. NOTE! Write a computer program that assigns random integers for each entry and generates a row vector. Different random integers should be drawn from different intervals in chunks of 4 , that is chunk1-chunk2-chunk3-chunk4 The parameters for specifying the lintervals by which the random numbers should be drawn should be able to change and be hardcoded in the script, however, be hardcoded in the script.
Give me a working MATLAB code for the Golden section search method . It should be...
Give me a working MATLAB code for the Golden section search method . It should be working Dont answer if you do not know, the code must work for the golden section method
The following code must be written using matlab How to loop through a vector in matlab...
The following code must be written using matlab How to loop through a vector in matlab and assigning a value to every 4th entry. The vector could be of any length. Thanks
This is the Matlab practice so needs Matlab code 2. Numerical Integration Consider an industrial tank...
This is the Matlab practice so needs Matlab code 2. Numerical Integration Consider an industrial tank in the shape of an inverted cone. The radius of the tank at the top rim is 3 m, and the total height of the tank is 4 m. The volume of the tank in m3 is given by: V = (1/3) R2 H. The volume of liquid in the tank when filled to a height h measured from the bottom vertex is: V...
The following code must be written using matlab How to get the elements that are different...
The following code must be written using matlab How to get the elements that are different in two set without using the setdiff function in matlbab?
For this question, you must show all work to receive any credit. DONOT USE MATLAB FOR...
For this question, you must show all work to receive any credit. DONOT USE MATLAB FOR THIS QUESTION. for k = 3*1:6:21 j = k/3; if rem(j,6) >= 3 disp(k) elseif rem(j,3) < 2 disp(j) else disp(3) end end write out the solution
q1) using Matlab make a code that allows a user to enter a function like fractional...
q1) using Matlab make a code that allows a user to enter a function like fractional function and cubic liner function then the Matlab send a domain, range, continuity
q1) using Matlab make a code that allows a user to enter a function like fractional...
q1) using Matlab make a code that allows a user to enter a function like fractional function and cubic liner function then the Matlab send a domain, range, continuity
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT