1
>> x=0:0.1:6; >> y=-((x-2).*(x-4).*(x-6)/48)-(x.*(x-4).*(x-6)/16)+(x.*(x-2).*(x-6)/ 16)+(x.*(x-2).*(x-4)/48); >> plot (x,y) >> grid >> hold on >> plot (0,1,'+r') >> plot (2,-1,'+r') >> plot (4,-1,'+r') >> plot (6,1,'+r') >> hold on >> x=0:0.1:6; >> y1=1-x+x.*(x-2)/4; >> plot (x,y1,'.g') >> title('Lagrange Interpolating Polynomial vs Newton Divided Difference') >> text(0,1,'(0,1)') >> text(2,-1,'(2,-1)') >> text(4,-1,'(4,-1)') >> text(6,1,'(6,1)')

Newton vs Langrange Coding

Embed Size (px)

DESCRIPTION

Newton vs Langrange Coding

Citation preview

Page 1: Newton vs Langrange Coding

>> x=0:0.1:6;

>> y=-((x-2).*(x-4).*(x-6)/48)-(x.*(x-4).*(x-6)/16)+(x.*(x-2).*(x-6)/16)+(x.*(x-2).*(x-4)/48);

>> plot (x,y)

>> grid

>> hold on

>> plot (0,1,'+r')

>> plot (2,-1,'+r')

>> plot (4,-1,'+r')

>> plot (6,1,'+r')

>> hold on

>> x=0:0.1:6;

>> y1=1-x+x.*(x-2)/4;

>> plot (x,y1,'.g')

>> title('Lagrange Interpolating Polynomial vs Newton Divided Difference')

>> text(0,1,'(0,1)')

>> text(2,-1,'(2,-1)')

>> text(4,-1,'(4,-1)')

>> text(6,1,'(6,1)')