How can I find the double integral using Trapezoidal rule?
Show older comments
I want to find the double integral of the following function (sin(x+3*y))^2*exp(x-2*y)/(x^2+2). Limits are x and y from -1 to 1.
N = 5;
x = linspace(-1, 1,N);
y = linspace(-1, 1,N);
dx = diff(x(1:2));
dy = diff(y(1:2));
[x,y] = meshgrid(x,y);
mat = (sin(x+3.*y)).^2.*exp(x-2.*y)/(x.^2+2);
mat(2:end-1,:) = mat(2:end-1,:)*2;
mat(:,2:end-1) = mat(:,2:end-1)*2;
out = sum(mat(:))*dx*dy/4
I edited this code to suit my function but it shows result as NaN with the following message:
In doubletraptest (line 7)
Warning: Matrix is singular to working precision
Accepted Answer
More Answers (0)
Categories
Find more on Numerical Integration and Differentiation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!