1
$\begingroup$

I found that to do hermite InterpolatingPolynomial
I need to write:

InterpolatingPolynomial[{{{1}, 2, 3}, {{2}, 6, 7, 8}}, x]

however,i need to apply it on a table:

 Table [{xi = a + (b - a)/n i ,  N[Round[10^7  f [xi]]/10^7],  
N[ N[Round[10^7  f2 [xi]]/10^7]]}, {i, 0, n}]  ]

so how can i do that?

thanks.

$\endgroup$
1
$\begingroup$

you have it close, just need an extra {} on the x term: ( making up a simple example..)

n = 4; a = 0; b = 1; f[x_] := 10^12 Sin[2 x] ; f2[x_] := 10^12 Cos[x] ;
poly = InterpolatingPolynomial[
   Table[{{xi = a + (b - a)/n i}, N@Round[ f[xi], 10^7], 
     N@Round[f2[xi], 10^7]}, {i, 0, n}], x] // Simplify

0.+ 1.*10^12 x + 6.76392*10^13 x^2 - 7.54631*10^14 x^3 + 3.6613*10^15 x^4 - 9.58558*10^15 x^5 + 1.44937*10^16 x^6 - 1.26549*10^16 x^7 + 5.91826*10^15 x^8 - 1.14596*10^15 x^9

Plot[{f[x], poly}, {x, 0, 1}, 
 PlotStyle -> {Thickness[.01], {Thin, Red}}]

enter image description here

I cleaned things up using the 2 arg form of Round.

You should notice I deliberately fed it the wrong derivative just for illustration, otherwise you get a perfect fit for this example.

Edit: if you already have the table of the form

 table={{x1,f[x1],fp[x1]},{x2,f[x2],fp[x2]},...}

you do like this to add in the { }:

 InterpolatingPolynomial[{List@First@#, Sequence @@ Rest@#} & /@ table, x]
| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.