main.m
Source code :
clc;
disp ('TUGAS 5');
disp ('METODE SECANT');
disp (' ');
disp ('Nama : Desianny Amalia Fauziah');
disp ('NIM : 5302413085');
disp ('Rombel : 02');
disp (' ');
disp('PERSAMAAN : exp(x)-2-(x.^2)');
disp(' ');
f_x = inline('exp(x)-2-(x.^2)','x'); %definisi fungsi
secant(f_x, -0.5, 1.5, 0.01, 10);
secant.m
Source code :
function secant(F,x0,x1,e,N)
E = 9;
i = 2;
X(1) = x0;
X(2) = x1;
Y(1) = F(x0);
Y(2) = F(x1);
disp('=========================================================');
display('Iterasi x F(a) a-b C-D');
disp('=========================================================');
while(E>e)
X(i+1) = X(i) - Y(i) *( (X(i)-X(i-1))/ (Y(i)-Y(i-1)) );
Y(i+1) = F(X(i+1));
fprintf('%6.0f %d %10.2f %8.2f %8.2f \n\n',i,X(i),F(X(i)),(X(i)-X(i-1)),(Y(i)-Y(i-1)));
if i>1
E = abs(X(i)-X(i+1));
err(i) = abs(E);
end
i = i+1;
if i>N
break;
end
end
plot(err);
end
Tidak ada komentar:
Posting Komentar