Senin, 04 Juni 2012

Metode Secant


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

int main()
{
  float g,g1,g2,v,v1,v2,x,dx;

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

  scanf("%f",&g1);
  printf("Input Nilai X1 : ");

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

     v1=g2*g2-6*g2+8;
     printf("f(X2)=%lf\n",v1);

     x=g2-((v1*(g1-g2))/(v-v1));
     printf("Xi+1=%lf\n",x);

     dx= x*x-6*x+8;

     printf("f(Xi+1) =%lf\n",dx);

     g1=g2;
     g2=x;

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

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

Tidak ada komentar:

Posting Komentar