Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

romberg function : function [q,ea,iter]=romberg(f,a,b,es,maxIt) % romberg: Romberg integration quadrature % q = romberg(f,a,b,es,maxIt): Romberg Integration % % inputs: % f = function to integrate

image text in transcribed

romberg function :

function [q,ea,iter]=romberg(f,a,b,es,maxIt)

% romberg: Romberg integration quadrature

% q = romberg(f,a,b,es,maxIt): Romberg Integration

%

% inputs:

% f = function to integrate

% a, b = integration limits

% es = desired relative error (default = .000001%)

% maxIt = maximum allowable iterations (default=50)

% outputs:

% q = integral estimate

% ea = approximate relative error

% iter = number of iterations

if nargin

if nargin

if nargin

I(1,1) = trap(f,a,b,1);

iter = 0;

while iter

iter = iter+1;

n = 2^iter;

I(iter+1,1) = trap(f,a,b,n);

for k = 2: iter+1

j = 2+iter-k;

I(j,k) = (4^(k-1)*I(j+1,k-1)-I(j,k-1)) /(4^(k-1)-1);

end

ea = abs((I(1,iter+1)-I(2,iter))/I(1,iter+1))*100;

if ea

end

q = I(1,iter+1);

end

here is the fuction of problem 1 and the problem 1

function I = GaussQuad(f,a,b,n)

% GaussQuad: gauss quadrature integration

% I=GaussQuad(f,a,b,n)

% Input:

% f = name of function to be integrated

% a, b = integration limits

% n = number of quad points (default=8)

% Other Variables:

% xd = Gauss points to evaluate

% w = Weight factors

% x = True position of evaluation

% Output:

% I = Integral estimate

if nargin

if ~(b>a), error('Upper bound must be greater than lower'), end

if nargin

[xd,w]=GLTable(n);

I = 0;

c1 = (b+a)/2;

c2 = (b-a)/2;

for i = 1:n

x = c1 + c2 * xd(i);

I = I + f(x) * w(i);

end

I = I * c2;

end

function [x,w] = GLTable(n)

% GLTable Nodes and weights for Gauss-Legendre quadrature of order n

%

% Synopsis: [x,w] = GLTable(n)

%

% Input: n = number of nodes in quadrature rule, maximum: n = 8

%

% Output: x = vector of nodes

% w = vector of weights

% Numerical values from "Handbook of Mathematical Functions",

% Abramowitz and Stegun, eds., 1965 Dover (reprint), Table 25.4, p. 916

nn = fix(n); % Make sure number of nodes is an integer

x = zeros(nn,1); w = x; % Preallocate x and w vectors

switch nn

case 1

x = 0; w = 2;

case 2

x(1) = -1/sqrt(3); x(2) = -x(1);

w(1) = 1; w(2) = w(1);

case 3

x(1) = -sqrt(3/5); x(2) = 0; x(3) = -x(1);

w(1) = 5/9; w(2) = 8/9; w(3) = w(1);

case 4

x(1) = -0.861136311594053; x(4) = -x(1);

x(2) = -0.339981043584856; x(3) = -x(2);

w(1) = 0.347854845137454; w(4) = w(1);

w(2) = 0.652145154862546; w(3) = w(2);

case 5

x(1) = -0.906179845938664; x(5) = -x(1);

x(2) = -0.538469310105683; x(4) = -x(2);

x(3) = 0;

w(1) = 0.236926885056189; w(5) = w(1);

w(2) = 0.478628670499366; w(4) = w(2);

w(3) = 0.568888888888889;

case 6

x(1) = -0.932469514203152; x(6) = -x(1);

x(2) = -0.661209386466265; x(5) = -x(2);

x(3) = -0.238619186083197; x(4) = -x(3);

w(1) = 0.171324492379170; w(6) = w(1);

w(2) = 0.360761573048139; w(5) = w(2);

w(3) = 0.467913934572691; w(4) = w(3);

case 7

x(1) = -0.949107912342759; x(7) = -x(1);

x(2) = -0.741531185599394; x(6) = -x(2);

x(3) = -0.405845151377397; x(5) = -x(3);

x(4) = 0;

w(1) = 0.129484966168870; w(7) = w(1);

w(2) = 0.279705391489277; w(6) = w(2);

w(3) = 0.381830050505119; w(5) = w(3);

w(4) = 0.417959183673469;

case 8

x(1) = -0.960289856497536; x(8) = -x(1);

x(2) = -0.796666477413627; x(7) = -x(2);

x(3) = -0.525532409916329; x(6) = -x(3);

x(4) = -0.183434642495650; x(5) = -x(4);

w(1) = 0.101228536290376; w(8) = w(1);

w(2) = 0.222381034453374; w(7) = w(2);

w(3) = 0.313706645877887; w(6) = w(3);

w(4) = 0.362683783378362; w(5) = w(4);

otherwise

error(sprintf('Gauss quadrature with %d nodes not supported',nn));

end

end

image text in transcribed

oConsider the function given in problem 1 over the interval from 0 to 1 (a) Use the Romberg integration technique to calculate the integral with an error of o(h8) Using Matlab Show all of the steps. You can use the trap function but not the romberg function. Print the results in a table like the one below 4X. xxXXxXXXXx (b) Use the romberg function with default tolerance and maximum iterations to verify your answer. Use an appropriate fprintf statement to print the result with 10 digits after the decimal point. (c) Why is the error not zero for the Gauss-Legendre method? Use an fprintf statement to print your answer. oConsider the function given in problem 1 over the interval from 0 to 1 (a) Use the Romberg integration technique to calculate the integral with an error of o(h8) Using Matlab Show all of the steps. You can use the trap function but not the romberg function. Print the results in a table like the one below 4X. xxXXxXXXXx (b) Use the romberg function with default tolerance and maximum iterations to verify your answer. Use an appropriate fprintf statement to print the result with 10 digits after the decimal point. (c) Why is the error not zero for the Gauss-Legendre method? Use an fprintf statement to print your

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design And Relational Theory Normal Forms And All That Jazz

Authors: Chris Date

1st Edition

1449328016, 978-1449328016

More Books

Students also viewed these Databases questions

Question

Define operations management

Answered: 1 week ago

Question

List the different categories of international employees. page 642

Answered: 1 week ago

Question

Explain the legal environments impact on labor relations. page 590

Answered: 1 week ago