You are on page 1of 2

>> x=1:0.

1:6;
>> y=5+7.*(x-1)-1.333.*(x-1).*(x-2)+0.442.*(x-1).*(x-2).*(x-4);
>> y1=5+7.*(x-1)-1.333.*(x-1).*(x-2);
>> y2=12+3.*(x-2)+(7.*(x-2).*(x-4)/8);
>> y3=-((x-2).*(x-4).*(x-6)/3)+(3/2).*(x-1).*(x-4).*(x-6)...
-(3/2).*(x-1).*(x-2).*(x-6)+(31/40).*(x-1).*(x-2).*(x-4);
>> y4=(5/3).*(x-2).*(x-4)-6.*(x-1).*(x-4)+3.*(x-1).*(x-2);
>> y5=(3/2).*(x-4).*(x-6)-(9/2).*(x-2).*(x-6)+(31/8).*(x-2).*(x-4);
>> plot (x,y,'xg')
>> plot (x,y3)
>> plot (x,y,'xg')
>> hold on
>> plot (x,y3,'g')
>> hold on
>> plot (x,y1,'xr')
>> hold on
>> plot (x,y4,'r')
>> hold on
>> plot (x,y2,'xb')
>> hold on
>> plot (x,y5,'b')
>> hold on
>> plot (1,5,'.k')
>> plot (2,12,'.k')
>> plot (4,18,'.k')
>> plot (6,31,'.k')
>> grid
>> text(1,5,'(1,5)')
>> text(2,12,'(2,12)')
>> text(4,18,'(4,18)')

>> text(6,31,'(6,31)')
>> title('Lagrange Interpolating Polynomial vs Newtons Divided-Difference
Method')
>> xlabel('x-axis')
>> ylabel('y-axis')

You might also like