Anda di halaman 1dari 1

Penyelesaian akar2 persamaaan karakteristik

1. Metode Bisection
function bisection(pers, xa, xb)
fa=pers(xa)
fb=pers (xb)
if fa*fb<0 then
err=1;
i=1;
while (err>1E-5)
xc=(xa+xb)/2;
fc=pers(xc);
tampil=[i,xa,xb,xc,fc]

if fc*fa<0 then xb=xc;
else xa=xc;
end
err=abs(xa-xb);
disp(err,tampil);
i=i+1;
end
else disp("error, ganti xa dan xb")
end
endfunction
2. Metode Newton Raphson
function newrap(x, y)
i=1; r=1; s=1;
while (r<>0 & s<>0) //(abs(r)<>1E-7 & abs(s)<>1E-7)
F=x^2+x*y-10;
G=y+3*x*y^2-57;
dFx1=2*x+y;
dFx2=x;
dGx1=3*y^2;
dGx2=1+6*x*y;
Ratas=[-1*F dFx2; -1*G dGx2];
Satas=[dFx1 -1*F; dGx1 -1*G];
bawah=[dFx1 dFx2; dGx1 dGx2];
r=det(Ratas)/det(bawah);
s=det(Satas)/det(bawah);
//tampil=[F,G,x,s];
tampil=[i,x,y,r,s];
disp(tampil);
x=x+r;
y=y+s;
i=i+1;
end
endfunction
Penyelesaian persamaan linear serentak
1. Jacobi
function akar=jacobi(A, b)
epsilon=0.0000000000000001;
counter=0;
[baris kolom]=size(A);
x0=zeros(baris,1);
while %T
counter=counter+1;
for i=1:baris
sigma=0;
for j=1:kolom
if i~=j then
sigma=sigma+(A(i,j)*x0(j));
end
end
x1(i)=1/A(i,i)*(b(i)-sigma);
end
if abs(norm(x0-x1))>epsilon then
x0=x1;
else
break;
end;
end
akar=x0;
disp(counter);
endfunction
2. Gauss Seidel
function akar=jacobi(A,b)
epsilon=0.0000000000000001;
counter=0;
[baris kolom]=size(A);
x0=zeros(baris,1);
while %T
counter=counter+1;
for i=1:baris
sigma=0;
for j=1:kolom
if i~=j then
sigma=sigma+(A(i,j)*x0(j));
end
end
x1(i)=1/A(i,i)*(b(i)-sigma);
end
if abs(norm(x0-x1))>epsilon then
x0=x1;
else
break;
end;
end
akar=x0;
disp(counter);
endfunction
Penyelesaian persamaan non linear karakteristik
1. Metode Newton Raphson
function newton2(x)
pers=3*x-cos(x);
tur1=3+sin(x);
tur2=cos(x);
if abs(pers*tur2/tur1*tur1)<1 then
err=1;
i=1;
while (err>1E-7)
xn=x-(3*x-cos(x))/(3+sin(x));
err=x-xn;
tampil=[i, xn, err];
disp(tampil);
x=xn;
i=i+1;
end
else disp("error, ganti nilai tebakan awal");
end
endfunction
Interpolasi
1. Newton Gregory Forward
//input adalah matriks nilai x, matriks nilai f(x) dan
nilai x
//program bertujuan mencari nilai dari f(xs)
function ngf(X,Y,xs)
n=length(X) //nilai n didapat dari panjang matrik X
atas = 1.0;
bawah = 1.0;
//nilai h didapat dari x(n)-x(n-1)
//rumus ini berlaku jika h bersifat
equispaced(konstan)
h=X(2)-X(1);
//menampilkan tabel beda hingga
for i=1:n-1
tabel2(i,1)= Y(i+1)-Y(i);
end
for j=2:n-1
for i=1:n-j
tabel2(i,j)=tabel2(i+1,j-1)-tabel2(i,j-1);
end
end
s=(xs-X(1))/h;
y=Y(1)
disp(tabel2)

for k=1:n-1
atas = atas * (s-k+1);
bawah = bawah * k;
y=y+(atas/bawah)*tabel2(1,k);
end
disp(y, "Nilai f(xs)= ")
endfunction
2. Stirling
function y=stirling(xs)
fx=[4.90 5.00 5.243 5.467 5.689 5.887 6.03
6.288 6.489];
x=[1.0 1.25 1.5 1.75 2.0 2.25 2.5 2.75 3];
for i=1:length(fx)
table(1,i)=fx(i);
end

for i=1:length(fx)-1
for j=1:length(fx)-1
table(i+1,j)=table (i,j+1)-table(i,j);
end
end
n=round(length(fx)/2);
s=(xs-x(n))/(x(2)-x(1));
fxs=table(1,n);
for i=1:(length(fx)-1)/2

temp=1;
for j=1:i-1
temp=(s^2-j^2)*temp;
end
even=s^2*table(2*i+1,n-1)*temp/factorial(2*i);
odd=s*(table(2*i,n)+table(2*i,n-
1))*temp/(2*factorial(2*i-1));
n=n-1;
fxs=even+fxs+odd;
end
y=fxs;
endfunction
3. Langrange


Integrasi numeric
1. Metode Trapezoida
function Trapezoida()
n = input ("Banyak data yang dicari : ")
for i=1 : n
x(i) = input("Masukkan x"+string(i)+" :
");
f(i) = input("Masukkan f(x)"+string(i)+" :
");
end;

h=x(2)-x(1);
e=0;
for i=2:(n-1),
e=e+f(i);
end;

hasil=(h/2)*(f(1)+(2*e)+(f(n)));
disp (string(hasil));
endfunction

Anda mungkin juga menyukai