Skip to content

Instantly share code, notes, and snippets.

dividedDiff[f_, xs_]:=dividedDiff[f, xs]=Piecewise[{
{(dividedDiff[f, Drop[xs, 1]]-dividedDiff[f,Drop[xs, -1]])/(Last[xs]-First[xs]), First[xs]!=Last[xs]},
{(D[f[x], {x, Length[xs]-1}]/.x->First[xs])/(Length[xs]-1) !, First[xs]==Last[xs]}
}];
P[n_, f_, xks_, x_]:=Sum[dividedDiff[f,Take[xks,i]]*Product[x-xks[[j]], {j,1,i-1}], {i, 1, n+1}];
f1[x_]:=1/(1+x x);
xks1 = 0.2 * Range[0, 6];
polynomial1=Expand[P[6,f1,xks1,x]]
Plot[Abs[f1[x]-polynomial1], {x, 0, 1.2}]
@zdravkoandonov
zdravkoandonov / extended_spec.rb
Created December 1, 2015 18:13
A bit more extended spec for the sixth task @ Ruby Course @ FMI
describe 'TurtleGraphics' do
describe 'Turtle' do
describe '#draw' do
context 'No special canvas' do
describe '#move' do
it 'marks where the turtle has moved' do
canvas = TurtleGraphics::Turtle.new(2, 2).draw { move }
expect(canvas).to eq [[1, 1], [0, 0]]
end