I'm trying to fit a function to data, but to make it go quicker I want to specify a starting point for Mathematica to start looking for the best fitting parameters. The equation I want to fit is:
SigmaBar[A_, Rs_][r_] := 4 r NIntegrate[rho[A, Rs][u r] u^2, {u, 0, 1}] + 4 NIntegrate[rho[A, Rs][u] u/(u + Sqrt[u^2 - r^2]), {u, r, Infinity}]
where
rho[A_, Rs_][r_] = (A 10^-3) r^(-1) (r + Rs)^(-2) Rs^(3);
I want to obtain starting values for two variables, $A$ and $R_s$. I have a list of values from my data for $\bar{\Sigma}$ and $r$, so I thought I could fill in two sets of those values (like $\bar{\Sigma}(r2)$, $r2$ and $\bar{\Sigma}(r4)$, $r4$), to solve for the $A$ and $R_s$. However, if I just use
Solve[{SigmaBar2 == SigmaBar[A, Rs][r2], SigmaBar4 == SigmaBar[A, Rs][r4]}, {A, Rs}]
I get an error saying that the integral in SigmaBar evaluated to non-numerical values (because A and Rs are not specified). Does anyone have an idea of how I can solve this?
I get an error saying that the integral in SigmaBar evaluated to non-numerical values (because A and Rs are not specified)
That is correct.Does anyone have an idea of how I can solve this?
. Yes. Give numerical values forA
andRs
andr
so thatNIntegrate
can work. Numerical integration can't integrate integrand which has unknown numerical values in them. Otherwise tryIntegrate
instead and see if that will work. $\endgroup$ClearAll[a,x]; NIntegrate[a*Sin[x], {x, -Pi, Pi}]
will give same error you had becausea
has no numerical value. $\endgroup$SigmaBar[A_?NumericQ, Rs_?NumericQ][r_?NumericQ] :=...
andrho[A_?NumericQ, Rs_?NumericQ][ r_?NumericQ] = (A 10^-3) r^(-1) (r + Rs)^(-2) Rs^(3);
$\endgroup$