0% found this document useful (0 votes)
37 views22 pages

Tugas Komputasi Fisika Arianti (1006703263) Newton Polinomial 2

The document is a report in Indonesian on computational physics tasks. It contains the code for 5 polynomial interpolation problems using the Newton method. The code generates difference tables from given data points, calculates the coefficients, and plots the interpolation polynomials of increasing degree. Summary: 1) The code performs polynomial interpolation using Newton's method on 5 examples with increasing polynomial degree. 2) Difference tables are generated from sample data points and used to calculate coefficients of the interpolation polynomials. 3) The polynomials are plotted and their values evaluated to demonstrate the interpolation.

Uploaded by

Arianti Ari
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views22 pages

Tugas Komputasi Fisika Arianti (1006703263) Newton Polinomial 2

The document is a report in Indonesian on computational physics tasks. It contains the code for 5 polynomial interpolation problems using the Newton method. The code generates difference tables from given data points, calculates the coefficients, and plots the interpolation polynomials of increasing degree. Summary: 1) The code performs polynomial interpolation using Newton's method on 5 examples with increasing polynomial degree. 2) Difference tables are generated from sample data points and used to calculate coefficients of the interpolation polynomials. 3) The polynomials are plotted and their values evaluated to demonstrate the interpolation.

Uploaded by

Arianti Ari
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 22

Tugas Komputasi fisika

Arianti (1006703263)
Newton polinomial 2
% Tugas arianti
% program interpolasi dengan metode newton
% tanggal 5- 12 - 2011
clear all;
close all;
x=0:4;
y=[2.00000 2.23607 2.44949 2.64575 2.82843];
plot(x,y,'b-');
grid on
x0=0;
x1=1;
x2=2;
x3=3;
x=2.5;
a0=5;
a1=-2;
a2=0.5;
a3=-0.1;
a4=0.003;
a=[a0 a1 a2 a3]
% pendekatan linier
x0=1
p1 = a0 + a1.*(x-x0)
hold on;
plot(x,p1,'--r')
x1=2
p2 = a0 + a1.*(x-x0)+a2.*(x-x0).*(x-x1)
hold on;
plot(x,p2,'--g')
x2=3
p3 = a0 + a1.*(x-x0)+a2.*(x-x0).*(x-x1)+a3.*(x-x0).*(x-x1).*(x-x2)
hold on;
plot(x,p3,'--m')
x3=3
p4 = a0 + a1.*(x-x0)+a2.*(x-x0).*(x-x1)+a3.*(x-x0).*(x-x1).*(x-x2)+a4.*(xx0).*(x-x1).*(x-x2).*(x-x3)
hold on;
plot(x,p4,'--b')

a=

5.0000 -2.0000

x0 =

p1 =

0.5000 -0.1000

x1 =

p2 =

2.3750

x2 =

p3 =

2.4125

x3 =

p4 =

2.4131

Newton polinomial 4

% Tugas arianti
% program interpolasi dengan metode newton
% tanggal 5- 12 - 2011
clear all;
close all;
x=0:4;
y=[2.00000 2.23607 2.44949 2.64575 2.82843];
plot(x,y,'b-');
grid on
x0=-3;
x1=-1;
x2=1;
x3=4;
x=2;
a0=-2;
a1=4;
a2=-0.04;
a3=0.06;
a4=0.005;
a=[a0 a1 a2 a3]
% pendekatan linier
x0=-3
p1 = a0 + a1.*(x-x0)
x1=-1
p2 = a0 + a1.*(x-x0)+a2.*(x-x0).*(x-x1)
hold on;
plot(x,p2,'--g')
x2=1
p3 = a0 + a1.*(x-x0)+a2.*(x-x0).*(x-x1)+a3.*(x-x0).*(x-x1).*(x-x2)
hold on;
plot(x,p3,'--m')

x3=4
p4 = a0 + a1.*(x-x0)+a2.*(x-x0).*(x-x1)+a3.*(x-x0).*(x-x1).*(x-x2)+a4.*(xx0).*(x-x1).*(x-x2).*(x-x3)
hold on;
plot(x,p4,'--b')

a =
-2.0000
x0 =
-3
p1 =
18
x1 =
-1
p2 =

4.0000

-0.0400

0.0600

17.4000
x2 =
1
p3 =
18.3000
x3 =
4
p4 =
18.1500

Newton polinomial 5
% Tugas arianti
% mencari nilai difference
clear all;
close all;
x=0:4;
y=[2.00000 2.23607 2.44949 2.64575 2.82843];
plot(x,y,'b*');
grid on
n=length(x); %menghitung banyak data x
D=zeros(n,n); %membuat matrik kosong berukuran nxn
D(:,1)=y'
%
for j=2:n;
for k=j:n;
D(k,j)=(D(k,j-1)-D(k-1,j-1))./(x(k)-x(k-j+1))
end
end
a=diag(D);
a0=a(1,:)
a1=a(2,:)
a2=a(3,:)
a3=a(4,:)
a4=a(5,:)

%pendekatan linier
x0=4;
p1=a0+a1.*(x-x0)
hold on;
plot(x,p1,'--r')
x1=5;
p2=a0+a1.*(x-x0)+a2.*(x-x0).*(x-x1)
hold on;
plot(x,p2,'--g')
x2=6;
p3=a0+a1.*(x-x0)+a2.*(x-x0).*(x-x1)+a3.*(x-x0).*(x-x1).*(x-x2)
hold on;
plot(x,p3,'--m')
x3=7
p4 = a0 + a1.*(x-x0)+a2.*(x-x0).*(x-x1)+a3.*(x-x0).*(x-x1).*(x-x2)+a4.*(xx0).*(x-x1).*(x-x2).*(x-x3)
hold on;
plot(x,p4,'--b')

D=

2.0000

2.2361

2.4495

2.6458

2.8284

2.0000

2.2361

0.2361

2.4495

2.6458

2.8284

2.0000

2.2361

0.2361

2.4495

0.2134

2.6458

2.8284

D=

D=

D=

2.0000

2.2361

0.2361

2.4495

0.2134

2.6458

0.1963

2.8284

2.0000

2.2361

0.2361

2.4495

0.2134

2.6458

0.1963

2.8284

0.1827

D=

D=

2.0000

2.2361

0.2361

2.4495

0.2134 -0.0113

2.6458

0.1963

2.8284

0.1827

0
0

0
0

D=

2.0000

2.2361

0.2361

2.4495

0.2134 -0.0113

2.6458

0.1963 -0.0086

2.8284

0.1827

0
0

D=

2.0000

2.2361

0.2361

2.4495

0.2134 -0.0113

2.6458

0.1963 -0.0086

2.8284

0.1827 -0.0068

0
0

D=

2.0000

2.2361

0.2361

2.4495

0.2134 -0.0113

2.6458

0.1963 -0.0086

0.0009

2.8284

0.1827 -0.0068

0
0

0
0
0
0

D=

2.0000

2.2361

0.2361

2.4495

0.2134 -0.0113

2.6458

0.1963 -0.0086

0.0009

2.8284

0.1827 -0.0068

0.0006

0
0

0
0

D=

2.0000

2.2361

0.2361

2.4495

0.2134 -0.0113

2.6458

0.1963 -0.0086

0.0009

2.8284

0.1827 -0.0068

0.0006 -0.0001

a0 =

a1 =

0
0

0
0

0
0
0

0.2361

a2 =

-0.0113

a3 =

9.1500e-004

a4 =

-7.9583e-005

p1 =

1.0557

1.2918

1.5279

1.7639

2.0000

1.1559

1.4599

1.7413

2.0000

p2 =

0.8292

p3 =

0.7194

1.1010

1.4380

1.7358

2.0000

1.0723

1.4284

1.7339

2.0000

x3 =

p4 =

0.6526

Newton polinomial 5c
% Tugas arianti
% evaluate with x value
x=[4.5 7.5]
x0=4;
p1=a0+a1.*(x-x0)
hold on;
plot(x,p1,'--r')
x1=5;
p2=a0+a1.*(x-x0)+a2.*(x-x0).*(x-x1)
hold on;
plot(x,p2,'--g')
x2=6;
p3=a0+a1.*(x-x0)+a2.*(x-x0).*(x-x1)+a3.*(x-x0).*(x-x1).*(x-x2)
hold on;
plot(x,p3,'--m')

x3=7
p4 = a0 + a1.*(x-x0)+a2.*(x-x0).*(x-x1)+a3.*(x-x0).*(x-x1).*(x-x2)+a4.*(xx0).*(x-x1).*(x-x2).*(x-x3)
hold on;
plot(x,p4,'--b')

x=

4.5000

7.5000

p1 =

2.1180

2.8262

p2 =

2.1209

2.7272

p3 =

2.1212

2.7392

x3 =

p4 =

2.1213

2.7386

Newton polinomial 7
% Tugas arianti
% mencari nilai difference
clear all;
close all;
x=0:4;
y=[0.00 0.75 2.25 3.00 2.25];
plot(x,y,'b*');
grid on
n=length(x); %menghitung banyak data x
D=zeros(n,n); %membuat matrik kosong berukuran nxn

D(:,1)=y'
%
for j=2:n;
for k=j:n;
D(k,j)=(D(k,j-1)-D(k-1,j-1))./(x(k)-x(k-j+1))
end
end
a=diag(D);
a0=a(1,:)
a1=a(2,:)
a2=a(3,:)
a3=a(4,:)
a4=a(5,:)
%pendekatan linier
x0=0;
p1=a0+a1.*(x-x0)
hold on;
plot(x,p1,'--r')
x1=1;
p2=a0+a1.*(x-x0)+a2.*(x-x0).*(x-x1)
hold on;
plot(x,p2,'--g')
x2=2;
p3=a0+a1.*(x-x0)+a2.*(x-x0).*(x-x1)+a3.*(x-x0).*(x-x1).*(x-x2)
hold on;
plot(x,p3,'--m')
x3=3
p4 = a0 + a1.*(x-x0)+a2.*(x-x0).*(x-x1)+a3.*(x-x0).*(x-x1).*(x-x2)+a4.*(xx0).*(x-x1).*(x-x2).*(x-x3)
hold on;
plot(x,p4,'--b')

D =
0
0.7500
2.2500
3.0000
2.2500

0
0
0
0
0

0
0
0
0
0

0
0
0
0
0

0
0
0
0
0

0
0.7500
2.2500
3.0000
2.2500

0
0.7500
0
0
0

0
0
0
0
0

0
0
0
0
0

0
0
0
0
0

0
0.7500
2.2500
3.0000
2.2500

0
0.7500
1.5000
0
0

0
0
0
0
0

0
0
0
0
0

0
0
0
0
0

D =

D =

D =
0
0.7500
2.2500
3.0000
2.2500

0
0.7500
1.5000
0.7500
0

0
0
0
0
0

0
0
0
0
0

0
0
0
0
0

0
0.7500
2.2500
3.0000
2.2500

0
0.7500
1.5000
0.7500
-0.7500

0
0
0
0
0

0
0
0
0
0

0
0
0
0
0

0
0.7500
2.2500
3.0000
2.2500

0
0.7500
1.5000
0.7500
-0.7500

0
0
0.3750
0
0

0
0
0
0
0

0
0
0
0
0

0
0.7500
2.2500
3.0000
2.2500

0
0.7500
1.5000
0.7500
-0.7500

0
0
0.3750
-0.3750
0

0
0
0
0
0

0
0
0
0
0

0
0.7500
2.2500
3.0000
2.2500

0
0.7500
1.5000
0.7500
-0.7500

0
0
0.3750
-0.3750
-0.7500

0
0
0
0
0

0
0
0
0
0

0
0.7500
2.2500
3.0000
2.2500

0
0.7500
1.5000
0.7500
-0.7500

0
0
0.3750
-0.3750
-0.7500

0
0
0
-0.2500
0

0
0
0
0
0

D =

D =

D =

D =

D =

D =
0
0.7500
2.2500
3.0000
2.2500

0
0.7500
1.5000
0.7500
-0.7500

0
0
0.3750
-0.3750
-0.7500

0
0
0
-0.2500
-0.1250

0
0
0
0
0

0
0.7500
2.2500
3.0000
2.2500

0
0.7500
1.5000
0.7500
-0.7500

0
0
0.3750
-0.3750
-0.7500

0
0
0
-0.2500
-0.1250

0
0
0
0
0.0313

0.7500

1.5000

2.2500

3.0000

D =

a0 =
0
a1 =
0.7500
a2 =
0.3750
a3 =
-0.2500
a4 =
0.0313
p1 =
0
p2 =

0.7500

2.2500

4.5000

7.5000

0.7500

2.2500

3.0000

1.5000

0.7500

2.2500

3.0000

2.2500

p3 =

x3 =
3
p4 =

Newton polinomial 7c
% Tugas arianti
% evaluate with x value
x=[1.5 3.5]
x0=0;
p1=a0+a1.*(x-x0)
hold on;
plot(x,p1,'--r')
x1=1;
p2=a0+a1.*(x-x0)+a2.*(x-x0).*(x-x1)
hold on;
plot(x,p2,'--g')
x2=2;
p3=a0+a1.*(x-x0)+a2.*(x-x0).*(x-x1)+a3.*(x-x0).*(x-x1).*(x-x2)
hold on;
plot(x,p3,'--m')
x3=3
p4 = a0 + a1.*(x-x0)+a2.*(x-x0).*(x-x1)+a3.*(x-x0).*(x-x1).*(x-x2)+a4.*(xx0).*(x-x1).*(x-x2).*(x-x3)
hold on;
plot(x,p4,'--b')

x =
1.5000

3.5000

p1 =
1.1250

2.6250

p2 =
1.4063

5.9063

p3 =
1.5000
x3 =
3
p4 =

2.6250

1.5176

2.8301

You might also like