https://www.math.ucdavis.edu/~guy/teaching/128a/hw5_128Af19.pdfproblem1

1 answer below »
Answered Same DayDec 05, 2021

Answer To: https://www.math.ucdavis.edu/~guy/teaching/128a/hw5_128Af19.pdfproblem1

Abr Writing answered on Dec 07 2021
155 Votes
composite_trapezoid.m
function F=composite_trapezoid(f, upper_limit, lower_limit, n, varargin)
if nargin==4
if upper_limit>lower_limit
h=(upper_limit-lower_limit)/n;
F=(h
/2)*(f(lower_limit)+f(upper_limit));
for ii=1:(n-1)
F(ii+1)=F(ii)+(h/2)*(2*f(lower_limit+ii*h));
end
else
h=(lower_limit-upper_limit)/n;
F=(h/2)*(f(lower_limit)+f(upper_limit));
for ii=1:(n-1)
F(ii+1)=F(ii)+(h/2)*(2*f(upper_limit+ii*h));
end
end
else
if upper_limit>lower_limit
h=(upper_limit-lower_limit)/n;
F=deg2rad(h/2)*(f(deg2rad(lower_limit))+f(deg2rad(upper_limit)));
for ii=1:(n-1)
F(ii+1)=F(ii)+deg2rad(h/2)*(2*f(deg2rad(lower_limit+ii*h)));
end
else
h=(lower_limit-upper_limit)/n;
F=deg2rad(h/2)*(f(deg2rad(upper_limit))+f(deg2rad(lower_limit)));
for ii=1:(n-1)
F(ii+1)=F(ii)+deg2rad(h/2)*(2*f(deg2rad(upper_limit+ii*h)));
end
end
end
F = F(end);
% fprintf('Integral of the given function is: %25.6f \n', F(end));
end
composite_gauss.m
function F = composite_gauss(f, lower_limit, upper_limit, n)
h = (upper_limit-lower_limit)/n;
x = lower_limit:h:upper_limit;
F = 0;
for k = 1:n
[pt,weight] = lgwt(2,x(k),x(k+1)); % Gauss points and weights
F = F + sum(f(pt).*weight);
end
F = F(1);
% fprintf('Integral of the given function is: %25.6f \n', F));
end
lgwt.m
function [x,w]=lgwt(N,a,b)
N=N-1;
N1=N+1; N2=N+2;
xu=linspace(-1,1,N1)';
% Initial guess
y=cos((2*(0:N)'+1)*pi/(2*N+2))+(0.27/N1)*sin(pi*xu*N/N2);
% Legendre-Gauss Vandermonde Matrix
L=zeros(N1,N2);
% Derivative of LGVM
Lp=zeros(N1,N2);
% Compute the zeros of the N+1 Legendre Polynomial
% using the recursion relation and the Newton-Raphson method
y0=2;
% Iterate until new points are uniformly...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here