Integral of another integral
Show older comments
I want to integrate h1b_eta and then plot it (m1b_eta). However, h1b_eta depends on other functions that also contain integrals. How can I do this?
h1b_eta=@(eta) blablabla and some integrals;
m1b_eta=@(eta) pi*(airy(2,eta)*integral(@(n) airy(n)*h1b_eta(n),eta_infts,eta)-airy(eta)*integral(@(n) airy(2,n)*h1b_eta(n),eta0ts,eta));
V1VEC=arrayfun(m1b_eta,0:0.01:N);
plot(abs(V1VEC),0:0.01:N)
I want to do this symbollically because I need to integrate m1b_eta aftwerwards (this can now be done numerically)
Answers (1)
Walter Roberson
on 19 May 2017
Code h1b_eta as a symbolic function; then
syms m1b_eta(eta) n
Pi = sym('pi');
m1b_eta(eta) = Pi * (airy(2,eta)*int(airy(n)*h1b_eta(n),n,eta_infts,eta) - airy(eta)*int( airy(2,n)*h1b_eta(n),n,eta0ts,eta));
x = 0:0.01:N;
V1VEC = m1b_eta(x);
plot(x, V1VEC)
Possibly the call will not be enough because it might have to turn the integral into numeric; you might need to use
V1VEC = arrayfun(@(ETA) double(m1b_eta(ETA)), x);
Also, if your expression is complicated, you might wan to use vpaintegral() instead of int() for performance: if you do, be sure to specify the RelTol option to get enough accuracy for your purpose.
4 Comments
carlos g
on 19 May 2017
Walter Roberson
on 19 May 2017
integral2(@(x, y) airy(y), eta01, eta, eta01, @(x) x)
is
int(int(airy(y), y, eta01, x), x, eta01, eta)
You use the same form but different variables in the next line, so it might help to know that the general form
int(int(airy(y),y,A,x),x,A,B)
has a closed-form solution,
syms A B; GAMMA=@(x) gamma(sym(x)); Pi = sym('pi');
result = (1/sym(120))*(20*A*Pi*sym(3)^sym(1/3)*(A-2*B)*hypergeom(sym([1/3]), sym([4/3, 5/3]), (1/sym(9))*A^3)-30*A^2*sym(3)^(1/sym(6))*GAMMA(2/3)^2*(A-B)*hypergeom(sym([2/3]), sym([4/3, 5/3]), (1/sym(9))*A^3)+A^4*Pi*sym(3)^sym(1/3)*(A-B)*hypergeom(sym([4/3]), sym([7/3, 8/3]), (1/sym(9))*A^3)+20*B^2*sym(3)^sym(1/3)*Pi*hypergeom(sym([1/3]), sym([4/3, 5/3]), (1/9)*B^3)-60*sym(3)^sym(1/6)*GAMMA(2/3)^2*hypergeom(sym([-1/3]), sym([1/3, 2/3]), (1/9)*A^3)+60*sym(3)^sym(1/6)*GAMMA(2/3)^2*hypergeom(sym([-1/3]), sym([1/3, 2/3]), (1/9)*B^3))/(Pi*GAMMA(2/3))
Walter Roberson
on 22 May 2017
V1s(eta)=((i*alpha1*lambda_0)^(-1/3))*q1*integral2(@(x, y) airy(y),...
eta01, eta, eta01, @(x) x);
V2s(eta)=((i*alpha2*lambda_0)^(-1/3))*q2*integral2(@(x, y) airy(y),...
eta02, eta, eta02, @(x) x);
comes out as
GAMMA=@(x) gamma(sym(x)); Pi = sym('pi');
V1s(eta) = (1/3)*(eta-eta01)*(-(3/4)*3^(1/6)*(hypergeom([2/3], [4/3, 5/3], (1/9)*x^3)*x^2-eta01^2*hypergeom([2/3], [4/3, 5/3], (1/9)*eta01^3))*GAMMA(2/3)^2+Pi*3^(1/3)*(x*hypergeom([1/3], [2/3, 4/3], (1/9)*x^3)-eta01*hypergeom([1/3], [2/3, 4/3], (1/9)*eta01^3)))*q1/((I*alpha1*lambda_0)^(1/3)*Pi*GAMMA(2/3));
V2s(eta) = (1/6)*(-2*3^(1/3)*eta02*Pi*(eta-(1/2)*eta02)*hypergeom([1/3], [4/3, 5/3], (1/9)*eta02^3)+(3/2)*GAMMA(2/3)^2*3^(1/6)*eta02^2*(eta-eta02)*hypergeom([2/3], [4/3, 5/3], (1/9)*eta02^3)-(1/20)*Pi*3^(1/3)*eta02^4*(eta-eta02)*hypergeom([4/3], [7/3, 8/3], (1/9)*eta02^3)+Pi*hypergeom([1/3], [4/3, 5/3], (1/9)*eta^3)*3^(1/3)*eta^2+3*GAMMA(2/3)^2*hypergeom([-1/3], [1/3, 2/3], (1/9)*eta^3)*3^(1/6)-3*GAMMA(2/3)^2*3^(1/6)*hypergeom([-1/3], [1/3, 2/3], (1/9)*eta02^3))*q2/((I*alpha2*lambda_0)^(1/3)*Pi*GAMMA(2/3));
Categories
Find more on Numeric Solvers in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!