Gaussian Quadrature Error Help
古いコメントを表示
Hi there, I have an assignment which asks to do Gaussian Quadrature for a 4th degree polynomial and discuss the error from the actual solution.
I'm a little confused however, as using 4 gauss points should give an exact solution for polynomials less than or equal to the degree 2n-1 = 7. Since I have a 4th degree polynomial here, why am I getting an error of around 3%? If I increase the number of gauss points to 9, I get an error in the order of 10^-8. Am I missing something major about Gaussian Quadrature? Thanks.
clear all
%% Exact solution
% Define the function as an inline function in x and y
% Create an inline function
ff = @(x,y) 2.*x.^4 - x.^3 + 3.*y.^3 +y.^2 - 2.*x.*y + 5;
% Calculate the exact solution
ExactSol = integral2(ff,-1,1,-1,1);
% Plot the function
ezsurf(ff,[-1 1],[-1 1])
%% Gaussian Quadrature
n = 4;
xi = zeros(n,1);
eta = zeros(n,1);
weights = zeros(n,1);
evaluated = zeros(n,1);
multiplied = zeros(n,1);
% Location of the Gauss points
xi(1) = -1/(sqrt(3));
xi(2) = 1/(sqrt(3));
xi(3) = -1/(sqrt(3));
xi(4) = 1/(sqrt(3));
eta(1) = -1/(sqrt(3));
eta(2) = -1/(sqrt(3));
eta(3) = 1/(sqrt(3));
eta(4) = 1/(sqrt(3));
% Gauss weights
for i = 1:n
weights(i) = 1;
end
% Evaulate the function at Gauss points, multiply by weights,
% then sum.
for j = 1:n
evaluated(j) = 2*xi(j)^4 - xi(j)^3 + 3*eta(j)^3 +eta(j)^2 - 2*xi(j)*eta(j) + 5;
multiplied(j) = evaluated(j)*weights(j);
end
GaussInt = sum(multiplied);
% Calculate the percentage error between the Gauss solution
% and the exact solution
Error = (GaussInt - ExactSol)/ExactSol*100;
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Numerical Integration and Differentiation についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!