# how to plot this curve against the original function?

Clear["Global*"]

pts = {{1, 0}, {2, -1 + 2/E}, {3, -1 + 3/E^2}, {4, -1 + 4/E^3}};

p[x_] = a (x^3) + b (x^2) + c (x) + d;

print["p[x]=", p[x]];

eq1 = p == 0;

eq2 = p == -1 + 2/E;

eq3 = p == -1 + 3/E^2;

eq4 = p == -1 + 4/E^3;

eqns = {eq1, eq2, eq3, eq4};

vars = {a, b, c, d};

solset = Solve[eqns, vars];

Print[TableForm[eqns]];

Print["Solve and get"];

Print[solset];

p[x];

ReplaceAll[p[x],solset[]]; (*Note this is solset subscript [] but I didnt know how to write it onto here*)

p3[x_]=ReplaceAll[p[x],solset[]];(*Note this is solset subscript [] but I didnt know how to write it onto here, it is also p subscript 3*)

Needs["GraphicsColors"];

dots = ListPlot[pts, PlotStyle -> {Red,
PointSize[0.02]},

DisplayFunction -> Identity]
gr = Plot[[p3][x], {x, 1.0, 10.0}, PlotStyle -> Blue, DisplayFunction -> Identity]; (Note it is also p subscript 3)

graph1 = Show[gr, dots, PlotRange -> {{0, 10}, {-10, 3}},
Ticks -> {Range[0, 3, 1], Range[0, 3, 1]},
DisplayFunction -> \$DisplayFunction]


I am getting an error and the need function as well as there being an issue with posting my curve against the original functions curve. For now, I do see the curve plotted using the show function above but when I try to add the function before the beziur curve, it messes up.

• [p3][x] is invalid syntax. Try p3[x]. Oct 23, 2019 at 2:38
• yes I changed that but I get two errors: 1.Get: Cannot open GraphicsColors. and 2. Needs:Context GraphicsColors was not created when Needs was evaluated. It only prints out my Beziur curve Oct 23, 2019 at 3:05
• There is no need to load GraphicsColors or specify DisplayFunction. Oct 23, 2019 at 3:08
• took them out! I tried adding p[x] to my gr then showing that graph which just gave me what I already had. I then tried to put p[x] next to gr like this {p[x],gr,....} and got the error: graphs cant be combined Oct 23, 2019 at 3:19

You could try

Clear["Global*"]

pts = {{1, 0}, {2, -1 + 2/E}, {3, -1 + 3/E^2}, {4, -1 + 4/E^3}};
p[x_] := a (x^3) + b (x^2) + c (x) + d;
eq1 = p == 0;
eq2 = p == -1 + 2/E;
eq3 = p == -1 + 3/E^2;
eq4 = p == -1 + 4/E^3;
eqns = {eq1, eq2, eq3, eq4};
vars = {a, b, c, d};
solset = Solve[eqns, vars];
dots = ListPlot[pts, PlotStyle -> {Red, PointSize[0.02]}];
gr = Plot[p[x] /. solset, {x, 1.0, 10.0}, PlotStyle -> Blue];
graph1 = Show[gr, dots, GridLines -> Automatic, GridLinesStyle -> LightGray] Are you using very old version of Mathematica? Because you using very old commands there. The above is done on 11.3.

Also notice that show takes default options from the first graphics in its input. If you want the options taken from the second plot, you can change the order, or provide explicit options in Show itself

Clear["Global*"]

pts = {{1, 0}, {2, -1 + 2/E}, {3, -1 + 3/E^2}, {4, -1 + 4/E^3}};

p[x_] = a (x^3) + b (x^2) + c (x) + d;


Note that Print is seldom required

Column[StringForm["p(1) = 2", ##] & @@@ pts] // TraditionalForm (eqns = p[#[]] == #[] & /@ pts) // Column // TraditionalForm vars = Variables[Level[eqns, {-1}]];


Solve and get

(solset = Solve[eqns, vars][]) // Column // TraditionalForm Verifying the solution,

And @@ (eqns /. solset)

(* True *)

StringForm["p(x) = ", p[x] /. solset] // TraditionalForm or

StringForm["p(x) = ", p[x] /. solset // Simplify] // TraditionalForm The exact roots of p[x] are

(roots = Solve[p[x] == 0 /. solset, x] // SortBy[#, N] & //
FullSimplify) // Grid[#, Alignment -> Left] & // TraditionalForm The approximate numeric values of the roots are

roots // N // Grid[#, Alignment -> Left] & Plot[p[x] /. solset, {x, -0.5, 6.2},
Epilog -> {Red, PointSize[0.02], Point[pts]}]
` 