Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package metodenumerik;
- /**
- * @author Kelompok3_RK_3IA14
- **/
- public class NewtonRaphson {
- public static void main(String[] args) {
- float x = 100;
- float x_sebelum = 9999;
- float selisih = x_sebelum - x;
- float error = (float) 0;
- String prefix1 = "X";
- String prefix2 = "Selisih";
- String format = "%-15s%s%n";
- System.out.printf(format, prefix1, " | " + prefix2);
- System.out.println("------------------------------");
- System.out.printf(format, x, " | " + selisih);
- while(Math.abs(selisih) > error){
- x_sebelum = x;
- x = x_sebelum - (fungsi(x) / turunanFungsi(x));
- selisih = x_sebelum - x;
- System.out.printf(format, x, " | " + selisih);
- }
- String prefix3 = "Akar Persamaan";
- String prefix4 = "Error";
- float absolute = Math.abs(selisih);
- System.out.println("------------------------------");
- System.out.printf(format, prefix3, " : " + x);
- System.out.printf(format, prefix4, " : " + absolute);
- }
- public static float fungsi(float x){
- //fungsi ini bisa diganti dengan fungsi apa pun
- float y = (x * x)-(7 * x)- 7;
- return y;
- }
- public static float turunanFungsi(float x){
- //fungsi ini bisa diganti dengan fungsi apa pun
- float y = (2 * x) - 7;
- return y;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement