Advertisement
Guest User

Untitled

a guest
Jul 21st, 2019
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. <?php
  2.  
  3. if(isset($_POST['nilai'])){
  4. function first($x)
  5. {
  6. $a = pow($x,3) + 2*pow($x,2) + 10*$x - 20;
  7. return $a;
  8. }
  9.  
  10. function turunan_first($x){
  11. $a = 3*pow($x,2) + 4*$x + 10;
  12. return $a;
  13. }
  14.  
  15. function hasil_1($x)
  16. {
  17. $per = first($x) / turunan_first($x);
  18. $a = $x - $per;
  19.  
  20. return $a;
  21. }
  22.  
  23.  
  24. }
  25.  
  26. ?>
  27. <!DOCTYPE html>
  28. <html lang="en" dir="ltr">
  29. <head>
  30. <meta charset="utf-8">
  31. <title>Metode Numerik</title>
  32. <style media="screen">
  33. body{
  34. background: #fdfafa;
  35. }
  36. form{
  37. width: 30%;
  38. height: auto;
  39. margin:auto;
  40. padding:32px;
  41. border:1px solid #f1f1f1;
  42. box-shadow: 2px 1px 8px #d9d9d9;
  43. border-radius:4px;
  44. margin-top:250px;
  45. background: #fff;
  46. }
  47. input{
  48. padding:4px;
  49. }
  50. button{
  51. background: #07c;
  52. color:#fff;
  53. border:2px solid #07c;
  54. padding:4px 38px;
  55. border-radius:2px;
  56. }
  57. </style>
  58. </head>
  59. <body>
  60. <form action="index.php" method="post">
  61. <label for="">Masukkan Nilai : </label>
  62. <input type="text" name="nilai" value="">
  63. <button type="submit" name="button">Cek</button>
  64. </form>
  65. <table align="center" border="1" width="800">
  66. <tr>
  67. <th>Iterasi</th>
  68. <th>F(x)</th>
  69. <th>F'(x)</th>
  70. <th>g(x)</th>
  71. <th>Error(x)</th>
  72. </tr>
  73. <?php
  74. $flag = true;
  75. $i = 1;
  76. $x = $_POST['nilai'];
  77. $givenError = $x;
  78.  
  79. while ($flag) {
  80. $root = hasil_1($x);
  81. $error = abs(($root - $x)/$root)*100;
  82. $f = first($x);
  83. $f0 = turunan_first($x);
  84. ?>
  85. <tr>
  86. <td><?= $i++ ?></td>
  87. <td><?= number_format($f,6) ?></td>
  88. <td><?= number_format($f0,6) ?></td>
  89. <td><?= number_format($root,6) ?></td>
  90. <td><?= number_format($error,6) ?></td>
  91. </tr>
  92.  
  93. <?php
  94. $x = $root;
  95.  
  96. if($givenError > $error){
  97. $flag = false;
  98. }
  99. }
  100. ?>
  101. </table>
  102. </body>
  103. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement