Professional Documents
Culture Documents
142015100
Kelas B
NO 4)
EDITOR:
function[p,q,r,s]=natural_cubic_spline(t,y)
n=length(t)
p(n)=y(n)
a(1)=1
b(1)=0
c(1)=0
d(1)=0
ii=1;
while ii<=n-1
h(ii)=t(ii+1)-t(ii)
ii=ii+1
end
a(n)=1
b(n)=0
c(n)=0
d(n)=0
ii=2;
while ii<=n-1
a(ii)=2*(h(ii-1)+h(ii))
b(ii)=h(ii-1)
c(ii)=h(ii)
d(ii)=(3*(p(ii+1)-p(ii))/h(ii))-(3*(p(ii)-p(ii-1))/h(ii-1))
ii=ii+1;
end
[x]=Tridiagonal_Thomas (a,b,c,d)
ii=1
while ii<=n
r(ii)=x(ii)
ii=ii+1
end
ii=1
while ii<=n-1
s(ii)=(r(ii+1)-r(ii))/3*h(ii)
q(ii)=((p(ii+1)-p(ii))/h(ii))-(h(ii)*(2*r(ii)+r(ii+1))/3)
g(ii+1)=p(ii)+(q(ii)*h(ii))+(r(ii)*h(ii)^2)+(s(ii)*h(ii)^3)
Z(ii)=(2*r(ii))+(6*s(ii)*h(ii))
Z(ii)=0
ii=ii+1;
end
p
q
r
s
COMMAND WIDOW:
Columns 1 through 6
2 4 7 11 16 21
Columns 7 through 10
24 26 30 35
y=
Columns 1 through 6
15 20 17 13 18 24
Columns 7 through 10
25 23 19 12
>> function[p,q,r,s]=natural_cubic_spline(t,y)
function[p,q,r,s]=natural_cubic_spline(t,y)
>> [p,q,r,s]=natural_cubic_spline(t,y)
beta =
0 2
alfa =
1 10
ii =
beta =
0 2.0000 0.3000
alfa =
ii =
beta =
Columns 1 through 3
0 2.0000 0.3000
Column 4
0.3053
alfa =
Columns 1 through 3
Column 4
16.7786
ii =
beta =
Columns 1 through 3
0 2.0000 0.3000
Columns 4 through 5
0.3053 0.2980
alfa =
Columns 1 through 3
Columns 4 through 5
16.7786 18.5100
ii =
beta =
Columns 1 through 3
0 2.0000 0.3000
Columns 4 through 6
Columns 1 through 3
Columns 4 through 6
ii =
beta =
Columns 1 through 3
0 2.0000 0.3000
Columns 4 through 6
Column 7
0.2048
alfa =
Columns 1 through 3
Columns 4 through 6
Column 7
9.3856
ii =
beta =
Columns 1 through 3
0 2.0000 0.3000
Columns 4 through 6
0.2048 0.2131
alfa =
Columns 1 through 3
Columns 4 through 6
Columns 7 through 8
9.3856 11.5738
ii =
beta =
Columns 1 through 3
0 2.0000 0.3000
Columns 4 through 6
Columns 7 through 9
alfa =
Columns 1 through 3
Columns 4 through 6
Columns 7 through 9
ii =
10
beta =
Columns 1 through 3
0 2.0000 0.3000
Columns 4 through 6
Columns 7 through 9
Column 10
alfa =
Columns 1 through 3
Columns 4 through 6
Columns 7 through 9
1.0000
ii =
11
y=
ii =
y=
0 0
ii =
3
y=
0 0 0
ii =
y=
0 0 0 0
ii =
y=
0 0 0 0 0
ii =
y=
0 0 0 0 0 0
ii =
y=
Columns 1 through 6
0 0 0 0 0 0
Column 7
ii =
y=
Columns 1 through 6
0 0 0 0 0 0
Columns 7 through 8
0 0
ii =
y=
Columns 1 through 3
0 0 0
Columns 4 through 6
0 0 0
Columns 7 through 9
0 0 7.2000
ii =
10
y=
Columns 1 through 3
0 0 0
Columns 4 through 6
0 0 0
Columns 7 through 9
0 0 7.2000
Column 10
ii =
11
x=
Columns 1 through 6
0 0 0 0 0 0
Columns 7 through 10
0 0 0 0
ii =
x=
Columns 1 through 3
0 0 0
Columns 4 through 6
0 0 0
Columns 7 through 9
0 0 0.4333
Column 10
ii =
8
x=
Columns 1 through 3
0 0 0
Columns 4 through 6
0 0 0
Columns 7 through 9
0 -0.1497 0.4333
Column 10
ii =
x=
Columns 1 through 3
0 0 0
Columns 4 through 6
0 0 0
Columns 7 through 9
Column 10
ii =
x=
Columns 1 through 3
0 0 0
Columns 4 through 6
0 0 -0.0065
Columns 7 through 9
ii =
x=
Columns 1 through 3
0 0 0
Columns 4 through 6
0 0.0018 -0.0065
Columns 7 through 9
Column 10
ii =
4
x=
Columns 1 through 3
0 0 0
Columns 4 through 6
Columns 7 through 9
Column 10
ii =
x=
Columns 1 through 3
0 0 0.0002
Columns 4 through 6
Columns 7 through 9
Column 10
ii =
x=
Columns 1 through 3
0 -0.0000 0.0002
Columns 4 through 6
Column 10
ii =
x=
Columns 1 through 3
0 -0.0000 0.0002
Columns 4 through 6
Columns 7 through 9
Column 10
0
ii =
x=
-0.0000
0.0002
-0.0005
0.0018
-0.0065
0.0319
-0.1497
0.4333
x=
-0.0000
0.0002
-0.0005
0.0018
-0.0065
0.0319
-0.1497
0.4333
p=
Columns 1 through 6
0 0 0 0 0 0
Columns 7 through 10
0 0 0 12
q=
Columns 1 through 3
Columns 4 through 6
Columns 7 through 9
r=
Columns 1 through 3
0 -0.0000 0.0002
Columns 4 through 6
Columns 7 through 9
Column 10
s=
Columns 1 through 3
Columns 4 through 6
Columns 7 through 9
Columns 1 through 6
0 0 0 0 0 0
Columns 7 through 10
0 0 0 12
q=
Columns 1 through 3
Columns 4 through 6
Columns 7 through 9
r=
Columns 1 through 3
0 -0.0000 0.0002
Columns 4 through 6
Columns 7 through 9
Column 10
s=
Columns 1 through 3
Columns 4 through 6
Columns 7 through 9
EDITOR:
function[Ca]=bhingga_maju(fungsi,l,m,n,t,alfa)
fungsi=@(x)4*x-2*x^2
l=2
m=2
n=2
alfa=1.5
t=2
h=l/m;
k=t/n;
lamda=(alfa^2*k)/h^2;
ii=1
while ii<=m+1
x(ii+1)=ii*h;
C(ii,1)=fungsi(x(ii));
ii=ii+1;
end
ii=1;
while ii<=m+1
A(ii,ii)=1-2*lamda;
A(ii+1,ii)=lamda;
A(ii,ii+1)=lamda;
ii=ii+1;
end
ii=1;
while ii<=m+1
CC(ii)=C(ii,1);
ii=ii+1;
end
ii=1;
while ii<=m+1
jj=1;
Ca(ii)=0;
while jj<=n+1
Ca(ii)=Ca(ii)+CC(ii)*A(ii,jj);
jj=jj+1;
end
ii=ii+1;
end
Ca
COMMAND WINDOW:
bhingga_maju
fungsi =
@(x)4*x-2*x^2
l=
m=
n=
alfa =
1.5000
t=
ii =
Ca =
0 2 0
ans =
0 2 0
>>
NO 3)
EDITOR:
NO 1)
EDITOR: