A question using trapz integration
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello all
I have a problem using the trapz integration. I’m trying to integrate this integral (in the attached file) using trapz twice when I’m trying to approximate the analytic solution to z = 0.

(For arctan(R/Z) far from pi/2 it is working ok). I’m taking z to be very small but final and it seems that the code I wrote doesn't handles it very well; I guess it is because tan diverges in pi/2.
(the analytic solution is pi*R^2)
Maybe there is another way to solve this problem?
Thanks
(In the next step I need to perform this integral where in the integrand I have a function which is dependent on theta and phi, And that is why I can’t just take the area of the circle)

The code I wrote:
theta_val_new = (round(linspace(0,pi./2,100).*100)/100)';
phi_val_new = linspace(0,2.*pi,120);
theta_val_mat = repmat(theta_val_new,1,120);
function_to_integrate = abs(tan(theta_val_mat)./(cos(theta_val_mat)).^2) .*(30./tan(theta_val_new(end,1))).^2;
energy1 = (trapz(phi_val_new,trapz(theta_val_new,function_to_integrate))
11 Kommentare
Lukas Bystricky
am 4 Aug. 2015
Bearbeitet: Lukas Bystricky
am 4 Aug. 2015
I see you added a second integral that can't be integrated exactly. Do you know if gamma is 0 at theta = pi/2 (for all phi)? If it isn't, then that integral is unbounded since Rz/cos^2(arctan(R/z)) goes to infinity as z goes to 0.
If you do wish to do this integral numerically for other values of z I agree with Torsten that integral2 is a much better route.
Antworten (0)
Siehe auch
Kategorien
Mehr zu Numerical Integration and Differentiation finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

