2. Code program
#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 ("Tebakan pertama : ");
scanf ("%lf", &x1);
printf ("Tebakan kedua : ");
scanf ("%lf", &x2);
printf ("Masukan eror : ");
scanf ("%lf", &e);
printf ("Berapa kali iterasi : ");
scanf ("%i", &it);
printf ("%lf",e);
int i=1;
double xt, fxt;
printf("\n");
printf ("Iterasi ke- xl xb xt |f(xt)| \n");
for (i=1;i<it;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;
}
}
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 ((7*(power(x,3))) - (12*(power(x,4))) + 16*x - 4);
}
double calculate(double xl, double xb)
{
return (xb - ((xb-xl)/(value(xb)-value(xl)))*value(xb));
}
3. Hasil iterasi;
Interasi ke 14 0.2462 seperti gambar di atas
Nama: Tito Anggoro
NIM : D1042131014
No comments:
Post a Comment