Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function f($x)
- {
- if (sin($x) > cos($x))
- return sin($x) - cos($x);
- else
- return cos($x) - sin($x);
- }
- if (isset($_POST['policz']))
- {
- if ($_POST['policz'])
- {
- $xk = $_POST['xk'];
- $xp = $_POST['xp'];
- $N = 1000;
- $wartoscCalki = 0;
- $dx = ($xk - $xp) / $N;
- for($i = 1; $i < $N; $i++)
- {
- $wartoscCalki += f($xp + $i * $dx);
- }
- $wartoscCalki = ($wartoscCalki + (f($xp) + f($xk)) / 2) * $dx;
- echo 'Wartość całki: ' + abs($wartoscCalki);
- }
- }
- ?>
- <html>
- <head>
- </head>
- <body>
- <form action="" method="post">
- <table>
- <tr>
- <td>
- Początek przedziału:
- </td>
- <td>
- <input type="text" name="xp">
- </td>
- </tr>
- <tr>
- <td>
- Koniec przedziału:
- </td>
- <td>
- <input type="text"name="xk">
- </td>
- </tr>
- <tr>
- <td>
- <input type="submit" value="Policz całkę" name="policz" />
- </td>
- </tr>
- </table>
- </form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement