Senin, 04 Juni 2012

Metode Bierg Vieta


#include <iostream.h>
#include <stdio.h>
#include <conio.h>
#include <math.h>
#define epsilon 0.001

int main()
{
  float g,g1,v,a0=8,a1=-6,b,b0,b1,b2=1,c1,c2=1,x,dx;

  int converged=0,i;
  printf("Input Nilai Xo : ");

  scanf("%f",&g1);
  i=1;
  while (converged==0)
    {
      printf("\n iteration no=%d\n",i);
      v=g1*g1-6*g1+8;
      printf("f(Xn)=%lf\n",v);

      b1=a1+(g1*b2);
      printf("b1=%lf\n",b1);

      b0=a0+(g1*b1);
      printf("b0=%lf\n",b0);

      c1=b1+(g1*c2);
      printf("c1=%lf\n",c1);

      x=g1-(b0/c1);
      printf("Xn=%lf\n",x);

      g1=x;

      if (fabs(b0)<=epsilon)
         {converged=1;}
      printf("Solusi Xn=%lf\n",x);

      i=i+1;
    }
getch();
}

Tidak ada komentar:

Posting Komentar