# 2D Scalar plot of roots as function of parameters

Suppose I have a function of x with two parameters a,b : f(x;a,b).

I want to plot x'(a,b) where x' is the root of the above function .i.e f(x';a,b).

I know that for all a and b, the roots real.

How can I plot this over a range of a and b?

I feel like if I specify a resolution, then I'll just get a scatter plot of individual points. I'd like to get a smooth plot ideally.

• Please include an example function and the parameter ranges to get a concrete answer. Thanks.
– Syed
Feb 9 at 18:20

## 1 Answer

\$Version

(* "14.0.0 for Mac OS X ARM (64-bit) (December 13, 2023)" *)

Clear["Global*"]

f[x_, a_, b_] := a*x + b

root[a_, b_] = SolveValues[f[x, a, b] == 0, x][[1]]

(* -(b/a) *)


In 3D

Plot3D[root[a, b], {a, -5, 5}, {b, -6, 6},
AxesLabel -> (Style[#, 14] & /@ {a, b, root}),
ClippingStyle -> None]


In 2D

Plot[Evaluate@Table[
Tooltip[root[a, b], b], {b, -6, 6}],
{a, -5, 5},
AxesLabel -> (Style[#, 14] & /@ {a, root}),
PlotLegends -> LineLegend[Range[-6, 6],
LegendLayout -> {"Column", 2},
LegendLabel -> Style[b, 14]]]
`