Senin, 11 Mei 2015

Source Code Scilab untuk Menggambar Grafik Interpolasi

INTERPOLASI LANJAR
Data tabulasi jumlah penduduk Purworejo
Tahun                           2000        2010
Jumlah Penduduk         187900     205700

SOURCE CODE
function y=f(x0,y0,x1,y1,x)
    y=y0+((y1-y0)/(x1-x0))*(x-x0);
endfunction

x0=2000;
y0=187900;
x1=2010;
y1=205700;

j=1;
for i=x0-5:0.1:x1+5
    tx(j)=i;
    ty(j)=f(x0,y0,x1,y1,i);
    j=j+1;
end
plot(tx,ty);
plot(x0,y0,'or');
plot(x1,y1,'og');

INTERPOLASI KUADRATIK
Data tabulasi jumlah penduduk Purworejo
Tahun                        2000        2010        2012
Jumlah Penduduk      180700    205700    190000

SOURCE CODE
function y=f(x0,y0,x1,y1,x2,y2,x)
    y=(y1*(((x-x1)*(x-x2))/((x0-x1)*(x0-x2))))+(y1*(((x-x0)*(x-x2))/((x1-x0)*(x1-x2))))+(y2*(((x-x0)*(x-x1))/((x2-x0)*(x2-x1))));
endfunction

x0=2000;
y0=180700;
x1=2010;
y1=205700;
x2=2012;
y2=190000;

j=1;
for i=x0-60:0.01:x2+20
    tx(j)=i;
    ty(j)=f(x0,y0,x1,y1,x2,y2,i);
    j=j+1;
end
plot(tx,ty);
plot(x0,y0,'or');
plot(x1,y1,'og');
plot(x2,y2,'ob');

INTERPOLASI KUBIK
Data tabulasi jumlah penduduk Purworejo
Tahun                     2000        2010       2012      2015
Jumlah Penduduk   187900    205700   190000   210000

SOURCE CODE
function y=f(x0,y0,x1,y1,x2,y2,x3,y3,x)
    y=(y0*((x-x1)*(x-x2)*(x-x3))/((x0-x1)*(x0-x2)*(x0-x3)))+(y1*((x-x0)*(x-x2)*(x-x3))/((x1-x0)*(x1-x2)*(x1-x3)))+(y2*((x-x0)*(x-x1)*(x-x3))/((x2-x0)*(x2-x1)*(x2-x3)))+(y3*((x-x0)*(x-x1)*(x-x2))/((x3-x0)*(x3-x1)*(x3-x2)));
endfunction

x0=1;
y0=10;
x1=5;
y1=10;
x2=9;
y2=18;
x3=15;
y3=24;

j=1;
for i=x0-5:0.1:x3+5
    tx(j)=i;
    ty(j)=f(x0,y0,x1,y1,x2,y2,x3,y3,i);
    j=j+1;
end
plot(tx,ty);
plot(x0,y0,'or');
plot(x1,y1,'og');
plot(x2,y2,'ob');
plot(x3,y3,'oy');

Mencari solusi persamaan nonlinear dengan metode titik tetap menggunakan program silab

Dipunyai persamaan :
dengan x0=2 error=0.00001

Penyelesaian:
x^3-2x+1=0
<=> x^3-2x=-1
<=> x(x^2-2)=-1
<=>x=-1/(x^2-2)

Source Code Scilab

function y=g(x)
    y=-1/(x^2-2);
endfunction

n=100;
i=0;

x0=1;
x1=2;
err=0.00001;

while abs(x1-x0)>err
    x2=g(x1);
    x0=x1;
    x1=x2;
    i=i+1;
    disp("iterasi  "+string(i)+ " => "+string(x0)+"    "+string(x1));
    if i >= n then
        disp("Maks iteration exceed");
    end;
end
disp("Solusi=  "+string(x2));



You can replace this text by going to "Layout" and then "Page Elements" section. Edit " About "

Baca Selengkapnya Di : http://indonesianblog-jmk.blogspot.com/2012/06/cara-membuat-komentar-admin-berbeda.html#ixzz2kb6khEJE