Question about Integrating a 2D matrix that depends on 3 variables
조회 수: 1 (최근 30일)
이전 댓글 표시
I have a question about numeric integration specfically trying to compute the integral form below. I have a function in a general form of
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/274548/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/274549/image.png)
where
is a first order Bessel function of the 0th order and i is the complex number. If I understand this correctly - to integrate this function numerically over two variables k and z I put this function, f(r,L) into a for loop for every value of r and compute the double integral. The issue is I don't think I did this correctly code wise since I am trying to avoid any use of symbolic equations which most other posts use.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/274550/image.png)
for NN = 1:length(r)
Val = r(NN)
for MM = 1:length(z)
Temp(MM) = (integral(@(K) K.*MAS(K).*f(K,z(MM),Val),0,1));
end
Intval(NN) = sum(Temp);
end
My idea is to loop through all values of r, in this case a 1D vector, and then do the same for each value of z and then sum up all values for each value of z at a particular r which is the second integral. Is this the correct way to go about a numerical double integral?
If anyone has insight or a way to do this using the function integral2 it would be greatly appriciated since I am really having a problem solving this integral correctly.
댓글 수: 0
답변 (1개)
darova
2020년 3월 2일
I used numerical calculations
kk = linspace(0,1,20);
zz = linspace(0,10,20);
rr = linspace(0,15,20);
dk = kk(2)-kk(1);
dz = zz(2)-zz(1);
[K,Z,R] = meshgrid(kk,zz,rr);
b = 0.2;
J0 = 1.5;
C = 1.2;
A = -2;
G = 1.1;
f1 = 1 - exp(-b.*(K.*Z).^2).*J0.*([1-(1-b).*Z-1i*C*Z].*K.*R);
F = A*exp(-b*K.*G.*f1);
RES = sum(sum(F,1),2);
RES = RES(:)*dk*dz;
plot(rr,RES)
This how course integration works
x = linspace(0,10,20);
y = sin(x);
dx = x(2)-x(1);
disp('course integration')
sum(y)*dx
disp('trapz integration')
trapz(x,y)
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!