Rabu, 04 April 2012

Tugas Rekayasa Komputasional

METODE PENGURUNGAN
------------------------------------
1. Metode Bagidua

Pada Soal f(x)=x^3+2x^2+10x-20=0
================================================






2. Metode Regula Falsi

caranya:

-execute

-ketik: regulafalsi(f, 1, 1.5, 0.000001)

*ket: 1 ama 1.5 itu selangnya, 0.000001 itu epsilon.
================================================

function y=f(x)
y=x^3 + 2*x^2 + 10*x - 20;
endfunction
function xn=regulafalsi(f, a1, b1, aprox)
i=1;
ea(1)=100;
if f(a1)*f(b1) < 0
x0(1)=a1;
x1(1)=b1;
xn(1)=x0(1)-f(x0(1))*(x1(1)-x0(1))/(f(x1(1))-f(x0(1)));
printf('r.\t\t x0\t\t xn\t\t x1\t Error \n');
printf('%2d \t %11.7f \t %11.7f \t %11.7f \n',i,x0(i),xn(i),x1(i));
while abs(ea(i))>=aprox,
if f(x0(i))*f(xn(i))< 0
x0(i+1)=x0(i);
x1(i+1)=xn(i);
end
if f(x0(i))*f(xn(i))> 0
x0(i+1)=xn(i);
x1(i+1)=x1(i);
end
xn(i+1)=x0(i+1)-f(x0(i+1))*(x1(i+1)-x0(i+1))/(f(x1(i+1))-f(x0(i+1)));
ea(i+1)=abs((xn(i+1)-xn(i))/(xn(i+1)));
printf('%2d \t %11.7f \t %11.7f \t %11.7f \t %7.7f \n', i+1,x0(i+1),xn(i+1),x1(i+1),ea(i+1));
i=i+1;
end
else
printf(' ');
end
endfunction




METODE TERBUKA
----------------------------------------
3. METODE NEWTON-RAPHSON

caranya:

-execute

-ketik: newtonraphson(f, 1, 0.000001)

*ket: 1 = x0, 0.000001 = epsilon.
================================================


function y=f(x)
y=x^3 + 2*x^2 + 10*x - 20;
endfunction
function y=df(x)
y=3*x^2 + 4*x + 10;
endfunction
function xr=newtonraphson(f, x0, aprox);
i=1;
er(1)=1;
xr(1)=x0;
while abs(er(i))>=aprox;
xr(i+1)=xr(i)-f(xr(i))/df(xr(i));
er(i+1)=abs((xr(i+1)-xr(i))/xr(i+1));
i=i+1;
end
printf(' i \t xn(i) Error aprox (i) \n');
for j=1:i;
printf('%2d \t %11.7f \t %7.6f \n',j-1,xr(j),er(j));
end
endfunction




4. METODE SECANT:

caranya:
-execute

-ketik: metodesecant(1, 1.5, 0.000001)

*ket: 1 = x0, 1.5 = x1, 0.000001= epsilon.

=======================================================

function y=g(x)
y=x^3 + 2*x^2 + 10*x - 20;
endfunction
function pn=metodesecant(x0, x1, aprox)
j=2;
i=1;
pn(1)=x0;
pn(2)=x1;
er(i)=1;
while abs(er(i))>=aprox
pn(j+1)=(pn(j-1)*f(pn(j))-pn(j)*f(pn(j-1)))/(f(pn(j))-f(pn(j-1)));
er(i+1)=abs((pn(j+1)-pn(j))/pn(j+1));
j=j+1;
i=i+1;
end

printf(' i \t\t pn(i) \t\t Error aprox (i) \n');
printf('%2d \t %11.7f \t\t \n',0,pn(1));
for k=2:j;
printf('%2d \t %11.7f \t %7.8f \n',k,pn(k),er(k-1));
end
endfunction

0 komentar:

Posting Komentar