Using trapz to find integral of a function in polar coordinates

2 次查看(过去 30 天)
I have an xy grid over which I define two cosine functions and try to find the integral of their product using trapz. Given the orthogonality of cosine function, i.e., integral of cos(n*theta)*cos(m*theta) = pi if n = m and 0 if n is not equal to m. However, using the following code, the results do not agree with this property. Can someone suggest me a way of doing this?
if true
x = linspace(-1,1,1000);
y = linspace(-1,1,1000);
[X, Y] = meshgrid(x, y);
[theta, r] = cart2pol(X, Y); %cartesian to polar coordinates
step = theta(1,2)-theta(1,1);
n = 4;
m = 8;
E1 = cos(n*theta);
E2 = cos(m*theta);
a = step*trapz(step*trapz(E1.*E2));
end
In this case a is not zero.

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Numerical Integration and Differentiation 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by