Created
August 19, 2014 04:42
-
-
Save dukenmarga/7312da7bc7c78fd83fe8 to your computer and use it in GitHub Desktop.
Secant Method
This file contains 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
/* | |
* program untuk mencari solusi persamaan | |
* dengan menggunakan metode secant | |
* coder : duken marga | |
*/ | |
#include <stdio.h> | |
#include <math.h> | |
#define PHI 3.141592654 | |
#define TOLERANCE 10E-10 | |
float f(float x); | |
int main() | |
{ | |
float x1, x2, x3; | |
int i, loop; | |
printf("Masukkan nilai bilangan inisiasi pertama : "); | |
scanf("%f", &x1); | |
printf("Masukkan nilai bilangan inisiasi kedua : "); | |
scanf("%f", &x2); | |
printf("Masukkan jumlah maksimum perulangan : "); | |
scanf("%d", &loop); | |
printf(" x1 \t x2 \t x3\n "); | |
for(i = 0; i < loop; i++){ | |
x3 = x2 - f(x2) * (x1 - x2) / (f(x1) - f(x2)); | |
printf("%f %f %f\n ", x1, x2, x3); | |
if( x2 - x3 < TOLERANCE){ | |
break; | |
} | |
x1 = x2; | |
x2 = x3; | |
} | |
printf("Solusi persamaan adalah : %20.10f", x3); | |
} | |
/* | |
* | |
* f(x) = x^2 + x - cos(x) | |
*/ | |
float f(float x){ | |
//return x*x + x - cos(x * PHI / 180); | |
return x*x + x - cos(x * PHI / 180); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment