You have several issues with your code.
1. First, you're evaluating some parts in floating-point. This isn't always bad as long as you know the solution will be exact. However, factorial(500)
overflows to Inf
. In fact, for factorial
, anything bigger than 170
will overflow and any input bigger than 21
is potentially inexact because the result will be larger than flintmax
. This calculation should be preformed symbolically via sym/factorial
:
n = sym(500);
f = factorial(n);
which returns an integer approximately equal to 1.22e1134
for f
.
2. You're using a period ('.'
) to specify multiplication. In MuPAD, upon which most of the symbolic math functions are based, a period is shorthand for concatenation.
Additionally, as is stated in the R2015a documentation (and possibly earlier):
String inputs will be removed in a future release. Use syms
to declare the variables instead, and pass them as a comma-separated list or vector.
If you had not used a string, I don't think that it would have been possible for your command to get misinterpreted and return such a confusing result. Here is how you could use solve
with symbolic variables:
syms r;
n = sym(500);
A = sym(1000000);
d = n/A;
s = solve(1==(d*sym(pi)*r^2)^n/factorial(n)*exp(-d*sym(pi)*r^2),r)
which, after several minutes, returns a 1,000-by-1 vector of solutions, all of which are complex. As @BenVoigt suggests, you can try the 'Real'
option for solve
. However, in R2015a at least, the four solutions returned in terms of lambertw
don't appear to actually be real.