I am trying to Plot this code but it is not showing any plot. I want a bistable type plot between "NL" and "P0" and there are six equations and six unknowns. The code is given below,
delta = 4;
g0 = 1;
Pb = 2;
KL = 1;
kb = 0.2;
ome1 = 1;
gma = 0.02;
nth = 2;
sol[P0_?NumericQ] :=
NSolve[{I*P0*(Conjugate[a1] - a1) +
I*Pb*(Lf - Conjugate[Lf] + Conjugate[Bf] - Bf) - KL*NL -
kb*(Lf*a1 + Conjugate[Lf]*Conjugate[a1] + Bf*Conjugate[a1] +
Conjugate[Bf]*
a1 + (NL - 2*Abs[a1]^2)*(b1 + Conjugate[b1])) == 0,
I*g0*((NL - 2*Abs[a1]^2)*(Conjugate[b1] - b1) +
Conjugate[Lf]*Conjugate[a1] - Lf*a1 + Conjugate[Bf]*a1 -
Bf*Conjugate[a1]) +
I*Pb*(Conjugate[Bf] - Lf + Conjugate[Lf] - Bf) - gma*Nb +
gma*nth ==
0, -I*delta*Lf - I*ome1*Lf +
I*g0*((2*NL - Abs[a1]^2 - Nb + 2*Abs[b1]^2 + b1^2)*
Conjugate[a1] - (Conjugate[Bf] + 2*Lf)*b1 -
Lf*Conjugate[b1]) - I*P0*b1 == 0,
I*delta*Bf - I*ome1*Bf +
I*g0*((2*NL - Abs[a1]^2 + Nb - 2*Abs[b1]^2)*
a1 + (2*Bf - a1*b1 + Conjugate[Lf])*b1 + Bf*Conjugate[b1]) +
I*P0*b1 + I*Pb*(NL + Nb + a1^2 + b1^2 + 1) - (KL + gma)*Bf/2 -
kb/2*((2*Bf - a1*b1 + Conjugate[Lf])*b1 + (Nb - 2*Abs[b1]^2)*
a1 + Bf*Conjugate[b1]) == 0,
I*delta*a1 + I*delta*a1 + I*g0*(Conjugate[Lf] + Bf) + I*P0 +
I*Pb*(b1 + Conjugate[b1]) - KL*a1/2 -
kb*(Conjugate[Lf] + Bf)/2 == 0,
I*ome1*b1 + I*g0*NL + I*Pb*(a1 + Conjugate[a1]) - gma*b1/2 ==
0}, {a1, b1, NL, Lf, Bf, Nb}];
Plot[{NL /. sol[P0]}, {P0, 0, 30}]
This code is showing error like this;
NSolve::ivar: 0.07` is not a valid variable. >>
ReplaceAll::reps: {NSolve[{(0. +0. I)-NL+2 I (Times[<<2>>]+Lf+Conjugate[<<1>>]+Times[<<2>>])-0.2 (Times[<<2>>]+Times[<<2>>]+Times[<<2>>]+Times[<<2>>]+Times[<<2>>])==0,0.04 -0.02 b1 Conjugate[b1]+I (Times[<<2>>]+Times[<<2>>]+Times[<<2>>]+Times[<<2>>]+Times[<<2>>])+2 I (Times[<<2>>]+Times[<<2>>]+Conjugate[<<1>>]+Conjugate[<<1>>])==0,(0. -0.000612857 I) b1-5 I Lf+I (Times[<<3>>]+Times[<<2>>]+Times[<<3>>])==0,<<6>>+I (Times[<<2>>]+<<1>>+Times[<<2>>])==0,(-0.035+0.560613 I)+2 I (b1+Conjugate[<<1>>])-(0.1 -1. I) (Bf+Conjugate[<<1>>])==0,(0. +0.28 I)-(0.01 -1. I) b1+I NL==0},{0.07,b1,NL,Lf,Bf}]} is neither a list of replacement rules nor a valid dispatch table, and so cannot be used for replacing. >>
If anyone can resolve this will be appreciated.



P0in your NSolve which is symbolic. It doesn't matter that you use this in the Plot. You should changesoltosol[P0_?NumericQ] :=and plotPlot[{NL /. sol[P0]}, {P0, 0, 30}]. However this will take a very long time, and even a single point e.gsol[0.5]takes an unacceptably long time. You may get better performance byNMinimize-ing the sum of the Abs squared of all equations instead. i.e Abs[eq1]^2 + Abs[eq2]^2 + ... – flinty Jul 07 '20 at 14:25