# Restrict domain of a function?

I have a function f[x,y,...,z] and I want to restrict its range to positive numbers only, f > 0. f[x,y,...,z] is multivalued for some x,y,...,z and I cannot plot it for these values. How can I restrict the range?

To clarify, I don't want to restrict the range of a plot of the function, I want to restrict the range of the function itself.

I've tried Assuming[f>0, f[x,y,...,z]=(function)] but that hasn't helped.

Here is the definition of f, which I originally didn't supply because it's rather complicated:

f[∏, G, M, v, R, A, L] = Abs[1. v + (12.355667760004051 G M + 1235.5667760004053 M R)/(Sqrt[
1. + 0.0001 G^2] (Abs[(994964.5401209999 A^2 G M v)/Sqrt[
1. + 0.0001 G^2] + (9.949645401209998*^7 A^2 M R v)/Sqrt[
1. + 0.0001 G^2] -
1.0145762999999998*^7 A^2 \[CapitalPi] +
101457.62999999999 A^2 L \[CapitalPi] + \[Sqrt]((1.35*^7 \(12.023014199999999 A G M + 1202.30142 A M R)^3)/(1. +
0.0001 G^2)^(3/2) +
1/(10000. + 1. G^2)
9.899544360981928*^15 A^4 (1. G M v + 100. M R v +
0.10197110138986612 Sqrt[
1. + 0.0001 G^2] (-99.99999999999999 +
1. L) \[CapitalPi])^2)])^(1/3)) - 1/A 0.004315935432213702 (Abs[(994964.5401209999 A^2 G M v)/Sqrt[
1. + 0.0001 G^2] + (9.949645401209998*^7 A^2 M R v)/Sqrt[
1. + 0.0001 G^2] - 1.0145762999999998*^7 A^2 \[CapitalPi] +
101457.62999999999 A^2 L \[CapitalPi] + \[Sqrt]((
1.35*^7 (12.023014199999999 A G M +
1202.30142 A M R)^3)/(1. + 0.0001 G^2)^(3/2) +
1/(10000. + 1. G^2)

9.899544360981928*^15 A^4 (1. G M v + 100. M R v +
0.10197110138986612 Sqrt[
1. + 0.0001 G^2] (-99.99999999999999 +
1. L) \[CapitalPi])^2)])^(1/3)];


It's negative values of G (which are necessary to my project) that make the function multivalued (this is the function that solves $∏ = af^3+bf^2+cf+d$ for appropriate $a$,$b$,$c$,$d$.

This is the plot I am now getting:

As you can see Mathematica adds a straight line instead of graphing the function when it becomes multivalued. I even asked Mathematica for the value of the function at Pi=100 and got the value of that line, so Mathematica is defining the function weirdly, not just plotting it weirdly.

• Without the definition of f, it's hard to decide how you would go about doing this. Sep 4 '15 at 5:35
• I've updated it with the definition of f. Sep 4 '15 at 5:54
• But in MMA, all of the functions that you've shown are single-valued. It's hard to parse that expression of course, but is it that sometimes there are square roots of negative numbers? Sep 4 '15 at 5:59
• Since you're solving a cubic, did you look at the discriminant already? Sep 4 '15 at 6:04
• After checking a bit based on this, it's solving for the principal root of the cubed roots rather than the real-valued one. It now plots, but it's still having an issue plotting the multi-valuedness. I'm not sure what exactly in the function lets it be multivalued, but it definitely us as the graph should be a sideways cubic function. I've uploaded a picture (in which f=V). Sep 4 '15 at 6:35

Not an answer, but maybe this version of OP's function can be of use. The code in the question seems to have some artifacts that won't allow it to parse.

velocityAtPower[power_, grade_, mass_, windspeed_, resistance_, area_, losses_]:= windspeed-(1/area)(0.004315935432213702*Abs[-1.0145762999999998*^7*area^2*power+101457.63*area^2*losses*power+(994964.540121*area^2*grade*mass*windspeed)/Sqrt[1+0.0001*grade^2]+(9.949645401209998*^7*area^2*mass*resistance*windspeed)/Sqrt[1+0.0001*grade^2]+Sqrt[(1.35*^7*(12.0230142*area*grade*mass+1202.30142*area*mass*resistance)^3)/(1+0.0001*grade^2)^(3/2)+(9.899544360981928*^15*area^4*(0.10197110138986612*Sqrt[1+0.0001*grade^2]*(losses-100)*power+grade*mass*windspeed+100*mass*resistance*windspeed)^2)/(10000+grade^2)]]^(1/3))+(12.355667760004051*grade*mass+1235.5667760004053*mass*resistance)/(Sqrt[1+0.0001*grade^2]*Abs[-1.0145762999999998*^7*area^2*power+101457.63*area^2*losses*power+(994964.5401209999*area^2*grade*mass*windspeed)/Sqrt[1+0.0001*grade^2]+(9.949645401209998*^7*area^2*mass*resistance*windspeed)/Sqrt[1+0.0001*grade^2]+Sqrt[(1.35*^7*(12.0230142*area*grade*mass+1202.30142*area*mass*resistance)^3)/(1+0.0001*grade^2)^(3/2)+(9.899544360981928*^15*area^4*(0.10197110138986612*Sqrt[1+0.0001*grade^2]*(losses-100)*power+grade*mass*windspeed+100*mass*resistance*windspeed)^2)/(10000+grade^2)]]^(1/3))//Abs

velocityAtPower[100, -5, 82, 0, 0.003, 0.315, 3]
(*16.1447*)


Here's the code for OP's plot showing the issue with negative grade (G in the code above):

Manipulate[
Plot[velocityAtPower[P, G, M, v, R, A, L], {P, 0, 1500},
PlotRange -> {-25, 25},
AxesLabel -> {"Power (W)", "Velocity (m/s)"},
PlotLabel -> "Velocity at Power, P"],
{{G, 0, "Grade (%)"}, -20, 20},
{{M, 82, "Total Mass (kg)"}, 50, 125},
{{v, 0, "Wind Velocity (m/s)"}, -25, 25},
{{A, 0.315, "Effective Frontal Area (m^2)"}, 0.1, 1},
{{L, 3, "Drivetrain Loss (%)"}, 0, 5},
{{R, 0.003, "Coeff. of Rolling Resistance"}, 0.001, 0.006}]


The trouble seems to arise when this sub-expression under the square root goes negative:

Module[{f, vals = {power -> 100, mass -> 82, windspeed -> 0, resistance -> 0.003, area -> 0.315, losses -> 3}},
f = (1.35*^7 * (12.0230142 * area * grade * mass + 1202.30142 * area * mass * resistance)^3)/(1 + 0.0001 * grade^2)^(3/2) +
(9.899544360981928*^15 * area^4 * (0.10197110138986612 * Sqrt[1 + 0.0001*grade^2] * (losses - 100) * power + grade * mass * windspeed + 100 * mass * resistance * windspeed)^2)/(10000 + grade^2);
f = f/.vals;


After supplying definitions of $a$, $b$, $c$, and $d$, just define

f[pi_, G_, M_, v_, R_, A_, L_] =

In the documentation for Root, the solutions are ordered so that real roots come first (provided the $a$, $b$, $c$, and $d$ are real, I think).
So unless there is something really strange going on, this should yield correct results even when pi is taken small.