1

How can I be able to setup a mathematica code using a Vandermonde matrix? We had to plot the interpolated polynomial and regular polynomial. I had this but we aren't supposed to use the built-in interpolating polynomial function:

P = f[x_] = 1/(1 + x^2);
IP = InterpolatingPolynomial[{-2, -1, 0, 1, 2}, P];
ipplot = Plot[IP, {x, -2, 2}];
polyplot = Plot[P, {x, -2, 2}];
Bob Duncan
  • 11
  • 1
  • 2
    There's an example right here in the Wolfram documentation - I've given a direct link to the point on the page https://wolfram.com/xid/0scs1tumhqxdfkwj-ijwd8o – flinty Jun 16 '20 at 00:40

1 Answers1

3
SeedRandom[1234567];
points = Table[{i, RandomReal[]}, {i, 1, 10}];
degree = 10;
vmdmtx = Table[points[[i, 1]]^j, {i, 1, Length[points]}, {j, 0, degree}];
coefficients = PseudoInverse[vmdmtx].points[[All, 2]];
terms = Array[Power[x, # - 1] &, degree + 1];
polynomial = Dot[coefficients, terms];
Show[
 Plot[polynomial, {x, 1, 10}],
 ListPlot[points, PlotStyle -> Red]
]

interpolation

flinty
  • 25,147
  • 2
  • 20
  • 86