1
votes

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

1
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
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
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
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

1 Answers

0
votes

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.