Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if(isset($_POST['nilai'])){
- function first($x)
- {
- $a = pow($x,3) + 2*pow($x,2) + 10*$x - 20;
- return $a;
- }
- function turunan_first($x){
- $a = 3*pow($x,2) + 4*$x + 10;
- return $a;
- }
- function hasil_1($x)
- {
- $per = first($x) / turunan_first($x);
- $a = $x - $per;
- return $a;
- }
- }
- ?>
- <!DOCTYPE html>
- <html lang="en" dir="ltr">
- <head>
- <meta charset="utf-8">
- <title>Metode Numerik</title>
- <style media="screen">
- body{
- background: #fdfafa;
- }
- form{
- width: 30%;
- height: auto;
- margin:auto;
- padding:32px;
- border:1px solid #f1f1f1;
- box-shadow: 2px 1px 8px #d9d9d9;
- border-radius:4px;
- margin-top:250px;
- background: #fff;
- }
- input{
- padding:4px;
- }
- button{
- background: #07c;
- color:#fff;
- border:2px solid #07c;
- padding:4px 38px;
- border-radius:2px;
- }
- </style>
- </head>
- <body>
- <form action="index.php" method="post">
- <label for="">Masukkan Nilai : </label>
- <input type="text" name="nilai" value="">
- <button type="submit" name="button">Cek</button>
- </form>
- <table align="center" border="1" width="800">
- <tr>
- <th>Iterasi</th>
- <th>F(x)</th>
- <th>F'(x)</th>
- <th>g(x)</th>
- <th>Error(x)</th>
- </tr>
- <?php
- $flag = true;
- $i = 1;
- $x = $_POST['nilai'];
- $givenError = $x;
- while ($flag) {
- $root = hasil_1($x);
- $error = abs(($root - $x)/$root)*100;
- $f = first($x);
- $f0 = turunan_first($x);
- ?>
- <tr>
- <td><?= $i++ ?></td>
- <td><?= number_format($f,6) ?></td>
- <td><?= number_format($f0,6) ?></td>
- <td><?= number_format($root,6) ?></td>
- <td><?= number_format($error,6) ?></td>
- </tr>
- <?php
- $x = $root;
- if($givenError > $error){
- $flag = false;
- }
- }
- ?>
- </table>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement