1

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

alg
  • 11
  • 4
  • Relevant perhaps: http://www.mathworks.com/matlabcentral/newsreader/view_thread/113255? – Mad Physicist Nov 23 '15 at 05:08
  • Thanks @mad, I've tried using vectorize(inline(char(...))) within fzero and around the first integral in f but rho still remains in the equation. I guess that's the crux of my issue--the first definite integral is not integrating besseli, it stays as a symbolic expression, so rho isn't eliminated from the function as it should be. – alg Nov 24 '15 at 00:38
  • 1
    I don't think `fzero` works with symbolic input. You can define f` as `f=@(r) double( exp(-r^2)...);`, then `fzero` will work. I'm not sure `f` has any roots though... (unless l is greater than or equal to 1?) – David Nov 24 '15 at 02:17
  • That works! Thanks very much @David, I knew I was missing something simple. And you're right - it looks like my formula doesn't have any roots... that's the next challenge I guess. Thanks again – alg Nov 24 '15 at 10:27
  • Post an answer with what you found! Because `exp` is positive, `besseli` is positive, so since both terms are positive, the coefficient of the second term, `1-l` must be negative, which means `l` must be larger than one. (When `l=0`, the solutions are at r=infinity,-infinity) – David Nov 24 '15 at 22:18

1 Answers1

0

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.

alg
  • 11
  • 4