Question about converting integral formula to matlab code

I'm trying to code an integral formula as a sum of discrete data.
That seems correct, but the result is different.
Please let me know if there are any changes to my code.
Please let me know if there is a new way.
The code I made is below.
~~~~~~~~~~~~~~~~~~~~
for r = 1:M
for p = 1:N
for f0 = 1:M0
for p0 = 1:N0-1
PSI(r,p) = PSI(r,p)+...
(1/(pi^2*Rho0^2))*...
K0(f0)*...
d_K0*d_Phi0_rad*...
U(f0,p0)*...
(Rho0*(Rho0-Rho(r)*cos(Phi_rad(p)-Phi0_rad(p0)))/(Rho0^2-2*Rho0*Rho(r)*cos(Phi_rad(p)-Phi0_rad(p0))+Rho(r)^2))*...
(norm([Rho(r)*cos(Phi_rad(p)) Rho(r)*sin(Phi_rad(p))]-[Rho0*cos(Phi0_rad(p0)) Rho0*sin(Phi0_rad(p0))])^2)*...
(exp(2*1i*K0(f0)*((norm([Rho(r)*cos(Phi_rad(p)) Rho(r)*sin(Phi_rad(p))]-[Rho0*cos(Phi0_rad(p0)) Rho0*sin(Phi0_rad(p0))]))-Rho0)));
end
end
end
end

댓글 수: 6

Any reason why you don't use "integral2" ?
I didn't know such code existed...
I think you should set up your problem for the use with "integral2".
I thought about it, but it seems wrong to use that code.
Because U(f,pi) in term 4 is discrete matrix data of M0 by N0.
Therefore, U(f,pi) cannot be substituted into the corresponding code.
"integral2(fun,xmin,xmax,ymin,ymax)"
And, I missed that the result of the integral is not a specific value, but the N by M matrix data. * PIS(rho,phi)
It may be necessary to use integral iteratively with the 'ArrayValued' flag set if you are integrating an array. Check the inner integral before calculating the outer integral to be certain that it is doing what you want.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

도움말 센터File Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기

제품

릴리스

R2022a

질문:

2022년 9월 23일

댓글:

2022년 9월 23일

Community Treasure Hunt

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

Start Hunting!

Translated by