plotting a function on a (x,y) plane

I looked at different questions asked concerning the error message that I get but it did not help. I try to plot a function. Here is the code that I use ;

u[c_] := (c^(1 - σ) - 1)/(1 - σ)
h[s_] := (2 hbar)/(1 + Exp[η (1 - s/sbar)])
d[s_] := (b s^2)/2
ψ[k_] := ω + (1 - ω) Exp[-γ k]
co[a_] := x  (a^2)/2


The calibration I use ;

paramFinal1 = {σ -> 2.1, ρ -> 0.01, sbar -> 128, η -> 5.1, hbar -> 0.08, b -> 0.0001, γ -> 0.6, χ -> 0.025, ω -> 0.185, δ -> 0.015, x -> 0.14, β -> 0.8};


I wrote the following code ;

Here is the function that I try to plot on a $(k,s)$ plane

l[k_, s_] :=   u'[χ/β s] - β (h'[s]/(ρ + h[s]) ((u[χ/β s] - ψ[k] d[s] - co[δ k]  )/(χ + (ρ + h[s]))) + ( ψ[k] d'[s])/(χ + (ρ + h[s])))


I write

sol3[i_] := Solve[l[k, i] == 0 /. paramFinal1, k]
tab = Table[sol3[i], {i, 1, 300}];
pollutiondot0 = Last /@ Flatten[tab] // ListPlot


But the code generates the following error messages ;

Solve::inex: Solve was unable to solve the system with inexact coefficients or the system obtained by direct rationalization of inexact numbers present in the system. Since many of the methods used by Solve require exact input, providing Solve with an exact version of the system may help. >> General::stop: Further output of Solve::inex will be suppressed during this calculation. >>

How can I fix it ? What could be the problem ? Thanks in advance.

• Try using exact numbers e.g. instead of p -> 0.01 use p -> 1/100. You can use Rationalize[] to convert your parameters automatically. – Sascha Jan 2 '16 at 16:02
• You also might try to use NSolve instead of Solve to find a numerical solution – Sascha Jan 2 '16 at 16:11
• This is a question about Solve and NSolve, not a question about plotting. – march Jan 2 '16 at 16:14

u[c_] := (c^(1 - σ) - 1)/(1 - σ);
h[s_] := (2 hbar)/(1 + Exp[η (1 - s/sbar)]);
d[s_] := (b s^2)/2;
ψ[k_] := ω + (1 - ω) Exp[-γ k];
co[a_] := x (a^2)/2;

paramFinal1 = {σ -> 2.1, ρ -> 0.01, sbar -> 128, η -> 5.1,
hbar -> 0.08, b -> 0.0001, γ -> 0.6, χ -> 0.025,
ω -> 0.185, δ -> 0.015, x -> 0.14, β -> 0.8};

l[k_, s_] :=
u'[χ/β s] - β (h'[
s]/(ρ +
h[s]) ((u[χ/β s] - ψ[k] d[s] -
co[δ k])/(χ + (ρ + h[s]))) +
(ψ[k] d'[s])/(χ + (ρ + h[s])));


Use NSolve and since you are using a numeric technique, restrict sol3 to numeric arguments

sol3[i_?NumericQ] :=
{i, k} /. NSolve[l[k, i] == 0 /. paramFinal1, k, Reals]


For many values of i there is a single solution, e.g.,

sol3[1]

(*  {{1, -22.6603}}  *)


However, for some values of i there are two solutions, e.g.,

sol3[100]

(*  {{100, -2.37307}, {100, 133.086}}  *)

tab = Table[sol3[i], {i, 1, 300}];

ListLinePlot[
Flatten[#, {1}] & /@ {Last /@ tab, First /@ Select[tab, Length[#] == 2 &]},
PlotLegends -> Automatic]


• Thanks for this insightful code. – optimal control Jan 3 '16 at 21:51