Search code examples
matlabsymbolic-mathintegralbessel-functions

Roots of implicit function including integral of modified Bessel function - symbolic variables not compatible with fzero


I'm trying to solve equation f for r, as below:

syms rho
C0 = 0.5;
a_bar = sqrt(-log((1-C0)/(1+C0)));
l = 0.77;
f = @(r) exp(-r^2)*int(rho*exp(-rho^2)*besseli(0,2*r*rho),rho,0,a_bar)-(l-1)*int(rho*exp(-rho^2),rho,0,a_bar);
r1 = fzero(f,1);

However the symbolic output from the first integral (containing besseli) is giving errors in fzero. The problem seems to be that besseli contains rho (when I remove this instance of rho I don't get any errors).

I've tried playing with subs and eval, and solving the entire thing as symbolic, but it's really been trial and error to be honest. I'm sure there's something simple that I'm missing - any help would be amazing!

Cheers,

Alan


Solution

  • As suggested by David in the comments to my question, including double within the function solves this problem; i.e:

    f = @(r) double(exp(-r^2)*int(rho*exp(-rho^2)*besseli(0,2*r*rho),rho,0,a_bar)-(l-1)*int(rho*exp(-rho^2),rho,0,a_bar));
    r1 = fzero(f,1);
    

    This works as it converts the symbolic expression (involving rho and r) into a numerical object. My equation doesn't have any roots but that's an issue with my working beforehand.

    Thanks again to David and Mad Physicist for the help on this.