Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <conio.h>
- #include <math.h>
- double f(double x)
- {
- return (x+exp(x));
- }
- main()
- {
- double a, b, e, c, ya, yb, yc,tempc;
- int i=1, n,tempi;
- puts("\t\t\tPENYELESAIAN PERSAMAAN NON LINIER");
- puts("\t\t\t\t menggunakan");
- puts("\t\t\t\t METODE BISEKSI");
- puts("");
- puts("persamaan fungsi = x+exp(x) ");
- puts("");
- printf("Masukkan batas bawah (a) = ");
- scanf("%lf", &a);
- printf("Masukkan batas atas (b) = ");
- scanf("%lf", &b);
- printf("Masukkan toleransi error = ");
- scanf("%lf", &e);
- printf("Masukkan iterasi maksimum = ");
- scanf("%d", &n);
- puts("");
- ya = f(a);
- yb = f(b);
- printf("i a b c ya yb yc\n");
- puts("");
- while(i <= n)
- {
- if(ya*yb>0)
- break;
- else
- {
- c = (a+b)/2;
- yc = f(c);
- printf("%-8d%-10.4g%-10.4g%-10.4g%-12.4g%-12.4g%-10.4g\n", i, a, b, c, ya, yb,yc);
- if(yc*ya<0)
- {
- b = c;
- yb = yc;
- }
- else
- {
- a = c;
- ya = yc;
- }
- if(i == 1)
- tempc = yc;
- if(fabs(yc) <= fabs(tempc)) {
- tempi = i;
- tempc = yc;
- }
- if(fabs(yc)<e)
- break;
- else
- i++;
- }
- }
- puts("");
- printf("Akar persamaan di c = %lf\n", c);
- printf("Dengan nilai yc = %lf\n", yc);
- printf("Pada iterasi ke = %d\n", i-1);
- puts("");
- printf("Yang mendekati 0 adalah iterasi ke = %d\nyc = %lf\n", tempi,tempc);
- return 0;
- getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement