Professional Documents
Culture Documents
METODE NUMERIK
OLEH :
RISAL GUNAWAN
F1B314012
KENDARI
2017
1. Kode MATLAB function splineCurf
function k = splineCurv(xData, yData)
% Returns curvatures of a cubic spline at the knots.
% USAGE: k = splineCurv(xData,yData)
% xData = x-coordinates of data points.
% yData = y-coordinates of data points.
n = length(xData);
c =zeros(n-1,1);d=ones(n, 1);
e =zeros(n-1,1);k=zeros(n, 1);
c(1:n-2) = xData(1:n-2) - xData(2:n-1);
d(2:n-1) = 2*(xData(1:n-2) - xData(3:n));
e(2:n-1) = xData(2:n-1) - xData(3:n);
k(2:n-1) = 6*(yData(1:n-2) - yData(2:n-1))...
./(xData(1:n-2) - xData(2:n-1))...
- 6*(yData(2:n-1) - yData(3:n))...
./(xData(2:n-1) - xData(3:n));
[c,d,e] = LUdec3(c, d ,e);
k = LUsol3(c ,d, e, k);
i = findSeg(xData, x);
h = xData(i) - xData(i+1);
y = ((x - xData(i+1))^3/h - (x - xData(i+1))*h)*k(i)/6.0...
- ((x - xData(i))^3/h - (x - xData(i))*h)*k(i+1)/6.0...
+ yData(i)*(x - xData(i+1))/h...
- yData(i+1)*(x - xData(i))/h;
function i = findSeg(xData, x)
% Returns index of segment containing x.
iLeft = 1; iRight = length(xData);
while 1
if (iRight - iLeft) <= 1
i = iLeft; return
end
i = fix((iLeft + iRight)/2);
if x < xData(i)
iRight = i;
else
iLeft = i;
end
end
X 1 2 3 4 5
y 0 1 0 1 0
Komputasi numerik
xData = [1; 2; 3; 4; 5];
yData = [0; 1; 0; 1; 0];
k = splineCurv(xData,yData);
while 1
x = input('x = ');
if isempty(x)
fprintf('Done'); break
end
y = splineEval(xData,yData,k,x)
fprintf('\n')
end
Running the program produces the following results:
x = 2.5
y=
0.4464
x = 3.5
y=
0.4464
x = 4.5
y=
0.7679
Perhitungan Manual
x=2,5
k1 k
f1,2 x x x2 x x2 2 x x1 x x 1 y1 x x2 y2 x x1
3 3
6 6
0 4, 285
y 2,5 f1,2 2,5 2,5 2 2, 5 2 2,5 1 3 2,5 1
3
6 6
0 2,5 2 1 2,5 1
4, 285
0 3,375 1,5 0 1,5
6
4, 285
0
6
1,875 1,5
4, 285
3,375
6
14, 4618
6
2, 4103
x=3,5
0 4, 285
y 3,5 f1,2 3, 5 3,5 2 3,5 2 3,5 1 3 3,5 1 0 3,5 2 1 3,5 1
3
6 6
4, 285
0 15, 625 2,5 0 2,5
6
4, 285
6
13,125 2,5
4, 285
15, 625
6
66,531
6
11, 0885
x=4,5
0 4, 285
y 4,5 f1,2 4,5 4,5 2 4,5 2 4,5 1 4,5 1 0 4,5 2 1 4,5 1
3 3
6 6
4, 285
0 42,875 4,5 0 4,5
6
4, 285
6
38,375 4,5
4, 285
42,875
6
183, 719
6
30, 619
4. Gunakan data pada example 3.6 untuk menghitung nilai y
pada x=1.6, x=2.6(secara manual dan komputasi numerik).
Komputasi numerik
xData = [0; 1; 2; 3];
yData = [1; 1; 0.5; 0];
k = splineCurv(xData,yData);
while 1
x = input('x = ');
if isempty(x)
fprintf('Done'); break
end
y = splineEval(xData,yData,k,x)
fprintf('\n')
end
Running the program produces the following results:
x = 1.6
y=
0.7320
x = 2.6
y=
0.1888
Perhitungan Manual
i 1
x x2 2
k k ( x x1 ) 2 y y
f "i ,i 1 x i 3 x1 x2 2 ( x1 x2 ) 1 2
6 x1 x2 6 x1 x2 x1 x2
k1 k y y
x1 x2 2 x1 x2 1 2 0
3 6 x1 x2
or
y1 y2
2k1 k2 6
x1 x2
2
y1 y2 0
2k1 k 0
i 3, x 1.6
k3 k
f '3.4 1.6 x x4 x x4 4 ( x x3 )3 x x3 y3 x x4 y4 x x3
3
6 6
0.2308 0
'3.4 1.6 1.6 3 1.6 3 (1.6 2)3 1.6 2 0.5 1.6 3 0 1.6 2
3
f
6 6
0.2308 0
'3.4 1.6 1.4 1.4 (0.4)3 0.4 0.5 1.4 0 0.4
3
f
6 6
0.2308
f '3.4 1.6 1,344 0 0.7 0
6
f '3.4 1.6 0.65
i 3, x 2.6
k3 k
f '3.4 2.6 x x4 x x4 4 ( x x3 )3 x x3 y3 x x4 y4 x x3
3
6 6
0.2308 0
f '3.4 2.6 2.6 3 2.6 3 (2.6 2)3 2.6 2 0.5 2.6 3 0 2.6 2
3
6 6
0.2308 0
f '3.4 2.6 0.4 0.4 (0.6)3 0.6 0.5 0.6 0 0.6
3
6 6
0.2308
f '3.4 2.6 0.336 0 0.3 0
6
f '3.4 2.6 0.313
x = 1.5
y=
0.7679
x = 4.5
y=
0.7679
y=
x = 0.1
y=
0.2742
x = 0.2
y=
0.5440
x = 0.3
y=
0.8047
x = 0.4
y=
1.0520
x = 0.5
y=
1.2813
x = 0.6
y=
1.4880
x = 0.7
y=
1.6677
x = 0.8
y=
1.8160
x = 0.9
y=
1.9283
x=1
y=
x = 1.1
y=
2.0282
x = 1.2
y=
2.0160
x = 1.3
y=
1.9677
x = 1.4
y=
1.8880
x = 1.5
y=
1.7813
x = 1.6
y=
1.6520
x = 1.7
y=
1.5048
x = 1.8
y=
1.3440
x = 1.9
y=
1.1743
x=2
y=
1
Nomor11
xData = [1; 2; 3; 4; 5;];
yData = [13; 15; 12; 9; 13];
k = splineCurv(xData,yData);
while 1
x = input('x = ');
if isempty(x)
fprintf('Done'); break
end
y = splineEval(xData,yData,k,x)
fprintf('\n')
end
Running the program produces the following results:
x = 3.4
y=
10.2549
Nomor12
xData = [0.2; 0.4; 0.6; 0.8; 1.0];
yData = [1.150; 0.855; 0.377; -0.266; -1.049];
k = splineCurv(xData,yData);
while 1
x = input('x = ');
if isempty(x)
fprintf('Done'); break
end
y = splineEval(xData,yData,k,x)
fprintf('\n')
end
Nomor13
xData = [0.2; 20; 200; 2000; 20000];
yData = [103; 13.9; 2.72; 0.800; 0.401; 0.433];
k = splineCurv(xData,yData);
while 1
x = input('x = ');
if isempty(x)
fprintf('Done'); break
end
y = splineEval(xData,yData,k,x)
fprintf('\n')
end
Running the program produces the following results:
x=5
y=
80.3860
x = 50
y=
-78.8036
x = 500
y=
411.2887
x = 5000
y=
-1.9155e+003
Nomor 17
ReData = [0.2;2;20;200;2000;20000];
CdData = [103;13.9;2.72;0.800;0.401;0.433];
k = splineCurv(xData,yData);
while 1
x = input('x = ');
if isempty(x)
fprintf('Done'); break
end
y = splineEval(xData,yData,k,x)
fprintf('\n')
end
>> tugas17
x=5
y=
214.5685
x = 50
y=
4.2602e+05
x = 500
y=
4.5013e+08
x = 5000
y=
4.5257e+11