# Issue with variables/functions in solving equations

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;
p2=1;
F = 0.95;

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

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

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


Result:

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


Another try:

NSolve[
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]


Result:

Out[1057]= {{x -> 1.2635}}

• I get the same answer both times and a plot of FS2[x]-F agrees with the result. – Bill Watts Mar 2 at 23:39
• @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 12.0.0.0. – jpcgandre Mar 2 at 23:45
• 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. – Bill Watts Mar 3 at 0:02
• @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... – 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.