Created
August 19, 2014 04:43
-
-
Save dukenmarga/eabb722cec4c504e9ccb to your computer and use it in GitHub Desktop.
Bisection Method
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * metode numerik dengan bisection method | |
| * author : duken marga | |
| */ | |
| #include <stdio.h> | |
| #include <math.h> | |
| #define EPSILON 10E-10 | |
| #define PHI 3.141592654 | |
| float f(float x); | |
| int main() | |
| { | |
| float left, right, mid; | |
| printf("Masukkan nilai pertama : "); | |
| scanf("%f", &left); | |
| printf("Masukkan nilai kedua : "); | |
| scanf("%f", &right); | |
| do{ | |
| mid = (right + left) / 2; | |
| printf("%f %f %f \n", f(left), f(mid), f(right)); | |
| if(f(left) * f(mid) < 0){ | |
| right = mid; | |
| } | |
| else if(f(right) * f(mid) < 0){ | |
| left = mid; | |
| } | |
| else | |
| break; | |
| }while(abs(right-left) < 2 * EPSILON); | |
| printf("Solusi persamaan adalah : %f", mid); | |
| } | |
| /* | |
| * f(x) = x*x - 2*x + 1; | |
| */ | |
| float f(float x){ | |
| return x*x - 9; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment