Persamaan yang dicari akarnya adalah 4x^3 - 15x^2 + 17x - 6 = 0
dengan tebakan awal -1 dan 3 dan nilai error 0.00001
2. Code Program (Bahasa C)
/*mencari akar persamaan dari persamaan 4x^3 - 15x^2 + 17x - 6 = 0*/
#include<stdio.h>
#include<math.h>
double power(double, int);
double value(double);
double calculate(double, double);
main()
{
double x1, x2, e;
int it;
printf ("Input First Guess : ");
scanf ("%lf", &x1);
printf ("Input Second Guess : ");
scanf ("%lf", &x2);
printf ("Input Error Value : ");
scanf ("%lf", &e);
printf ("Input Total Iteration : ");
scanf ("%i", &it);
int i=1;
double xt, fxt=1.0000;
printf("\n");
printf ("+------------+--------+--------+--------+-----------+\n");
printf ("|Iterasi ke- | xl | xb | xt | |f(xt)| |\n");
printf ("+------------+--------+--------+--------+-----------+\n");
for (i=1;(i<it) && (fxt>e);i++)
{
xt = calculate(x1, x2);
printf ("| %3i |%8.4lf|%8.4lf|%8.4lf|%11.6lf|\n", i, x1, x2, xt, cabs(value(xt)));
fxt = cabs(value(xt));
x1=x2;
x2=xt;
}
printf ("+------------+--------+--------+--------+-----------+\n");
}
double power(double number, int power)
{
double result = 1.00;
if (power == 0.0)
{
return result;
}
int i;
for (i = 1; i <= power; i++)
{
result *=number;
}
return result;
}
double value(double x)
{
return ((4*(power(x,3))) - (15*(power(x,2))) + 17*x - 6);
}
double calculate(double xl, double xb)
{
return (xb - ((xb-xl)/(value(xb)-value(xl)))*value(xb));
}
3. Hasil Iterasi
4. Hasil Akhir
X = 2
Nama : Richart Mevil Adhitya
NIM : D1042131008
No comments:
Post a Comment