Plotting a function with restrictions

I am trying to plot the following $$U_a=\frac{wXn_l}{n_a}+H$$ as a function of $$s$$ which is given by the expressions below, where I assign values to the constants

Clear["Global*"]
P=1
w=1;
x=2
nl=2
S=2
sigmaL=0
sigmaH=1
n=6
Sigmai=Subdivide[sigmaL,sigmaH,10]
g=(P*(S-s))/(w*x*nl);
sigma=(-(1-sigmaL*g)-(Sqrt[((1-(sigmaL*g))^2)-(4*g)]/(2*g)));
L=(sigma*P*(S-s))/(w*x*nl);
na=((n-nl)/(1+L));
nf=(L(n-nl))/(1+L);
H=If[s>= 0,H=0,H<= s];
ua=((w*x*nl)/(na))+H;

ua=Simplify[ua];

Plot[ua, sigma>0, {s,0,S}]


Though the output message requires more inputs. I'd like to further add the constraint that $$nl+na+nf=1$$ but I don't know if this should be defined independently or within the plot command.

• Plot[ua, sigma>0, {s,0,S}] is non-syntactic. Commented Jul 8, 2022 at 1:10

Perhaps this will work for you.

First let's find where sigma>0

P=1;w=1;x=2;nl=2;S=2;sigmaL=0;sigmaH=1;n=6;
Sigmai=Subdivide[sigmaL,sigmaH,10];g=(P*(S-s))/(w*x*nl);
sigma=(-(1-sigmaL*g)-(Sqrt[((1-(sigmaL*g))^2)-(4*g)]/(2*g)));
Reduce[sigma>0,s]


which returns

2<s<2*(2+Sqrt[2])


so that tells us what we need to tell Plot

L=(sigma*P*(S-s))/(w*x*nl);na=((n-nl)/(1+L));
nf=(L(n-nl))/(1+L);H=If[s>= 0,H=0,H<= s];
ua=((w*x*nl)/(na))+H;ua=Simplify[ua];
Plot[ua, {s,2,2*(2+Sqrt[2])}]


And that gives you your plot of ua where sigma>0.

Reduce[nl+na+nf==1]


that returns False

So I try

Simplify[nl+na+nf-1]


to see where that might be zero. That returns

5


so it doesn't look like that constraint can be satisfied.

• Oh this is very helpful for sigma. Thank you. For the additional constraint, they should sum to n, not 1, this was my mistake. But I'll try the same approach you suggested.
– ZR8
Commented Jun 12, 2021 at 21:30
• Ah, good. And now Simplify[nl+na+nf==n] returns True` so that constraint is always satisfied, at least if I haven't made any mistakes.
– Bill
Commented Jun 12, 2021 at 21:35
• The only thing is that the upper bound for s when sigma>0 is greater than S, and I have defined the maximum value that s takes as S, so I will just change the upper bound.
– ZR8
Commented Jun 12, 2021 at 21:42