2
$\begingroup$

I would like to calculate/plot $min$ and $max$ values of a function whose parameters have finite intervals but I am receiving error messages as follows:

h = 0.7; cspeed = 299792.458; Omega\[CapitalLambda]0 = 0.7; Omegam0 = 0.3; Omega0 = 1.0002; 
Yp = Interval[0.2534 + 0.0083 {-1, 1}]; alpha = Interval[0.17 + 0.03 {-1, 1}]; logvc0 = Interval[1.58 + 0.05 {-1, 1}]; logvc1 = Interval[3.14 + 0.38 {-1, 1}]; beta = Interval[-0.50 + 0.18 {-1, 1}];

func1[Yp_] := func1[Yp] = (1 - Yp)*0.0462/0.281;
func2[z_?NumericQ] := func2[z] = (0.281*(1 + z)^3)/(0.281*(1 + z)^3 + 0.719);
func3[z_?NumericQ] := func3[z] = func2[z] - 1;
func4[z_?NumericQ] := func4[z] = (18*\[Pi]^2 + 82*func3[z] - 39*(func3[z])^2)/func2[z];
func5[z_?NumericQ, p_?NumericQ] := func5[z, p] = 96.6*((func4[z]*0.281*0.71^2)/24.4)^(1/6)*((1 + z)/3.3)^(1/2)*(10^(p - Log10[0.71] - 11))^(1/3);
func6[z_?NumericQ, p_?NumericQ, Yp_, alpha_, logvc0_, logvc1_, beta_] := func6[z, p, Yp, alpha, logvc0, logvc1, beta] = Log10[alpha] + Log10[func1[Yp]] + (beta + 1)*p + beta*(-11 + Log10[0.71]) - (Log[10])^-1*((10^logvc0/func5[z, p])^3 + (func5[z, p]/10^logvc1)^3);

Now would like to calculate $Min$ and $Max$ of the following function at values $z=0.03$ and $p=12$

func[z_?NumericQ, p_?NumericQ, Yp_, alpha_, logvc0_, logvc1_, beta_] := func[z, p, Yp, alpha, logvc0, logvc1, beta] = Derivative[0, 1, 0, 0, 0, 0, 0][func6][z, p, Yp, alpha, logvc0, logvc1, beta] // N;

using this line of code:

Min[func[0.03, 12, Yp, alpha, logvc0, logvc1, beta]]
Max[func[0.03, 12, Yp, alpha, logvc0, logvc1, beta]]

which doesn't give me any numerical answer.

!(*SuperscriptBox[(func6), * TagBox[ RowBox[{"(", RowBox[{"0", ",", "1", ",", "0", ",", "0", ",", "0", ",", "0", ",", "0"}], ")"}], Derivative], MultilineFunction->None])[0.03, 12., Interval[{0.2451, 0.2617}], Interval[{0.14, 0.2}], Interval[{1.53, 1.63}], Interval[{2.76, 3.52}], Interval[{-0.68, -0.32}]]

The final goal is to plot them for any $p$ value as follows:

LogPlot[{Min[func[0.03, p, Yp, alpha, logvc0, logvc1, beta]],
Max[func[0.03, p, Yp, alpha, logvc0, logvc1, beta]]}, 
{M, 10.25, 12.95}, PlotRange -> {10^-3, 10^7.4}]
$\endgroup$
  • $\begingroup$ Thanks dear Feyre for the edit, $\endgroup$ – Benjamin Jul 29 '16 at 19:58
  • 1
    $\begingroup$ The result of dNgalaxiesdzWSB[] is an unevaluated Integral. In it, the function LocalSMF appears to not evaluate possibly due to the presence of the variable p. $\endgroup$ – Feyre Jul 29 '16 at 20:01
  • $\begingroup$ I could not speculate about that one. Is there anyway to integrate M without introducing such complexity? $\endgroup$ – Benjamin Jul 29 '16 at 20:05
  • $\begingroup$ I think @Feyre is hinting that the argument corresponding to M_?NumericQ for LocalSMF appears to be a nonnumeric variable p in dNgalaxiesdzWSB[] -- that is, perhaps you miscoded your functions. (They're very complicated, which will be discouraging to many users, BTW.) $\endgroup$ – Michael E2 Jul 29 '16 at 20:20
  • $\begingroup$ Just changed it to a MWE to be manageable. $\endgroup$ – Benjamin Jul 30 '16 at 0:05
2
$\begingroup$

Answer to the first part of your question.

It workes well, rationalizing the functions

(by the way, why do your use the double-definitions ":=" and "=" ? This makes only sense when exact the same parametervalues occur several times, That's not the case here)

    h = 0.7; cspeed = 299792.458; OmegaΛ0 = 0.7; Omegam0 = 
    0.3; Omega0 = 1.0002;
    Yp = Interval[0.2534 + 0.0083 {-1, 1}]; alpha = 
    Interval[0.17 + 0.03 {-1, 1}]; logvc0 = 
    Interval[1.58 + 0.05 {-1, 1}]; logvc1 = 
    Interval[3.14 + 0.38 {-1, 1}]; beta = Interval[-0.50 + 0.18 {-1, 1}];



    {func1[Yp_] = Rationalize[(1 - Yp)*0.0462/0.281, 0],
     func2[z_] =  Rationalize[(0.281*(1 + z)^3)/(0.281*(1 + z)^3 + 0.719), 0],
    func3[z_] = func2[z] - 1,
    func4[z_] = (18*π^2 + 82*func3[z] - 39*(func3[z])^2)/func2[z],
    func5[z_, p_] = 
                   Rationalize[
                   96.6*((func4[z]*0.281*0.71^2)/24.4)^(1/6)*((1 + z)/3.3)^(1/
                   2)*(10^(p - Log10[0.71] - 11))^(1/3), 0],
    func6[z_, p_, Yp_, alpha_, logvc0_, logvc1_, beta_] = 
          Rationalize[
                      Log10[alpha] + Log10[func1[Yp]] + (beta + 1)*p + 
          beta*(-11 + 
          Log10[0.71]) - (Log[
          10])^-1*((10^logvc0/func5[z, p])^3 + (func5[z, p]/
          10^logvc1)^3), 0]} // Simplify;

    func[z_, p_, Yp_, alpha_, logvc0_, logvc1_, beta_] = 
        Derivative[0, 1, 0, 0, 0, 0, 0][func6][z, p, Yp, alpha, logvc0, 
        logvc1, beta] // Simplify

    min1[p_] := Min[func[3/100, p, Yp, alpha, logvc0, logvc1, beta]]

    max1[p_] := Max[func[3/100, p, Yp, alpha, logvc0, logvc1, beta]]

    {min1[12], max1[12]} // N

    (*   {0.316285, 0.704958}    *)

    Plot[{min1[p], max1[p]}, {p, 10.25, 12.95}]

enter image description here

$\endgroup$
  • $\begingroup$ I think Rationalize isn't actually necessary here? $\endgroup$ – xzczd Mar 29 '17 at 7:04
  • $\begingroup$ That's true. Rationalize is not necessary. May be the problem was the definition with "SetDelayed" and usage of "?NumericQ". $\endgroup$ – Akku14 Mar 29 '17 at 11:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.