Symbolic integration inside numerical integration
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I would like to solve the following integral numerically:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/171345/image.png)
As far as I can tell, the built-in function integral2 is not applicable here due to the nature of the expression. Instead, from Evaluating Double Integrals, I arrive at the following solution which takes forever to compute due to the third line:
syms x r
firstint=int(1./(1+x.^2.5),x,r,Inf)
answer=int(r.*exp(-r.^2).*firstint,r,0,Inf),
double(answer)
The last line is just to get a numerical answer out of the symbolic integration. To speed up things, I am inclined to replace the third line with the built-in function integral, but it requires me to make firstint into a handle first, for example by using another built-in function called matlabFunction. Unfortunately, I get an error when doing the following:
syms x r
firstint=int(1./(1+x.^2.5),x,r,Inf),
firstintHandle = matlabFunction(firstint),
answer=integral(r.*exp(-r.^2).*firstintHandle,0,Inf),
Any ideas on what to do? Please be very specific. Your help is greatly appreciated.
0 commentaires
Réponse acceptée
Star Strider
le 17 Mar 2018
See if this does what you want:
firstint = @(r) integral(@(x) 1./(1+x.^2.5), r, Inf, 'ArrayValued',1);
secondint = @(r) r.*exp(-r.^2).*exp(-firstint(r));
answer = integral(secondint, 0, Inf, 'ArrayValued',1)
answer =
0.274214226644371
The code appears to me to be correct. I defer to you to be certain it is.
6 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Calculus dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!