I've been posting some questions all around issues with defining and using variables/functions in Mathematica. Based on the answers/comments I got I still cannot make this simple code work... Why is this not working?

d1 = 50;
u22 = 1;
s22 = u22*0.25;
d2 = 1;
F = 0.95;

FS22[x_] := 
  CDF[GumbelDistribution[u22 - EulerGamma*s22*6^0.5/Pi, s22*6^0.5/Pi],

FS2[x_?NumericQ] := ((1 - p2)*UnitStep[x] + p2*FS22[x])^(d1/d2);

NSolve[F == FS2[x], x, Reals]


Out[1056]= NSolve[0.95 == FS2[x], x, Reals]

Another try:

 F == ((1 - p2)*UnitStep[x] + 
     p2*CDF[GumbelDistribution[u22 - EulerGamma*s22*6^0.5/Pi, 
        s22*6^0.5/Pi], x])^(d1/d2), x, Reals]


Out[1057]= {{x -> 1.2635}}
  • $\begingroup$ I get the same answer both times and a plot of FS2[x]-F agrees with the result. $\endgroup$ – Bill Watts Mar 2 at 23:39
  • $\begingroup$ @BillWatts Thank you for the feedback. I just restarted Mathematica and I don't get the same answer. I get what I show above. The version I'm working is $\endgroup$ – jpcgandre Mar 2 at 23:45
  • $\begingroup$ I use the same version. With the first result I get warning messages, but it spits out the answer, but slower than the second result. But both are the same. $\endgroup$ – Bill Watts Mar 3 at 0:02
  • $\begingroup$ @BillWatts I copy paste the code above in a new notebook and the result I get is NSolve[0.95 == FS2[x], x, Reals] Do you have any option activated or something that it can justify these different results? I just installed Mathematica yesterday... $\endgroup$ – jpcgandre Mar 3 at 0:10

First for general syntax tips, I highly suggest reading around here for syntax posts, there are lots of them. However this answer and others might be helpful.

With your code I suggest never using upper case letters as mathematica commands and code always starts with Capitals...though F is not one of them, get in the habit to start your variables with lowercase letters.

d1 = 50;
u22 = 1;
s22 = u22 0.25;
d2 = 1;
p2 = 1;
f = 0.95;

FS22[x_] := CDF[GumbelDistribution[u22 - EulerGamma s22 6^0.5/\[Pi], s22 6^0.5/\[Pi]], x]

FS2[x_] := ((1 - p2) UnitStep[x] + p2 FS22[x])^(d1/d2)

NSolve[f == FS2[x], x, Reals]

{{x -> 1.2635}}

This is what I had to do to modify your code to get it to work.

Namely I removed ?NumericQ.

| improve this answer | |

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.