Symbolic integration inside numerical integration
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Gunnar
am 17 Mär. 2018
Kommentiert: Star Strider
am 20 Mär. 2018
I would like to solve the following integral numerically:
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 Kommentare
Akzeptierte Antwort
Star Strider
am 17 Mär. 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 Kommentare
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!